+ return 1;
+}
+
+static int test_PACKET_get_length_prefixed_2()
+{
+ unsigned char buf[1024];
+ const size_t len = 516; /* 0x0204 */
+ unsigned int i;
+ PACKET pkt, short_pkt, subpkt;
+
+ for (i = 1; i <= 1024; i++) {
+ buf[i-1] = (i * 2) & 0xff;
+ }
+
+ if ( !PACKET_buf_init(&pkt, buf, 1024)
+ || !PACKET_buf_init(&short_pkt, buf, len)
+ || !PACKET_get_length_prefixed_2(&pkt, &subpkt)
+ || PACKET_remaining(&subpkt) != len
+ || !PACKET_get_net_2(&subpkt, &i)
+ || i != 0x0608
+ || PACKET_get_length_prefixed_2(&short_pkt, &subpkt)
+ || PACKET_remaining(&short_pkt) != len) {
+ fprintf(stderr, "test_PACKET_get_length_prefixed_2() failed\n");
+ return 0;
+ }
+
+ return 1;
+}
+
+static int test_PACKET_get_length_prefixed_3()
+{
+ unsigned char buf[1024];
+ const size_t len = 516; /* 0x000204 */
+ unsigned int i;
+ PACKET pkt, short_pkt, subpkt;
+
+ for (i = 0; i < 1024; i++) {
+ buf[i] = (i * 2) & 0xff;
+ }
+
+ if ( !PACKET_buf_init(&pkt, buf, 1024)
+ || !PACKET_buf_init(&short_pkt, buf, len)
+ || !PACKET_get_length_prefixed_3(&pkt, &subpkt)
+ || PACKET_remaining(&subpkt) != len
+ || !PACKET_get_net_2(&subpkt, &i)
+ || i != 0x0608
+ || PACKET_get_length_prefixed_3(&short_pkt, &subpkt)
+ || PACKET_remaining(&short_pkt) != len) {
+ fprintf(stderr, "test_PACKET_get_length_prefixed_3() failed\n");
+ return 0;
+ }
+
+ return 1;
+}
+
+int main(int argc, char **argv)
+{
+ unsigned char buf[BUF_LEN];
+ unsigned int i;
+
+ for (i=1; i<=BUF_LEN; i++) {
+ buf[i-1] = (i * 2) & 0xff;
+ }
+ i = 0;
+