]> The Tcpdump Group git mirrors - tcpdump/blob - print-bootp.c
NDOize safeputs() and safeputchar()
[tcpdump] / print-bootp.c
1 /*
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * Format and print bootp packets.
22 */
23
24 #define NETDISSECT_REWORKED
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <tcpdump-stdinc.h>
30
31 #include <string.h>
32
33 #include "interface.h"
34 #include "addrtoname.h"
35 #include "extract.h"
36 #include "bootp.h"
37
38 static const char tstr[] = " [|bootp]";
39
40 static void rfc1048_print(netdissect_options *, const u_char *);
41 static void cmu_print(netdissect_options *, const u_char *);
42 static char *client_fqdn_flags(u_int flags);
43
44 static const struct tok bootp_flag_values[] = {
45 { 0x8000, "Broadcast" },
46 { 0, NULL}
47 };
48
49 static const struct tok bootp_op_values[] = {
50 { BOOTPREQUEST, "Request" },
51 { BOOTPREPLY, "Reply" },
52 { 0, NULL}
53 };
54
55 /*
56 * Print bootp requests
57 */
58 void
59 bootp_print(netdissect_options *ndo,
60 register const u_char *cp, u_int length)
61 {
62 register const struct bootp *bp;
63 static const u_char vm_cmu[4] = VM_CMU;
64 static const u_char vm_rfc1048[4] = VM_RFC1048;
65
66 bp = (const struct bootp *)cp;
67 ND_TCHECK(bp->bp_op);
68
69 ND_PRINT((ndo, "BOOTP/DHCP, %s",
70 tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op)));
71
72 if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
73 ND_TCHECK2(bp->bp_chaddr[0], 6);
74 ND_PRINT((ndo, " from %s", etheraddr_string(bp->bp_chaddr)));
75 }
76
77 ND_PRINT((ndo, ", length %u", length));
78
79 if (!ndo->ndo_vflag)
80 return;
81
82 ND_TCHECK(bp->bp_secs);
83
84 /* The usual hardware address type is 1 (10Mb Ethernet) */
85 if (bp->bp_htype != 1)
86 ND_PRINT((ndo, ", htype %d", bp->bp_htype));
87
88 /* The usual length for 10Mb Ethernet address is 6 bytes */
89 if (bp->bp_htype != 1 || bp->bp_hlen != 6)
90 ND_PRINT((ndo, ", hlen %d", bp->bp_hlen));
91
92 /* Only print interesting fields */
93 if (bp->bp_hops)
94 ND_PRINT((ndo, ", hops %d", bp->bp_hops));
95 if (EXTRACT_32BITS(&bp->bp_xid))
96 ND_PRINT((ndo, ", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid)));
97 if (EXTRACT_16BITS(&bp->bp_secs))
98 ND_PRINT((ndo, ", secs %d", EXTRACT_16BITS(&bp->bp_secs)));
99
100 ND_PRINT((ndo, ", Flags [%s]",
101 bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags))));
102 if (ndo->ndo_vflag > 1)
103 ND_PRINT((ndo, " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags)));
104
105 /* Client's ip address */
106 ND_TCHECK(bp->bp_ciaddr);
107 if (EXTRACT_32BITS(&bp->bp_ciaddr.s_addr))
108 ND_PRINT((ndo, "\n\t Client-IP %s", ipaddr_string(&bp->bp_ciaddr)));
109
110 /* 'your' ip address (bootp client) */
111 ND_TCHECK(bp->bp_yiaddr);
112 if (EXTRACT_32BITS(&bp->bp_yiaddr.s_addr))
113 ND_PRINT((ndo, "\n\t Your-IP %s", ipaddr_string(&bp->bp_yiaddr)));
114
115 /* Server's ip address */
116 ND_TCHECK(bp->bp_siaddr);
117 if (EXTRACT_32BITS(&bp->bp_siaddr.s_addr))
118 ND_PRINT((ndo, "\n\t Server-IP %s", ipaddr_string(&bp->bp_siaddr)));
119
120 /* Gateway's ip address */
121 ND_TCHECK(bp->bp_giaddr);
122 if (EXTRACT_32BITS(&bp->bp_giaddr.s_addr))
123 ND_PRINT((ndo, "\n\t Gateway-IP %s", ipaddr_string(&bp->bp_giaddr)));
124
125 /* Client's Ethernet address */
126 if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
127 ND_TCHECK2(bp->bp_chaddr[0], 6);
128 ND_PRINT((ndo, "\n\t Client-Ethernet-Address %s", etheraddr_string(bp->bp_chaddr)));
129 }
130
131 ND_TCHECK2(bp->bp_sname[0], 1); /* check first char only */
132 if (*bp->bp_sname) {
133 ND_PRINT((ndo, "\n\t sname \""));
134 if (fn_print(bp->bp_sname, ndo->ndo_snapend)) {
135 ND_PRINT((ndo, "\""));
136 ND_PRINT((ndo, "%s", tstr + 1));
137 return;
138 }
139 ND_PRINT((ndo, "\""));
140 }
141 ND_TCHECK2(bp->bp_file[0], 1); /* check first char only */
142 if (*bp->bp_file) {
143 ND_PRINT((ndo, "\n\t file \""));
144 if (fn_print(bp->bp_file, ndo->ndo_snapend)) {
145 ND_PRINT((ndo, "\""));
146 ND_PRINT((ndo, "%s", tstr + 1));
147 return;
148 }
149 ND_PRINT((ndo, "\""));
150 }
151
152 /* Decode the vendor buffer */
153 ND_TCHECK(bp->bp_vend[0]);
154 if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
155 sizeof(u_int32_t)) == 0)
156 rfc1048_print(ndo, bp->bp_vend);
157 else if (memcmp((const char *)bp->bp_vend, vm_cmu,
158 sizeof(u_int32_t)) == 0)
159 cmu_print(ndo, bp->bp_vend);
160 else {
161 u_int32_t ul;
162
163 ul = EXTRACT_32BITS(&bp->bp_vend);
164 if (ul != 0)
165 ND_PRINT((ndo, "\n\t Vendor-#0x%x", ul));
166 }
167
168 return;
169 trunc:
170 ND_PRINT((ndo, "%s", tstr));
171 }
172
173 /*
174 * The first character specifies the format to print:
175 * i - ip address (32 bits)
176 * p - ip address pairs (32 bits + 32 bits)
177 * l - long (32 bits)
178 * L - unsigned long (32 bits)
179 * s - short (16 bits)
180 * b - period-seperated decimal bytes (variable length)
181 * x - colon-seperated hex bytes (variable length)
182 * a - ascii string (variable length)
183 * B - on/off (8 bits)
184 * $ - special (explicit code to handle)
185 */
186 static const struct tok tag2str[] = {
187 /* RFC1048 tags */
188 { TAG_PAD, " PAD" },
189 { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */
190 { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */
191 { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */
192 { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */
193 { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
194 { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */
195 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
196 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
197 { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */
198 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
199 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
200 { TAG_HOSTNAME, "aHostname" }, /* ascii hostname */
201 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
202 { TAG_END, " END" },
203 /* RFC1497 tags */
204 { TAG_DUMPPATH, "aDP" },
205 { TAG_DOMAINNAME, "aDomain-Name" },
206 { TAG_SWAP_SERVER, "iSS" },
207 { TAG_ROOTPATH, "aRP" },
208 { TAG_EXTPATH, "aEP" },
209 /* RFC2132 tags */
210 { TAG_IP_FORWARD, "BIPF" },
211 { TAG_NL_SRCRT, "BSRT" },
212 { TAG_PFILTERS, "pPF" },
213 { TAG_REASS_SIZE, "sRSZ" },
214 { TAG_DEF_TTL, "bTTL" },
215 { TAG_MTU_TIMEOUT, "lMTU-Timeout" },
216 { TAG_MTU_TABLE, "sMTU-Table" },
217 { TAG_INT_MTU, "sMTU" },
218 { TAG_LOCAL_SUBNETS, "BLSN" },
219 { TAG_BROAD_ADDR, "iBR" },
220 { TAG_DO_MASK_DISC, "BMD" },
221 { TAG_SUPPLY_MASK, "BMS" },
222 { TAG_DO_RDISC, "BRouter-Discovery" },
223 { TAG_RTR_SOL_ADDR, "iRSA" },
224 { TAG_STATIC_ROUTE, "pStatic-Route" },
225 { TAG_USE_TRAILERS, "BUT" },
226 { TAG_ARP_TIMEOUT, "lAT" },
227 { TAG_ETH_ENCAP, "BIE" },
228 { TAG_TCP_TTL, "bTT" },
229 { TAG_TCP_KEEPALIVE, "lKI" },
230 { TAG_KEEPALIVE_GO, "BKG" },
231 { TAG_NIS_DOMAIN, "aYD" },
232 { TAG_NIS_SERVERS, "iYS" },
233 { TAG_NTP_SERVERS, "iNTP" },
234 { TAG_VENDOR_OPTS, "bVendor-Option" },
235 { TAG_NETBIOS_NS, "iNetbios-Name-Server" },
236 { TAG_NETBIOS_DDS, "iWDD" },
237 { TAG_NETBIOS_NODE, "$Netbios-Node" },
238 { TAG_NETBIOS_SCOPE, "aNetbios-Scope" },
239 { TAG_XWIN_FS, "iXFS" },
240 { TAG_XWIN_DM, "iXDM" },
241 { TAG_NIS_P_DOMAIN, "sN+D" },
242 { TAG_NIS_P_SERVERS, "iN+S" },
243 { TAG_MOBILE_HOME, "iMH" },
244 { TAG_SMPT_SERVER, "iSMTP" },
245 { TAG_POP3_SERVER, "iPOP3" },
246 { TAG_NNTP_SERVER, "iNNTP" },
247 { TAG_WWW_SERVER, "iWWW" },
248 { TAG_FINGER_SERVER, "iFG" },
249 { TAG_IRC_SERVER, "iIRC" },
250 { TAG_STREETTALK_SRVR, "iSTS" },
251 { TAG_STREETTALK_STDA, "iSTDA" },
252 { TAG_REQUESTED_IP, "iRequested-IP" },
253 { TAG_IP_LEASE, "lLease-Time" },
254 { TAG_OPT_OVERLOAD, "$OO" },
255 { TAG_TFTP_SERVER, "aTFTP" },
256 { TAG_BOOTFILENAME, "aBF" },
257 { TAG_DHCP_MESSAGE, " DHCP-Message" },
258 { TAG_SERVER_ID, "iServer-ID" },
259 { TAG_PARM_REQUEST, "bParameter-Request" },
260 { TAG_MESSAGE, "aMSG" },
261 { TAG_MAX_MSG_SIZE, "sMSZ" },
262 { TAG_RENEWAL_TIME, "lRN" },
263 { TAG_REBIND_TIME, "lRB" },
264 { TAG_VENDOR_CLASS, "aVendor-Class" },
265 { TAG_CLIENT_ID, "$Client-ID" },
266 /* RFC 2485 */
267 { TAG_OPEN_GROUP_UAP, "aUAP" },
268 /* RFC 2563 */
269 { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
270 /* RFC 2610 */
271 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
272 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
273 /* RFC 2937 */
274 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
275 /* RFC 3011 */
276 { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
277 /* RFC 3442 */
278 { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
279 { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
280 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
281 { TAG_USER_CLASS, "aCLASS" },
282 { TAG_SLP_NAMING_AUTH, "aSLP-NA" },
283 { TAG_CLIENT_FQDN, "$FQDN" },
284 { TAG_AGENT_CIRCUIT, "$Agent-Information" },
285 { TAG_AGENT_REMOTE, "bARMT" },
286 { TAG_AGENT_MASK, "bAMSK" },
287 { TAG_TZ_STRING, "aTZSTR" },
288 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */
289 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */
290 { TAG_VINES_SERVERS, "iVINES" },
291 { TAG_SERVER_RANK, "sRANK" },
292 { TAG_CLIENT_ARCH, "sARCH" },
293 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */
294 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */
295 { TAG_LDAP_URL, "aLDAP" },
296 { TAG_6OVER4, "i6o4" },
297 { TAG_PRINTER_NAME, "aPRTR" },
298 { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */
299 { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */
300 { TAG_NETINFO_PARENT, "iNI" },
301 { TAG_NETINFO_PARENT_TAG, "aNITAG" },
302 { TAG_URL, "aURL" },
303 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */
304 { 0, NULL }
305 };
306 /* 2-byte extended tags */
307 static const struct tok xtag2str[] = {
308 { 0, NULL }
309 };
310
311 /* DHCP "options overload" types */
312 static const struct tok oo2str[] = {
313 { 1, "file" },
314 { 2, "sname" },
315 { 3, "file+sname" },
316 { 0, NULL }
317 };
318
319 /* NETBIOS over TCP/IP node type options */
320 static const struct tok nbo2str[] = {
321 { 0x1, "b-node" },
322 { 0x2, "p-node" },
323 { 0x4, "m-node" },
324 { 0x8, "h-node" },
325 { 0, NULL }
326 };
327
328 /* ARP Hardware types, for Client-ID option */
329 static const struct tok arp2str[] = {
330 { 0x1, "ether" },
331 { 0x6, "ieee802" },
332 { 0x7, "arcnet" },
333 { 0xf, "frelay" },
334 { 0x17, "strip" },
335 { 0x18, "ieee1394" },
336 { 0, NULL }
337 };
338
339 static const struct tok dhcp_msg_values[] = {
340 { DHCPDISCOVER, "Discover" },
341 { DHCPOFFER, "Offer" },
342 { DHCPREQUEST, "Request" },
343 { DHCPDECLINE, "Decline" },
344 { DHCPACK, "ACK" },
345 { DHCPNAK, "NACK" },
346 { DHCPRELEASE, "Release" },
347 { DHCPINFORM, "Inform" },
348 { 0, NULL }
349 };
350
351 #define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */
352 #define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */
353 #define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */
354 static const struct tok agent_suboption_values[] = {
355 { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" },
356 { AGENT_SUBOPTION_REMOTE_ID, "Remote-ID" },
357 { AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" },
358 { 0, NULL }
359 };
360
361
362 static void
363 rfc1048_print(netdissect_options *ndo,
364 register const u_char *bp)
365 {
366 register u_int16_t tag;
367 register u_int len;
368 register const char *cp;
369 register char c;
370 int first, idx;
371 u_int32_t ul;
372 u_int16_t us;
373 u_int8_t uc, subopt, suboptlen;
374
375 ND_PRINT((ndo, "\n\t Vendor-rfc1048 Extensions"));
376
377 /* Step over magic cookie */
378 ND_PRINT((ndo, "\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp)));
379 bp += sizeof(int32_t);
380
381 /* Loop while we there is a tag left in the buffer */
382 while (ND_TTEST2(*bp, 1)) {
383 tag = *bp++;
384 if (tag == TAG_PAD && ndo->ndo_vflag < 3)
385 continue;
386 if (tag == TAG_END && ndo->ndo_vflag < 3)
387 return;
388 if (tag == TAG_EXTENDED_OPTION) {
389 ND_TCHECK2(*(bp + 1), 2);
390 tag = EXTRACT_16BITS(bp + 1);
391 /* XXX we don't know yet if the IANA will
392 * preclude overlap of 1-byte and 2-byte spaces.
393 * If not, we need to offset tag after this step.
394 */
395 cp = tok2str(xtag2str, "?xT%u", tag);
396 } else
397 cp = tok2str(tag2str, "?T%u", tag);
398 c = *cp++;
399
400 if (tag == TAG_PAD || tag == TAG_END)
401 len = 0;
402 else {
403 /* Get the length; check for truncation */
404 ND_TCHECK2(*bp, 1);
405 len = *bp++;
406 }
407
408 ND_PRINT((ndo, "\n\t %s Option %u, length %u%s", cp, tag, len,
409 len > 0 ? ": " : ""));
410
411 if (tag == TAG_PAD && ndo->ndo_vflag > 2) {
412 u_int ntag = 1;
413 while (ND_TTEST2(*bp, 1) && *bp == TAG_PAD) {
414 bp++;
415 ntag++;
416 }
417 if (ntag > 1)
418 ND_PRINT((ndo, ", occurs %u", ntag));
419 }
420
421 if (!ND_TTEST2(*bp, len)) {
422 ND_PRINT((ndo, "[|rfc1048 %u]", len));
423 return;
424 }
425
426 if (tag == TAG_DHCP_MESSAGE && len == 1) {
427 uc = *bp++;
428 ND_PRINT((ndo, "%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc)));
429 continue;
430 }
431
432 if (tag == TAG_PARM_REQUEST) {
433 idx = 0;
434 while (len-- > 0) {
435 uc = *bp++;
436 cp = tok2str(tag2str, "?Option %u", uc);
437 if (idx % 4 == 0)
438 ND_PRINT((ndo, "\n\t "));
439 else
440 ND_PRINT((ndo, ", "));
441 ND_PRINT((ndo, "%s", cp + 1));
442 idx++;
443 }
444 continue;
445 }
446
447 if (tag == TAG_EXTENDED_REQUEST) {
448 first = 1;
449 while (len > 1) {
450 len -= 2;
451 us = EXTRACT_16BITS(bp);
452 bp += 2;
453 cp = tok2str(xtag2str, "?xT%u", us);
454 if (!first)
455 ND_PRINT((ndo, "+"));
456 ND_PRINT((ndo, "%s", cp + 1));
457 first = 0;
458 }
459 continue;
460 }
461
462 /* Print data */
463 if (c == '?') {
464 /* Base default formats for unknown tags on data size */
465 if (len & 1)
466 c = 'b';
467 else if (len & 2)
468 c = 's';
469 else
470 c = 'l';
471 }
472 first = 1;
473 switch (c) {
474
475 case 'a':
476 /* ascii strings */
477 ND_PRINT((ndo, "\""));
478 if (fn_printn(bp, len, ndo->ndo_snapend)) {
479 ND_PRINT((ndo, "\""));
480 goto trunc;
481 }
482 ND_PRINT((ndo, "\""));
483 bp += len;
484 len = 0;
485 break;
486
487 case 'i':
488 case 'l':
489 case 'L':
490 /* ip addresses/32-bit words */
491 while (len >= sizeof(ul)) {
492 if (!first)
493 ND_PRINT((ndo, ","));
494 ul = EXTRACT_32BITS(bp);
495 if (c == 'i') {
496 ul = htonl(ul);
497 ND_PRINT((ndo, "%s", ipaddr_string(&ul)));
498 } else if (c == 'L')
499 ND_PRINT((ndo, "%d", ul));
500 else
501 ND_PRINT((ndo, "%u", ul));
502 bp += sizeof(ul);
503 len -= sizeof(ul);
504 first = 0;
505 }
506 break;
507
508 case 'p':
509 /* IP address pairs */
510 while (len >= 2*sizeof(ul)) {
511 if (!first)
512 ND_PRINT((ndo, ","));
513 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
514 ND_PRINT((ndo, "(%s:", ipaddr_string(&ul)));
515 bp += sizeof(ul);
516 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
517 ND_PRINT((ndo, "%s)", ipaddr_string(&ul)));
518 bp += sizeof(ul);
519 len -= 2*sizeof(ul);
520 first = 0;
521 }
522 break;
523
524 case 's':
525 /* shorts */
526 while (len >= sizeof(us)) {
527 if (!first)
528 ND_PRINT((ndo, ","));
529 us = EXTRACT_16BITS(bp);
530 ND_PRINT((ndo, "%u", us));
531 bp += sizeof(us);
532 len -= sizeof(us);
533 first = 0;
534 }
535 break;
536
537 case 'B':
538 /* boolean */
539 while (len > 0) {
540 if (!first)
541 ND_PRINT((ndo, ","));
542 switch (*bp) {
543 case 0:
544 ND_PRINT((ndo, "N"));
545 break;
546 case 1:
547 ND_PRINT((ndo, "Y"));
548 break;
549 default:
550 ND_PRINT((ndo, "%u?", *bp));
551 break;
552 }
553 ++bp;
554 --len;
555 first = 0;
556 }
557 break;
558
559 case 'b':
560 case 'x':
561 default:
562 /* Bytes */
563 while (len > 0) {
564 if (!first)
565 ND_PRINT((ndo, c == 'x' ? ":" : "."));
566 if (c == 'x')
567 ND_PRINT((ndo, "%02x", *bp));
568 else
569 ND_PRINT((ndo, "%u", *bp));
570 ++bp;
571 --len;
572 first = 0;
573 }
574 break;
575
576 case '$':
577 /* Guys we can't handle with one of the usual cases */
578 switch (tag) {
579
580 case TAG_NETBIOS_NODE:
581 /* this option should be at least 1 byte long */
582 if (len < 1) {
583 ND_PRINT((ndo, "ERROR: option %u len %u < 1 bytes",
584 TAG_NETBIOS_NODE, len));
585 break;
586 }
587 tag = *bp++;
588 --len;
589 ND_PRINT((ndo, "%s", tok2str(nbo2str, NULL, tag)));
590 break;
591
592 case TAG_OPT_OVERLOAD:
593 /* this option should be at least 1 byte long */
594 if (len < 1) {
595 ND_PRINT((ndo, "ERROR: option %u len %u < 1 bytes",
596 TAG_OPT_OVERLOAD, len));
597 break;
598 }
599 tag = *bp++;
600 --len;
601 ND_PRINT((ndo, "%s", tok2str(oo2str, NULL, tag)));
602 break;
603
604 case TAG_CLIENT_FQDN:
605 /* this option should be at least 3 bytes long */
606 if (len < 3) {
607 ND_PRINT((ndo, "ERROR: option %u len %u < 3 bytes",
608 TAG_CLIENT_FQDN, len));
609 bp += len;
610 len = 0;
611 break;
612 }
613 if (*bp)
614 ND_PRINT((ndo, "[%s] ", client_fqdn_flags(*bp)));
615 bp++;
616 if (*bp || *(bp+1))
617 ND_PRINT((ndo, "%u/%u ", *bp, *(bp+1)));
618 bp += 2;
619 ND_PRINT((ndo, "\""));
620 if (fn_printn(bp, len - 3, ndo->ndo_snapend)) {
621 ND_PRINT((ndo, "\""));
622 goto trunc;
623 }
624 ND_PRINT((ndo, "\""));
625 bp += len - 3;
626 len = 0;
627 break;
628
629 case TAG_CLIENT_ID:
630 { int type;
631
632 /* this option should be at least 1 byte long */
633 if (len < 1) {
634 ND_PRINT((ndo, "ERROR: option %u len %u < 1 bytes",
635 TAG_CLIENT_ID, len));
636 break;
637 }
638 type = *bp++;
639 len--;
640 if (type == 0) {
641 ND_PRINT((ndo, "\""));
642 if (fn_printn(bp, len, ndo->ndo_snapend)) {
643 ND_PRINT((ndo, "\""));
644 goto trunc;
645 }
646 ND_PRINT((ndo, "\""));
647 bp += len;
648 len = 0;
649 break;
650 } else {
651 ND_PRINT((ndo, "%s ", tok2str(arp2str, "hardware-type %u,", type)));
652 while (len > 0) {
653 if (!first)
654 ND_PRINT((ndo, ":"));
655 ND_PRINT((ndo, "%02x", *bp));
656 ++bp;
657 --len;
658 first = 0;
659 }
660 }
661 break;
662 }
663
664 case TAG_AGENT_CIRCUIT:
665 while (len >= 2) {
666 subopt = *bp++;
667 suboptlen = *bp++;
668 len -= 2;
669 if (suboptlen > len) {
670 ND_PRINT((ndo, "\n\t %s SubOption %u, length %u: length goes past end of option",
671 tok2str(agent_suboption_values, "Unknown", subopt),
672 subopt,
673 suboptlen));
674 bp += len;
675 len = 0;
676 break;
677 }
678 ND_PRINT((ndo, "\n\t %s SubOption %u, length %u: ",
679 tok2str(agent_suboption_values, "Unknown", subopt),
680 subopt,
681 suboptlen));
682 switch (subopt) {
683
684 case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
685 case AGENT_SUBOPTION_REMOTE_ID:
686 case AGENT_SUBOPTION_SUBSCRIBER_ID:
687 fn_printn(bp, suboptlen, NULL);
688 break;
689
690 default:
691 print_unknown_data(ndo, bp, "\n\t\t", suboptlen);
692 }
693
694 len -= suboptlen;
695 bp += suboptlen;
696 }
697 break;
698
699 case TAG_CLASSLESS_STATIC_RT:
700 case TAG_CLASSLESS_STA_RT_MS:
701 {
702 u_int mask_width, significant_octets, i;
703
704 /* this option should be at least 5 bytes long */
705 if (len < 5) {
706 ND_PRINT((ndo, "ERROR: option %u len %u < 5 bytes",
707 TAG_CLASSLESS_STATIC_RT, len));
708 bp += len;
709 len = 0;
710 break;
711 }
712 while (len > 0) {
713 if (!first)
714 ND_PRINT((ndo, ","));
715 mask_width = *bp++;
716 len--;
717 /* mask_width <= 32 */
718 if (mask_width > 32) {
719 ND_PRINT((ndo, "[ERROR: Mask width (%d) > 32]", mask_width));
720 bp += len;
721 len = 0;
722 break;
723 }
724 significant_octets = (mask_width + 7) / 8;
725 /* significant octets + router(4) */
726 if (len < significant_octets + 4) {
727 ND_PRINT((ndo, "[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4));
728 bp += len;
729 len = 0;
730 break;
731 }
732 ND_PRINT((ndo, "("));
733 if (mask_width == 0)
734 ND_PRINT((ndo, "default"));
735 else {
736 for (i = 0; i < significant_octets ; i++) {
737 if (i > 0)
738 ND_PRINT((ndo, "."));
739 ND_PRINT((ndo, "%d", *bp++));
740 }
741 for (i = significant_octets ; i < 4 ; i++)
742 ND_PRINT((ndo, ".0"));
743 ND_PRINT((ndo, "/%d", mask_width));
744 }
745 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
746 ND_PRINT((ndo, ":%s)", ipaddr_string(&ul)));
747 bp += sizeof(ul);
748 len -= (significant_octets + 4);
749 first = 0;
750 }
751 }
752 break;
753
754 default:
755 ND_PRINT((ndo, "[unknown special tag %u, size %u]",
756 tag, len));
757 bp += len;
758 len = 0;
759 break;
760 }
761 break;
762 }
763 /* Data left over? */
764 if (len) {
765 ND_PRINT((ndo, "\n\t trailing data length %u", len));
766 bp += len;
767 }
768 }
769 return;
770 trunc:
771 ND_PRINT((ndo, "|[rfc1048]"));
772 }
773
774 static void
775 cmu_print(netdissect_options *ndo,
776 register const u_char *bp)
777 {
778 register const struct cmu_vend *cmu;
779
780 #define PRINTCMUADDR(m, s) { ND_TCHECK(cmu->m); \
781 if (cmu->m.s_addr != 0) \
782 ND_PRINT((ndo, " %s:%s", s, ipaddr_string(&cmu->m.s_addr))); }
783
784 ND_PRINT((ndo, " vend-cmu"));
785 cmu = (const struct cmu_vend *)bp;
786
787 /* Only print if there are unknown bits */
788 ND_TCHECK(cmu->v_flags);
789 if ((cmu->v_flags & ~(VF_SMASK)) != 0)
790 ND_PRINT((ndo, " F:0x%x", cmu->v_flags));
791 PRINTCMUADDR(v_dgate, "DG");
792 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
793 PRINTCMUADDR(v_dns1, "NS1");
794 PRINTCMUADDR(v_dns2, "NS2");
795 PRINTCMUADDR(v_ins1, "IEN1");
796 PRINTCMUADDR(v_ins2, "IEN2");
797 PRINTCMUADDR(v_ts1, "TS1");
798 PRINTCMUADDR(v_ts2, "TS2");
799 return;
800
801 trunc:
802 ND_PRINT((ndo, "%s", tstr));
803 #undef PRINTCMUADDR
804 }
805
806 static char *
807 client_fqdn_flags(u_int flags)
808 {
809 static char buf[8+1];
810 int i = 0;
811
812 if (flags & CLIENT_FQDN_FLAGS_S)
813 buf[i++] = 'S';
814 if (flags & CLIENT_FQDN_FLAGS_O)
815 buf[i++] = 'O';
816 if (flags & CLIENT_FQDN_FLAGS_E)
817 buf[i++] = 'E';
818 if (flags & CLIENT_FQDN_FLAGS_N)
819 buf[i++] = 'N';
820 buf[i] = '\0';
821
822 return buf;
823 }