1 #include <netinet/in.h>
11 encode_inet6_opt (socklen_t *elp)
27 printf ("cl == -1 on line %d\n", __LINE__); \
32 /* Estimate the length */
33 cl = inet6_opt_init (NULL, 0);
35 cl = inet6_opt_append (NULL, 0, cl, OPT_X, 12, 8, NULL);
37 cl = inet6_opt_append (NULL, 0, cl, OPT_Y, 7, 4, NULL);
39 cl = inet6_opt_append (NULL, 0, cl, OPT_Z, 7, 1, NULL);
41 cl = inet6_opt_finish (NULL, 0, cl);
48 puts ("malloc failed");
52 memcpy (eb + el, "deadbeef", 8);
54 cl = inet6_opt_init (eb, el);
57 cl = inet6_opt_append (eb, el, cl, OPT_X, 12, 8, &db);
60 offset = inet6_opt_set_val (db, 0, &val4, sizeof (val4));
61 val8 = 0x0102030405060708LL;
62 inet6_opt_set_val (db, offset, &val8, sizeof (val8));
64 cl = inet6_opt_append (eb, el, cl, OPT_Y, 7, 4, &db);
67 offset = inet6_opt_set_val (db, 0, &val1, sizeof (val1));
69 offset = inet6_opt_set_val (db, offset, &val2, sizeof (val2));
71 inet6_opt_set_val (db, offset, &val4, sizeof (val4));
73 cl = inet6_opt_append (eb, el, cl, OPT_Z, 7, 1, &db);
75 inet6_opt_set_val (db, 0, (void *) "abcdefg", 7);
77 cl = inet6_opt_finish (eb, el, cl);
80 if (memcmp (eb + el, "deadbeef", 8) != 0)
82 puts ("Canary corrupted");
91 decode_inet6_opt (void *eb, socklen_t el)
106 while ((cl = inet6_opt_next (eb, el, cl, &type, &len, &db)) != -1)
112 puts ("OPT_X is not first");
117 printf ("OPT_X's length %d != 12\n", len);
120 offset = inet6_opt_get_val (db, 0, &val4, sizeof (val4));
121 if (val4 != 0x12345678)
123 printf ("OPT_X's val4 %x != 0x12345678\n", val4);
126 offset = inet6_opt_get_val (db, offset, &val8, sizeof (val8));
127 if (offset != len || val8 != 0x0102030405060708LL)
129 printf ("OPT_X's val8 %llx != 0x0102030405060708\n",
137 puts ("OPT_Y is not second");
142 printf ("OPT_Y's length %d != 7\n", len);
145 offset = inet6_opt_get_val (db, 0, &val1, sizeof (val1));
148 printf ("OPT_Y's val1 %x != 0x01\n", val1);
151 offset = inet6_opt_get_val (db, offset, &val2, sizeof (val2));
154 printf ("OPT_Y's val2 %x != 0x1331\n", val2);
157 offset = inet6_opt_get_val (db, offset, &val4, sizeof (val4));
158 if (offset != len || val4 != 0x01020304)
160 printf ("OPT_Y's val4 %x != 0x01020304\n", val4);
167 puts ("OPT_Z is not third");
172 printf ("OPT_Z's length %d != 7\n", len);
175 offset = inet6_opt_get_val (db, 0, buf, 7);
176 if (offset != len || memcmp (buf, "abcdefg", 7) != 0)
179 printf ("OPT_Z's buf \"%s\" != \"abcdefg\"\n", buf);
184 printf ("Unknown option %d\n", type);
190 puts ("Didn't see all of OPT_X, OPT_Y and OPT_Z");
201 eb = encode_inet6_opt (&el);
204 if (decode_inet6_opt (eb, el))