1 #include <netinet/in.h>
12 encode_inet6_opt (socklen_t *elp)
28 printf ("cl == -1 on line %d\n", __LINE__); \
33 /* Estimate the length */
34 cl = inet6_opt_init (NULL, 0);
36 cl = inet6_opt_append (NULL, 0, cl, OPT_X, 12, 8, NULL);
38 cl = inet6_opt_append (NULL, 0, cl, OPT_Y, 7, 4, NULL);
40 cl = inet6_opt_append (NULL, 0, cl, OPT_Z, 7, 1, NULL);
42 cl = inet6_opt_finish (NULL, 0, cl);
49 puts ("malloc failed");
53 memcpy (eb + el, "deadbeef", 8);
55 cl = inet6_opt_init (eb, el);
58 cl = inet6_opt_append (eb, el, cl, OPT_X, 12, 8, &db);
61 offset = inet6_opt_set_val (db, 0, &val4, sizeof (val4));
62 val8 = 0x0102030405060708LL;
63 inet6_opt_set_val (db, offset, &val8, sizeof (val8));
65 cl = inet6_opt_append (eb, el, cl, OPT_Y, 7, 4, &db);
68 offset = inet6_opt_set_val (db, 0, &val1, sizeof (val1));
70 offset = inet6_opt_set_val (db, offset, &val2, sizeof (val2));
72 inet6_opt_set_val (db, offset, &val4, sizeof (val4));
74 cl = inet6_opt_append (eb, el, cl, OPT_Z, 7, 1, &db);
76 inet6_opt_set_val (db, 0, (void *) "abcdefg", 7);
78 cl = inet6_opt_finish (eb, el, cl);
81 if (memcmp (eb + el, "deadbeef", 8) != 0)
83 puts ("Canary corrupted");
92 decode_inet6_opt (void *eb, socklen_t el)
107 while ((cl = inet6_opt_next (eb, el, cl, &type, &len, &db)) != -1)
113 puts ("OPT_X is not first");
118 printf ("OPT_X's length %d != 12\n", len);
121 offset = inet6_opt_get_val (db, 0, &val4, sizeof (val4));
122 if (val4 != 0x12345678)
124 printf ("OPT_X's val4 %x != 0x12345678\n", val4);
127 offset = inet6_opt_get_val (db, offset, &val8, sizeof (val8));
128 if (offset != len || val8 != 0x0102030405060708LL)
130 printf ("OPT_X's val8 %llx != 0x0102030405060708\n",
138 puts ("OPT_Y is not second");
143 printf ("OPT_Y's length %d != 7\n", len);
146 offset = inet6_opt_get_val (db, 0, &val1, sizeof (val1));
149 printf ("OPT_Y's val1 %x != 0x01\n", val1);
152 offset = inet6_opt_get_val (db, offset, &val2, sizeof (val2));
155 printf ("OPT_Y's val2 %x != 0x1331\n", val2);
158 offset = inet6_opt_get_val (db, offset, &val4, sizeof (val4));
159 if (offset != len || val4 != 0x01020304)
161 printf ("OPT_Y's val4 %x != 0x01020304\n", val4);
168 puts ("OPT_Z is not third");
173 printf ("OPT_Z's length %d != 7\n", len);
176 offset = inet6_opt_get_val (db, 0, buf, 7);
177 if (offset != len || memcmp (buf, "abcdefg", 7) != 0)
180 printf ("OPT_Z's buf \"%s\" != \"abcdefg\"\n", buf);
185 printf ("Unknown option %d\n", type);
191 puts ("Didn't see all of OPT_X, OPT_Y and OPT_Z");
202 eb = encode_inet6_opt (&el);
205 if (decode_inet6_opt (eb, el))