xref: /dflybsd-src/contrib/tcpdump/print-bootp.c (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
341c99275SPeter Avalos  *	The Regents of the University of California.  All rights reserved.
441c99275SPeter Avalos  *
541c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos  * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos  * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos  * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos  * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos  * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos  * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos  * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos  * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos  * or promote products derived from this software without specific prior
1641c99275SPeter Avalos  * written permission.
1741c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos  */
21411677aeSAaron LI 
22411677aeSAaron LI /* \summary: BOOTP and IPv4 DHCP printer */
2341c99275SPeter Avalos 
2441c99275SPeter Avalos #ifdef HAVE_CONFIG_H
25*ed775ee7SAntonio Huete Jimenez #include <config.h>
2641c99275SPeter Avalos #endif
2741c99275SPeter Avalos 
28*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
2941c99275SPeter Avalos 
3041c99275SPeter Avalos #include <string.h>
3141c99275SPeter Avalos 
32411677aeSAaron LI #include "netdissect.h"
3341c99275SPeter Avalos #include "addrtoname.h"
3441c99275SPeter Avalos #include "extract.h"
3541c99275SPeter Avalos 
36411677aeSAaron LI 
37411677aeSAaron LI /*
38411677aeSAaron LI  * Bootstrap Protocol (BOOTP).  RFC951 and RFC1048.
39411677aeSAaron LI  *
40411677aeSAaron LI  * This file specifies the "implementation-independent" BOOTP protocol
41411677aeSAaron LI  * information which is common to both client and server.
42411677aeSAaron LI  *
43411677aeSAaron LI  * Copyright 1988 by Carnegie Mellon.
44411677aeSAaron LI  *
45411677aeSAaron LI  * Permission to use, copy, modify, and distribute this program for any
46411677aeSAaron LI  * purpose and without fee is hereby granted, provided that this copyright
47411677aeSAaron LI  * and permission notice appear on all copies and supporting documentation,
48411677aeSAaron LI  * the name of Carnegie Mellon not be used in advertising or publicity
49411677aeSAaron LI  * pertaining to distribution of the program without specific prior
50411677aeSAaron LI  * permission, and notice be given in supporting documentation that copying
51411677aeSAaron LI  * and distribution is by permission of Carnegie Mellon and Stanford
52411677aeSAaron LI  * University.  Carnegie Mellon makes no representations about the
53411677aeSAaron LI  * suitability of this software for any purpose.  It is provided "as is"
54411677aeSAaron LI  * without express or implied warranty.
55411677aeSAaron LI  */
56411677aeSAaron LI 
57411677aeSAaron LI struct bootp {
58*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	bp_op;		/* packet opcode type */
59*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	bp_htype;	/* hardware addr type */
60*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	bp_hlen;	/* hardware addr length */
61*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	bp_hops;	/* gateway hops */
62*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t	bp_xid;		/* transaction ID */
63*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t	bp_secs;	/* seconds since boot began */
64*ed775ee7SAntonio Huete Jimenez 	nd_uint16_t	bp_flags;	/* flags - see bootp_flag_values[]
65411677aeSAaron LI 					   in print-bootp.c */
66*ed775ee7SAntonio Huete Jimenez 	nd_ipv4		bp_ciaddr;	/* client IP address */
67*ed775ee7SAntonio Huete Jimenez 	nd_ipv4		bp_yiaddr;	/* 'your' IP address */
68*ed775ee7SAntonio Huete Jimenez 	nd_ipv4		bp_siaddr;	/* server IP address */
69*ed775ee7SAntonio Huete Jimenez 	nd_ipv4		bp_giaddr;	/* gateway IP address */
70*ed775ee7SAntonio Huete Jimenez 	nd_byte		bp_chaddr[16];	/* client hardware address */
71*ed775ee7SAntonio Huete Jimenez 	nd_byte		bp_sname[64];	/* server host name */
72*ed775ee7SAntonio Huete Jimenez 	nd_byte		bp_file[128];	/* boot file name */
73*ed775ee7SAntonio Huete Jimenez 	nd_byte		bp_vend[64];	/* vendor-specific area */
74*ed775ee7SAntonio Huete Jimenez };
75411677aeSAaron LI 
76411677aeSAaron LI #define BOOTPREPLY	2
77411677aeSAaron LI #define BOOTPREQUEST	1
78411677aeSAaron LI 
79411677aeSAaron LI /*
80411677aeSAaron LI  * Vendor magic cookie (v_magic) for CMU
81411677aeSAaron LI  */
82411677aeSAaron LI #define VM_CMU		"CMU"
83411677aeSAaron LI 
84411677aeSAaron LI /*
85411677aeSAaron LI  * Vendor magic cookie (v_magic) for RFC1048
86411677aeSAaron LI  */
87411677aeSAaron LI #define VM_RFC1048	{ 99, 130, 83, 99 }
88411677aeSAaron LI 
89411677aeSAaron LI /*
90411677aeSAaron LI  * RFC1048 tag values used to specify what information is being supplied in
91411677aeSAaron LI  * the vendor field of the packet.
92411677aeSAaron LI  */
93411677aeSAaron LI 
94411677aeSAaron LI #define TAG_PAD			((uint8_t)   0)
95411677aeSAaron LI #define TAG_SUBNET_MASK		((uint8_t)   1)
96411677aeSAaron LI #define TAG_TIME_OFFSET		((uint8_t)   2)
97411677aeSAaron LI #define TAG_GATEWAY		((uint8_t)   3)
98411677aeSAaron LI #define TAG_TIME_SERVER		((uint8_t)   4)
99411677aeSAaron LI #define TAG_NAME_SERVER		((uint8_t)   5)
100411677aeSAaron LI #define TAG_DOMAIN_SERVER	((uint8_t)   6)
101411677aeSAaron LI #define TAG_LOG_SERVER		((uint8_t)   7)
102411677aeSAaron LI #define TAG_COOKIE_SERVER	((uint8_t)   8)
103411677aeSAaron LI #define TAG_LPR_SERVER		((uint8_t)   9)
104411677aeSAaron LI #define TAG_IMPRESS_SERVER	((uint8_t)  10)
105411677aeSAaron LI #define TAG_RLP_SERVER		((uint8_t)  11)
106411677aeSAaron LI #define TAG_HOSTNAME		((uint8_t)  12)
107411677aeSAaron LI #define TAG_BOOTSIZE		((uint8_t)  13)
108411677aeSAaron LI #define TAG_END			((uint8_t) 255)
109411677aeSAaron LI /* RFC1497 tags */
110411677aeSAaron LI #define	TAG_DUMPPATH		((uint8_t)  14)
111411677aeSAaron LI #define	TAG_DOMAINNAME		((uint8_t)  15)
112411677aeSAaron LI #define	TAG_SWAP_SERVER		((uint8_t)  16)
113411677aeSAaron LI #define	TAG_ROOTPATH		((uint8_t)  17)
114411677aeSAaron LI #define	TAG_EXTPATH		((uint8_t)  18)
115411677aeSAaron LI /* RFC2132 */
116411677aeSAaron LI #define	TAG_IP_FORWARD		((uint8_t)  19)
117411677aeSAaron LI #define	TAG_NL_SRCRT		((uint8_t)  20)
118411677aeSAaron LI #define	TAG_PFILTERS		((uint8_t)  21)
119411677aeSAaron LI #define	TAG_REASS_SIZE		((uint8_t)  22)
120411677aeSAaron LI #define	TAG_DEF_TTL		((uint8_t)  23)
121411677aeSAaron LI #define	TAG_MTU_TIMEOUT		((uint8_t)  24)
122411677aeSAaron LI #define	TAG_MTU_TABLE		((uint8_t)  25)
123411677aeSAaron LI #define	TAG_INT_MTU		((uint8_t)  26)
124411677aeSAaron LI #define	TAG_LOCAL_SUBNETS	((uint8_t)  27)
125411677aeSAaron LI #define	TAG_BROAD_ADDR		((uint8_t)  28)
126411677aeSAaron LI #define	TAG_DO_MASK_DISC	((uint8_t)  29)
127411677aeSAaron LI #define	TAG_SUPPLY_MASK		((uint8_t)  30)
128411677aeSAaron LI #define	TAG_DO_RDISC		((uint8_t)  31)
129411677aeSAaron LI #define	TAG_RTR_SOL_ADDR	((uint8_t)  32)
130411677aeSAaron LI #define	TAG_STATIC_ROUTE	((uint8_t)  33)
131411677aeSAaron LI #define	TAG_USE_TRAILERS	((uint8_t)  34)
132411677aeSAaron LI #define	TAG_ARP_TIMEOUT		((uint8_t)  35)
133411677aeSAaron LI #define	TAG_ETH_ENCAP		((uint8_t)  36)
134411677aeSAaron LI #define	TAG_TCP_TTL		((uint8_t)  37)
135411677aeSAaron LI #define	TAG_TCP_KEEPALIVE	((uint8_t)  38)
136411677aeSAaron LI #define	TAG_KEEPALIVE_GO	((uint8_t)  39)
137411677aeSAaron LI #define	TAG_NIS_DOMAIN		((uint8_t)  40)
138411677aeSAaron LI #define	TAG_NIS_SERVERS		((uint8_t)  41)
139411677aeSAaron LI #define	TAG_NTP_SERVERS		((uint8_t)  42)
140411677aeSAaron LI #define	TAG_VENDOR_OPTS		((uint8_t)  43)
141411677aeSAaron LI #define	TAG_NETBIOS_NS		((uint8_t)  44)
142411677aeSAaron LI #define	TAG_NETBIOS_DDS		((uint8_t)  45)
143411677aeSAaron LI #define	TAG_NETBIOS_NODE	((uint8_t)  46)
144411677aeSAaron LI #define	TAG_NETBIOS_SCOPE	((uint8_t)  47)
145411677aeSAaron LI #define	TAG_XWIN_FS		((uint8_t)  48)
146411677aeSAaron LI #define	TAG_XWIN_DM		((uint8_t)  49)
147411677aeSAaron LI #define	TAG_NIS_P_DOMAIN	((uint8_t)  64)
148411677aeSAaron LI #define	TAG_NIS_P_SERVERS	((uint8_t)  65)
149411677aeSAaron LI #define	TAG_MOBILE_HOME		((uint8_t)  68)
150411677aeSAaron LI #define	TAG_SMPT_SERVER		((uint8_t)  69)
151411677aeSAaron LI #define	TAG_POP3_SERVER		((uint8_t)  70)
152411677aeSAaron LI #define	TAG_NNTP_SERVER		((uint8_t)  71)
153411677aeSAaron LI #define	TAG_WWW_SERVER		((uint8_t)  72)
154411677aeSAaron LI #define	TAG_FINGER_SERVER	((uint8_t)  73)
155411677aeSAaron LI #define	TAG_IRC_SERVER		((uint8_t)  74)
156411677aeSAaron LI #define	TAG_STREETTALK_SRVR	((uint8_t)  75)
157411677aeSAaron LI #define	TAG_STREETTALK_STDA	((uint8_t)  76)
158411677aeSAaron LI /* DHCP options */
159411677aeSAaron LI #define	TAG_REQUESTED_IP	((uint8_t)  50)
160411677aeSAaron LI #define	TAG_IP_LEASE		((uint8_t)  51)
161411677aeSAaron LI #define	TAG_OPT_OVERLOAD	((uint8_t)  52)
162411677aeSAaron LI #define	TAG_TFTP_SERVER		((uint8_t)  66)
163411677aeSAaron LI #define	TAG_BOOTFILENAME	((uint8_t)  67)
164411677aeSAaron LI #define	TAG_DHCP_MESSAGE	((uint8_t)  53)
165411677aeSAaron LI #define	TAG_SERVER_ID		((uint8_t)  54)
166411677aeSAaron LI #define	TAG_PARM_REQUEST	((uint8_t)  55)
167411677aeSAaron LI #define	TAG_MESSAGE		((uint8_t)  56)
168411677aeSAaron LI #define	TAG_MAX_MSG_SIZE	((uint8_t)  57)
169411677aeSAaron LI #define	TAG_RENEWAL_TIME	((uint8_t)  58)
170411677aeSAaron LI #define	TAG_REBIND_TIME		((uint8_t)  59)
171411677aeSAaron LI #define	TAG_VENDOR_CLASS	((uint8_t)  60)
172411677aeSAaron LI #define	TAG_CLIENT_ID		((uint8_t)  61)
173411677aeSAaron LI /* RFC 2241 */
174411677aeSAaron LI #define	TAG_NDS_SERVERS		((uint8_t)  85)
175411677aeSAaron LI #define	TAG_NDS_TREE_NAME	((uint8_t)  86)
176411677aeSAaron LI #define	TAG_NDS_CONTEXT		((uint8_t)  87)
177411677aeSAaron LI /* RFC 2242 */
178411677aeSAaron LI #define	TAG_NDS_IPDOMAIN	((uint8_t)  62)
179411677aeSAaron LI #define	TAG_NDS_IPINFO		((uint8_t)  63)
180411677aeSAaron LI /* RFC 2485 */
181411677aeSAaron LI #define	TAG_OPEN_GROUP_UAP	((uint8_t)  98)
182411677aeSAaron LI /* RFC 2563 */
183411677aeSAaron LI #define	TAG_DISABLE_AUTOCONF	((uint8_t) 116)
184411677aeSAaron LI /* RFC 2610 */
185411677aeSAaron LI #define	TAG_SLP_DA		((uint8_t)  78)
186411677aeSAaron LI #define	TAG_SLP_SCOPE		((uint8_t)  79)
187411677aeSAaron LI /* RFC 2937 */
188411677aeSAaron LI #define	TAG_NS_SEARCH		((uint8_t) 117)
189411677aeSAaron LI /* RFC 3004 - The User Class Option for DHCP */
190411677aeSAaron LI #define	TAG_USER_CLASS		((uint8_t)  77)
191411677aeSAaron LI /* RFC 3011 */
192411677aeSAaron LI #define	TAG_IP4_SUBNET_SELECT	((uint8_t) 118)
193411677aeSAaron LI /* RFC 3442 */
194411677aeSAaron LI #define TAG_CLASSLESS_STATIC_RT	((uint8_t) 121)
195411677aeSAaron LI #define TAG_CLASSLESS_STA_RT_MS	((uint8_t) 249)
196411677aeSAaron LI /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
197411677aeSAaron LI #define	TAG_TFTP_SERVER_ADDRESS	((uint8_t) 150)
198*ed775ee7SAntonio Huete Jimenez /* https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml */
199411677aeSAaron LI #define	TAG_SLP_NAMING_AUTH	((uint8_t)  80)
200411677aeSAaron LI #define	TAG_CLIENT_FQDN		((uint8_t)  81)
201411677aeSAaron LI #define	TAG_AGENT_CIRCUIT	((uint8_t)  82)
202411677aeSAaron LI #define	TAG_AGENT_REMOTE	((uint8_t)  83)
203411677aeSAaron LI #define	TAG_TZ_STRING		((uint8_t)  88)
204411677aeSAaron LI #define	TAG_FQDN_OPTION		((uint8_t)  89)
205411677aeSAaron LI #define	TAG_AUTH		((uint8_t)  90)
206*ed775ee7SAntonio Huete Jimenez #define	TAG_CLIENT_LAST_TRANSACTION_TIME	((uint8_t)  91)
207*ed775ee7SAntonio Huete Jimenez #define	TAG_ASSOCIATED_IP			((uint8_t)  92)
208411677aeSAaron LI #define	TAG_CLIENT_ARCH		((uint8_t)  93)
209411677aeSAaron LI #define	TAG_CLIENT_NDI		((uint8_t)  94)
210411677aeSAaron LI #define	TAG_CLIENT_GUID		((uint8_t)  97)
211411677aeSAaron LI #define	TAG_LDAP_URL		((uint8_t)  95)
212411677aeSAaron LI /* RFC 4833, TZ codes */
213411677aeSAaron LI #define	TAG_TZ_PCODE    	((uint8_t) 100)
214411677aeSAaron LI #define	TAG_TZ_TCODE    	((uint8_t) 101)
215411677aeSAaron LI #define	TAG_NETINFO_PARENT	((uint8_t) 112)
216411677aeSAaron LI #define	TAG_NETINFO_PARENT_TAG	((uint8_t) 113)
217411677aeSAaron LI #define	TAG_URL			((uint8_t) 114)
218411677aeSAaron LI #define TAG_MUDURL              ((uint8_t) 161)
219411677aeSAaron LI 
220411677aeSAaron LI /* DHCP Message types (values for TAG_DHCP_MESSAGE option) */
221411677aeSAaron LI #define DHCPDISCOVER	1
222411677aeSAaron LI #define DHCPOFFER	2
223411677aeSAaron LI #define DHCPREQUEST	3
224411677aeSAaron LI #define DHCPDECLINE	4
225411677aeSAaron LI #define DHCPACK		5
226411677aeSAaron LI #define DHCPNAK		6
227411677aeSAaron LI #define DHCPRELEASE	7
228411677aeSAaron LI #define DHCPINFORM	8
229*ed775ee7SAntonio Huete Jimenez /* Defined in RFC4388 */
230*ed775ee7SAntonio Huete Jimenez #define DHCPLEASEQUERY       10
231*ed775ee7SAntonio Huete Jimenez #define DHCPLEASEUNASSIGNED  11
232*ed775ee7SAntonio Huete Jimenez #define DHCPLEASEUNKNOWN     12
233*ed775ee7SAntonio Huete Jimenez #define DHCPLEASEACTIVE      13
234*ed775ee7SAntonio Huete Jimenez 
235411677aeSAaron LI 
236411677aeSAaron LI /*
237411677aeSAaron LI  * "vendor" data permitted for CMU bootp clients.
238411677aeSAaron LI  */
239411677aeSAaron LI 
240411677aeSAaron LI struct cmu_vend {
241*ed775ee7SAntonio Huete Jimenez 	nd_byte		v_magic[4];	/* magic number */
242*ed775ee7SAntonio Huete Jimenez 	nd_uint32_t	v_flags;	/* flags/opcodes, etc. */
243*ed775ee7SAntonio Huete Jimenez 	nd_ipv4		v_smask;	/* Subnet mask */
244*ed775ee7SAntonio Huete Jimenez 	nd_ipv4		v_dgate;	/* Default gateway */
245*ed775ee7SAntonio Huete Jimenez 	nd_ipv4		v_dns1, v_dns2; /* Domain name servers */
246*ed775ee7SAntonio Huete Jimenez 	nd_ipv4		v_ins1, v_ins2; /* IEN-116 name servers */
247*ed775ee7SAntonio Huete Jimenez 	nd_ipv4		v_ts1, v_ts2;	/* Time servers */
248*ed775ee7SAntonio Huete Jimenez 	nd_byte		v_unused[24];	/* currently unused */
249*ed775ee7SAntonio Huete Jimenez };
250411677aeSAaron LI 
251411677aeSAaron LI 
252411677aeSAaron LI /* v_flags values */
253411677aeSAaron LI #define VF_SMASK	1	/* Subnet mask field contains valid data */
254411677aeSAaron LI 
255411677aeSAaron LI /* RFC 4702 DHCP Client FQDN Option */
256411677aeSAaron LI 
257411677aeSAaron LI #define CLIENT_FQDN_FLAGS_S	0x01
258411677aeSAaron LI #define CLIENT_FQDN_FLAGS_O	0x02
259411677aeSAaron LI #define CLIENT_FQDN_FLAGS_E	0x04
260411677aeSAaron LI #define CLIENT_FQDN_FLAGS_N	0x08
261411677aeSAaron LI /* end of original bootp.h */
262411677aeSAaron LI 
263411677aeSAaron LI static void rfc1048_print(netdissect_options *, const u_char *);
264411677aeSAaron LI static void cmu_print(netdissect_options *, const u_char *);
26541c99275SPeter Avalos static char *client_fqdn_flags(u_int flags);
26641c99275SPeter Avalos 
26741c99275SPeter Avalos static const struct tok bootp_flag_values[] = {
26841c99275SPeter Avalos 	{ 0x8000,	"Broadcast" },
26941c99275SPeter Avalos 	{ 0, NULL}
27041c99275SPeter Avalos };
27141c99275SPeter Avalos 
27241c99275SPeter Avalos static const struct tok bootp_op_values[] = {
27341c99275SPeter Avalos 	{ BOOTPREQUEST,	"Request" },
27441c99275SPeter Avalos 	{ BOOTPREPLY,	"Reply" },
27541c99275SPeter Avalos 	{ 0, NULL}
27641c99275SPeter Avalos };
27741c99275SPeter Avalos 
27841c99275SPeter Avalos /*
27941c99275SPeter Avalos  * Print bootp requests
28041c99275SPeter Avalos  */
28141c99275SPeter Avalos void
bootp_print(netdissect_options * ndo,const u_char * cp,u_int length)282411677aeSAaron LI bootp_print(netdissect_options *ndo,
283*ed775ee7SAntonio Huete Jimenez 	    const u_char *cp, u_int length)
28441c99275SPeter Avalos {
285*ed775ee7SAntonio Huete Jimenez 	const struct bootp *bp;
28641c99275SPeter Avalos 	static const u_char vm_cmu[4] = VM_CMU;
28741c99275SPeter Avalos 	static const u_char vm_rfc1048[4] = VM_RFC1048;
288*ed775ee7SAntonio Huete Jimenez 	uint8_t bp_op, bp_htype, bp_hlen;
28941c99275SPeter Avalos 
290*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "bootp";
29141c99275SPeter Avalos 	bp = (const struct bootp *)cp;
292*ed775ee7SAntonio Huete Jimenez 	bp_op = GET_U_1(bp->bp_op);
293*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("BOOTP/DHCP, %s",
294*ed775ee7SAntonio Huete Jimenez 		  tok2str(bootp_op_values, "unknown (0x%02x)", bp_op));
29541c99275SPeter Avalos 
296*ed775ee7SAntonio Huete Jimenez 	bp_htype = GET_U_1(bp->bp_htype);
297*ed775ee7SAntonio Huete Jimenez 	bp_hlen = GET_U_1(bp->bp_hlen);
298*ed775ee7SAntonio Huete Jimenez 	if (bp_htype == 1 && bp_hlen == MAC_ADDR_LEN && bp_op == BOOTPREQUEST) {
299*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" from %s", GET_ETHERADDR_STRING(bp->bp_chaddr));
30041c99275SPeter Avalos 	}
30141c99275SPeter Avalos 
302*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(", length %u", length);
30341c99275SPeter Avalos 
304411677aeSAaron LI 	if (!ndo->ndo_vflag)
30541c99275SPeter Avalos 		return;
30641c99275SPeter Avalos 
307*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_2(bp->bp_secs);
30841c99275SPeter Avalos 
30941c99275SPeter Avalos 	/* The usual hardware address type is 1 (10Mb Ethernet) */
310*ed775ee7SAntonio Huete Jimenez 	if (bp_htype != 1)
311*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", htype %u", bp_htype);
31241c99275SPeter Avalos 
31341c99275SPeter Avalos 	/* The usual length for 10Mb Ethernet address is 6 bytes */
314*ed775ee7SAntonio Huete Jimenez 	if (bp_htype != 1 || bp_hlen != MAC_ADDR_LEN)
315*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", hlen %u", bp_hlen);
31641c99275SPeter Avalos 
31741c99275SPeter Avalos 	/* Only print interesting fields */
318*ed775ee7SAntonio Huete Jimenez 	if (GET_U_1(bp->bp_hops))
319*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", hops %u", GET_U_1(bp->bp_hops));
320*ed775ee7SAntonio Huete Jimenez 	if (GET_BE_U_4(bp->bp_xid))
321*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", xid 0x%x", GET_BE_U_4(bp->bp_xid));
322*ed775ee7SAntonio Huete Jimenez 	if (GET_BE_U_2(bp->bp_secs))
323*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", secs %u", GET_BE_U_2(bp->bp_secs));
32441c99275SPeter Avalos 
325*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(", Flags [%s]",
326*ed775ee7SAntonio Huete Jimenez 		  bittok2str(bootp_flag_values, "none", GET_BE_U_2(bp->bp_flags)));
327411677aeSAaron LI 	if (ndo->ndo_vflag > 1)
328*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" (0x%04x)", GET_BE_U_2(bp->bp_flags));
32941c99275SPeter Avalos 
33041c99275SPeter Avalos 	/* Client's ip address */
331*ed775ee7SAntonio Huete Jimenez 	if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_ciaddr))
332*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n\t  Client-IP %s", GET_IPADDR_STRING(bp->bp_ciaddr));
33341c99275SPeter Avalos 
33441c99275SPeter Avalos 	/* 'your' ip address (bootp client) */
335*ed775ee7SAntonio Huete Jimenez 	if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_yiaddr))
336*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n\t  Your-IP %s", GET_IPADDR_STRING(bp->bp_yiaddr));
33741c99275SPeter Avalos 
33841c99275SPeter Avalos 	/* Server's ip address */
339*ed775ee7SAntonio Huete Jimenez 	if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_siaddr))
340*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n\t  Server-IP %s", GET_IPADDR_STRING(bp->bp_siaddr));
34141c99275SPeter Avalos 
34241c99275SPeter Avalos 	/* Gateway's ip address */
343*ed775ee7SAntonio Huete Jimenez 	if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_giaddr))
344*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n\t  Gateway-IP %s", GET_IPADDR_STRING(bp->bp_giaddr));
34541c99275SPeter Avalos 
34641c99275SPeter Avalos 	/* Client's Ethernet address */
347*ed775ee7SAntonio Huete Jimenez 	if (bp_htype == 1 && bp_hlen == MAC_ADDR_LEN) {
348*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n\t  Client-Ethernet-Address %s", GET_ETHERADDR_STRING(bp->bp_chaddr));
34941c99275SPeter Avalos 	}
35041c99275SPeter Avalos 
351*ed775ee7SAntonio Huete Jimenez 	if (GET_U_1(bp->bp_sname)) {	/* get first char only */
352*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n\t  sname \"");
353*ed775ee7SAntonio Huete Jimenez 		if (nd_printztn(ndo, bp->bp_sname, (u_int)sizeof(bp->bp_sname),
354411677aeSAaron LI 				ndo->ndo_snapend) == 0) {
355*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("\"");
356*ed775ee7SAntonio Huete Jimenez 			nd_print_trunc(ndo);
35741c99275SPeter Avalos 			return;
35841c99275SPeter Avalos 		}
359*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\"");
36041c99275SPeter Avalos 	}
361*ed775ee7SAntonio Huete Jimenez 	if (GET_U_1(bp->bp_file)) {	/* get first char only */
362*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n\t  file \"");
363*ed775ee7SAntonio Huete Jimenez 		if (nd_printztn(ndo, bp->bp_file, (u_int)sizeof(bp->bp_file),
364411677aeSAaron LI 				ndo->ndo_snapend) == 0) {
365*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("\"");
366*ed775ee7SAntonio Huete Jimenez 			nd_print_trunc(ndo);
36741c99275SPeter Avalos 			return;
36841c99275SPeter Avalos 		}
369*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\"");
37041c99275SPeter Avalos 	}
37141c99275SPeter Avalos 
37241c99275SPeter Avalos 	/* Decode the vendor buffer */
373*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_4(bp->bp_vend);
37441c99275SPeter Avalos 	if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
375411677aeSAaron LI 		    sizeof(uint32_t)) == 0)
376411677aeSAaron LI 		rfc1048_print(ndo, bp->bp_vend);
37741c99275SPeter Avalos 	else if (memcmp((const char *)bp->bp_vend, vm_cmu,
378411677aeSAaron LI 			sizeof(uint32_t)) == 0)
379411677aeSAaron LI 		cmu_print(ndo, bp->bp_vend);
38041c99275SPeter Avalos 	else {
381411677aeSAaron LI 		uint32_t ul;
38241c99275SPeter Avalos 
383*ed775ee7SAntonio Huete Jimenez 		ul = GET_BE_U_4(bp->bp_vend);
38441c99275SPeter Avalos 		if (ul != 0)
385*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("\n\t  Vendor-#0x%x", ul);
38641c99275SPeter Avalos 	}
38741c99275SPeter Avalos 
38841c99275SPeter Avalos 	return;
38941c99275SPeter Avalos trunc:
390*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
39141c99275SPeter Avalos }
39241c99275SPeter Avalos 
39341c99275SPeter Avalos /*
39441c99275SPeter Avalos  * The first character specifies the format to print:
39541c99275SPeter Avalos  *     i - ip address (32 bits)
39641c99275SPeter Avalos  *     p - ip address pairs (32 bits + 32 bits)
39741c99275SPeter Avalos  *     l - long (32 bits)
39841c99275SPeter Avalos  *     L - unsigned long (32 bits)
39941c99275SPeter Avalos  *     s - short (16 bits)
400*ed775ee7SAntonio Huete Jimenez  *     b - period-separated decimal bytes (variable length)
401*ed775ee7SAntonio Huete Jimenez  *     x - colon-separated hex bytes (variable length)
402*ed775ee7SAntonio Huete Jimenez  *     a - ASCII string (variable length)
40341c99275SPeter Avalos  *     B - on/off (8 bits)
40441c99275SPeter Avalos  *     $ - special (explicit code to handle)
40541c99275SPeter Avalos  */
406411677aeSAaron LI static const struct tok tag2str[] = {
40741c99275SPeter Avalos /* RFC1048 tags */
40841c99275SPeter Avalos 	{ TAG_PAD,		" PAD" },
40941c99275SPeter Avalos 	{ TAG_SUBNET_MASK,	"iSubnet-Mask" },	/* subnet mask (RFC950) */
41041c99275SPeter Avalos 	{ TAG_TIME_OFFSET,	"LTime-Zone" },	/* seconds from UTC */
41141c99275SPeter Avalos 	{ TAG_GATEWAY,		"iDefault-Gateway" },	/* default gateway */
41241c99275SPeter Avalos 	{ TAG_TIME_SERVER,	"iTime-Server" },	/* time servers (RFC868) */
41341c99275SPeter Avalos 	{ TAG_NAME_SERVER,	"iIEN-Name-Server" },	/* IEN name servers (IEN116) */
41441c99275SPeter Avalos 	{ TAG_DOMAIN_SERVER,	"iDomain-Name-Server" },	/* domain name (RFC1035) */
41541c99275SPeter Avalos 	{ TAG_LOG_SERVER,	"iLOG" },	/* MIT log servers */
41641c99275SPeter Avalos 	{ TAG_COOKIE_SERVER,	"iCS" },	/* cookie servers (RFC865) */
41741c99275SPeter Avalos 	{ TAG_LPR_SERVER,	"iLPR-Server" },	/* lpr server (RFC1179) */
41841c99275SPeter Avalos 	{ TAG_IMPRESS_SERVER,	"iIM" },	/* impress servers (Imagen) */
41941c99275SPeter Avalos 	{ TAG_RLP_SERVER,	"iRL" },	/* resource location (RFC887) */
420*ed775ee7SAntonio Huete Jimenez 	{ TAG_HOSTNAME,		"aHostname" },	/* ASCII hostname */
42141c99275SPeter Avalos 	{ TAG_BOOTSIZE,		"sBS" },	/* 512 byte blocks */
42241c99275SPeter Avalos 	{ TAG_END,		" END" },
42341c99275SPeter Avalos /* RFC1497 tags */
42441c99275SPeter Avalos 	{ TAG_DUMPPATH,		"aDP" },
42541c99275SPeter Avalos 	{ TAG_DOMAINNAME,	"aDomain-Name" },
42641c99275SPeter Avalos 	{ TAG_SWAP_SERVER,	"iSS" },
42741c99275SPeter Avalos 	{ TAG_ROOTPATH,		"aRP" },
42841c99275SPeter Avalos 	{ TAG_EXTPATH,		"aEP" },
42941c99275SPeter Avalos /* RFC2132 tags */
43041c99275SPeter Avalos 	{ TAG_IP_FORWARD,	"BIPF" },
43141c99275SPeter Avalos 	{ TAG_NL_SRCRT,		"BSRT" },
43241c99275SPeter Avalos 	{ TAG_PFILTERS,		"pPF" },
43341c99275SPeter Avalos 	{ TAG_REASS_SIZE,	"sRSZ" },
43441c99275SPeter Avalos 	{ TAG_DEF_TTL,		"bTTL" },
43541c99275SPeter Avalos 	{ TAG_MTU_TIMEOUT,	"lMTU-Timeout" },
43641c99275SPeter Avalos 	{ TAG_MTU_TABLE,	"sMTU-Table" },
43741c99275SPeter Avalos 	{ TAG_INT_MTU,		"sMTU" },
43841c99275SPeter Avalos 	{ TAG_LOCAL_SUBNETS,	"BLSN" },
43941c99275SPeter Avalos 	{ TAG_BROAD_ADDR,	"iBR" },
44041c99275SPeter Avalos 	{ TAG_DO_MASK_DISC,	"BMD" },
44141c99275SPeter Avalos 	{ TAG_SUPPLY_MASK,	"BMS" },
44241c99275SPeter Avalos 	{ TAG_DO_RDISC,		"BRouter-Discovery" },
44341c99275SPeter Avalos 	{ TAG_RTR_SOL_ADDR,	"iRSA" },
44441c99275SPeter Avalos 	{ TAG_STATIC_ROUTE,	"pStatic-Route" },
44541c99275SPeter Avalos 	{ TAG_USE_TRAILERS,	"BUT" },
44641c99275SPeter Avalos 	{ TAG_ARP_TIMEOUT,	"lAT" },
44741c99275SPeter Avalos 	{ TAG_ETH_ENCAP,	"BIE" },
44841c99275SPeter Avalos 	{ TAG_TCP_TTL,		"bTT" },
44941c99275SPeter Avalos 	{ TAG_TCP_KEEPALIVE,	"lKI" },
45041c99275SPeter Avalos 	{ TAG_KEEPALIVE_GO,	"BKG" },
45141c99275SPeter Avalos 	{ TAG_NIS_DOMAIN,	"aYD" },
45241c99275SPeter Avalos 	{ TAG_NIS_SERVERS,	"iYS" },
45341c99275SPeter Avalos 	{ TAG_NTP_SERVERS,	"iNTP" },
45441c99275SPeter Avalos 	{ TAG_VENDOR_OPTS,	"bVendor-Option" },
45541c99275SPeter Avalos 	{ TAG_NETBIOS_NS,	"iNetbios-Name-Server" },
45641c99275SPeter Avalos 	{ TAG_NETBIOS_DDS,	"iWDD" },
45741c99275SPeter Avalos 	{ TAG_NETBIOS_NODE,	"$Netbios-Node" },
45841c99275SPeter Avalos 	{ TAG_NETBIOS_SCOPE,	"aNetbios-Scope" },
45941c99275SPeter Avalos 	{ TAG_XWIN_FS,		"iXFS" },
46041c99275SPeter Avalos 	{ TAG_XWIN_DM,		"iXDM" },
46141c99275SPeter Avalos 	{ TAG_NIS_P_DOMAIN,	"sN+D" },
46241c99275SPeter Avalos 	{ TAG_NIS_P_SERVERS,	"iN+S" },
46341c99275SPeter Avalos 	{ TAG_MOBILE_HOME,	"iMH" },
46441c99275SPeter Avalos 	{ TAG_SMPT_SERVER,	"iSMTP" },
46541c99275SPeter Avalos 	{ TAG_POP3_SERVER,	"iPOP3" },
46641c99275SPeter Avalos 	{ TAG_NNTP_SERVER,	"iNNTP" },
46741c99275SPeter Avalos 	{ TAG_WWW_SERVER,	"iWWW" },
46841c99275SPeter Avalos 	{ TAG_FINGER_SERVER,	"iFG" },
46941c99275SPeter Avalos 	{ TAG_IRC_SERVER,	"iIRC" },
47041c99275SPeter Avalos 	{ TAG_STREETTALK_SRVR,	"iSTS" },
47141c99275SPeter Avalos 	{ TAG_STREETTALK_STDA,	"iSTDA" },
47241c99275SPeter Avalos 	{ TAG_REQUESTED_IP,	"iRequested-IP" },
47341c99275SPeter Avalos 	{ TAG_IP_LEASE,		"lLease-Time" },
47441c99275SPeter Avalos 	{ TAG_OPT_OVERLOAD,	"$OO" },
47541c99275SPeter Avalos 	{ TAG_TFTP_SERVER,	"aTFTP" },
47641c99275SPeter Avalos 	{ TAG_BOOTFILENAME,	"aBF" },
47741c99275SPeter Avalos 	{ TAG_DHCP_MESSAGE,	" DHCP-Message" },
47841c99275SPeter Avalos 	{ TAG_SERVER_ID,	"iServer-ID" },
47941c99275SPeter Avalos 	{ TAG_PARM_REQUEST,	"bParameter-Request" },
48041c99275SPeter Avalos 	{ TAG_MESSAGE,		"aMSG" },
48141c99275SPeter Avalos 	{ TAG_MAX_MSG_SIZE,	"sMSZ" },
48241c99275SPeter Avalos 	{ TAG_RENEWAL_TIME,	"lRN" },
48341c99275SPeter Avalos 	{ TAG_REBIND_TIME,	"lRB" },
48441c99275SPeter Avalos 	{ TAG_VENDOR_CLASS,	"aVendor-Class" },
48541c99275SPeter Avalos 	{ TAG_CLIENT_ID,	"$Client-ID" },
48641c99275SPeter Avalos /* RFC 2485 */
48741c99275SPeter Avalos 	{ TAG_OPEN_GROUP_UAP,	"aUAP" },
48841c99275SPeter Avalos /* RFC 2563 */
48941c99275SPeter Avalos 	{ TAG_DISABLE_AUTOCONF,	"BNOAUTO" },
49041c99275SPeter Avalos /* RFC 2610 */
49141c99275SPeter Avalos 	{ TAG_SLP_DA,		"bSLP-DA" },	/*"b" is a little wrong */
49241c99275SPeter Avalos 	{ TAG_SLP_SCOPE,	"bSLP-SCOPE" },	/*"b" is a little wrong */
49341c99275SPeter Avalos /* RFC 2937 */
49441c99275SPeter Avalos 	{ TAG_NS_SEARCH,	"sNSSEARCH" },	/* XXX 's' */
495411677aeSAaron LI /* RFC 3004 - The User Class Option for DHCP */
496411677aeSAaron LI 	{ TAG_USER_CLASS,	"$User-Class" },
49741c99275SPeter Avalos /* RFC 3011 */
49841c99275SPeter Avalos 	{ TAG_IP4_SUBNET_SELECT, "iSUBNET" },
49941c99275SPeter Avalos /* RFC 3442 */
50041c99275SPeter Avalos 	{ TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
50141c99275SPeter Avalos 	{ TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
502411677aeSAaron LI /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
503411677aeSAaron LI 	{ TAG_TFTP_SERVER_ADDRESS, "iTFTP-Server-Address" },
504*ed775ee7SAntonio Huete Jimenez /* https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml#options */
50541c99275SPeter Avalos 	{ TAG_SLP_NAMING_AUTH,	"aSLP-NA" },
50641c99275SPeter Avalos 	{ TAG_CLIENT_FQDN,	"$FQDN" },
50741c99275SPeter Avalos 	{ TAG_AGENT_CIRCUIT,	"$Agent-Information" },
50841c99275SPeter Avalos 	{ TAG_AGENT_REMOTE,	"bARMT" },
50941c99275SPeter Avalos 	{ TAG_TZ_STRING,	"aTZSTR" },
51041c99275SPeter Avalos 	{ TAG_FQDN_OPTION,	"bFQDNS" },	/* XXX 'b' */
51141c99275SPeter Avalos 	{ TAG_AUTH,		"bAUTH" },	/* XXX 'b' */
512*ed775ee7SAntonio Huete Jimenez 	{ TAG_CLIENT_LAST_TRANSACTION_TIME, "LLast-Transaction-Time" },
513*ed775ee7SAntonio Huete Jimenez 	{ TAG_ASSOCIATED_IP,	"iAssociated-IP" },
51441c99275SPeter Avalos 	{ TAG_CLIENT_ARCH,	"sARCH" },
51541c99275SPeter Avalos 	{ TAG_CLIENT_NDI,	"bNDI" },	/* XXX 'b' */
51641c99275SPeter Avalos 	{ TAG_CLIENT_GUID,	"bGUID" },	/* XXX 'b' */
51741c99275SPeter Avalos 	{ TAG_LDAP_URL,		"aLDAP" },
518411677aeSAaron LI 	{ TAG_TZ_PCODE, 	"aPOSIX-TZ" },
519411677aeSAaron LI 	{ TAG_TZ_TCODE, 	"aTZ-Name" },
52041c99275SPeter Avalos 	{ TAG_NETINFO_PARENT,	"iNI" },
52141c99275SPeter Avalos 	{ TAG_NETINFO_PARENT_TAG, "aNITAG" },
52241c99275SPeter Avalos 	{ TAG_URL,		"aURL" },
523411677aeSAaron LI 	{ TAG_MUDURL,           "aMUD-URL" },
52441c99275SPeter Avalos 	{ 0, NULL }
52541c99275SPeter Avalos };
52641c99275SPeter Avalos 
52741c99275SPeter Avalos /* DHCP "options overload" types */
528411677aeSAaron LI static const struct tok oo2str[] = {
52941c99275SPeter Avalos 	{ 1,	"file" },
53041c99275SPeter Avalos 	{ 2,	"sname" },
53141c99275SPeter Avalos 	{ 3,	"file+sname" },
53241c99275SPeter Avalos 	{ 0, NULL }
53341c99275SPeter Avalos };
53441c99275SPeter Avalos 
53541c99275SPeter Avalos /* NETBIOS over TCP/IP node type options */
536411677aeSAaron LI static const struct tok nbo2str[] = {
53741c99275SPeter Avalos 	{ 0x1,	"b-node" },
53841c99275SPeter Avalos 	{ 0x2,	"p-node" },
53941c99275SPeter Avalos 	{ 0x4,	"m-node" },
54041c99275SPeter Avalos 	{ 0x8,	"h-node" },
54141c99275SPeter Avalos 	{ 0, NULL }
54241c99275SPeter Avalos };
54341c99275SPeter Avalos 
54441c99275SPeter Avalos /* ARP Hardware types, for Client-ID option */
545411677aeSAaron LI static const struct tok arp2str[] = {
54641c99275SPeter Avalos 	{ 0x1,	"ether" },
54741c99275SPeter Avalos 	{ 0x6,	"ieee802" },
54841c99275SPeter Avalos 	{ 0x7,	"arcnet" },
54941c99275SPeter Avalos 	{ 0xf,	"frelay" },
55041c99275SPeter Avalos 	{ 0x17,	"strip" },
55141c99275SPeter Avalos 	{ 0x18,	"ieee1394" },
55241c99275SPeter Avalos 	{ 0, NULL }
55341c99275SPeter Avalos };
55441c99275SPeter Avalos 
555411677aeSAaron LI static const struct tok dhcp_msg_values[] = {
55641c99275SPeter Avalos 	{ DHCPDISCOVER,	       "Discover" },
55741c99275SPeter Avalos 	{ DHCPOFFER,	       "Offer" },
55841c99275SPeter Avalos 	{ DHCPREQUEST,	       "Request" },
55941c99275SPeter Avalos 	{ DHCPDECLINE,	       "Decline" },
56041c99275SPeter Avalos 	{ DHCPACK,	       "ACK" },
56141c99275SPeter Avalos 	{ DHCPNAK,	       "NACK" },
56241c99275SPeter Avalos 	{ DHCPRELEASE,	       "Release" },
56341c99275SPeter Avalos 	{ DHCPINFORM,	       "Inform" },
564*ed775ee7SAntonio Huete Jimenez 	{ DHCPLEASEQUERY,      "LeaseQuery" },
565*ed775ee7SAntonio Huete Jimenez 	{ DHCPLEASEUNASSIGNED, "LeaseUnassigned" },
566*ed775ee7SAntonio Huete Jimenez 	{ DHCPLEASEUNKNOWN,    "LeaseUnknown" },
567*ed775ee7SAntonio Huete Jimenez 	{ DHCPLEASEACTIVE,     "LeaseActive" },
56841c99275SPeter Avalos 	{ 0, NULL }
56941c99275SPeter Avalos };
57041c99275SPeter Avalos 
571ea7b4bf5SPeter Avalos #define AGENT_SUBOPTION_CIRCUIT_ID	1	/* RFC 3046 */
572ea7b4bf5SPeter Avalos #define AGENT_SUBOPTION_REMOTE_ID	2	/* RFC 3046 */
573ea7b4bf5SPeter Avalos #define AGENT_SUBOPTION_SUBSCRIBER_ID	6	/* RFC 3993 */
574411677aeSAaron LI static const struct tok agent_suboption_values[] = {
57541c99275SPeter Avalos 	{ AGENT_SUBOPTION_CIRCUIT_ID,    "Circuit-ID" },
576ea7b4bf5SPeter Avalos 	{ AGENT_SUBOPTION_REMOTE_ID,     "Remote-ID" },
577ea7b4bf5SPeter Avalos 	{ AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" },
57841c99275SPeter Avalos 	{ 0, NULL }
57941c99275SPeter Avalos };
58041c99275SPeter Avalos 
58141c99275SPeter Avalos 
58241c99275SPeter Avalos static void
rfc1048_print(netdissect_options * ndo,const u_char * bp)583411677aeSAaron LI rfc1048_print(netdissect_options *ndo,
584*ed775ee7SAntonio Huete Jimenez 	      const u_char *bp)
58541c99275SPeter Avalos {
586*ed775ee7SAntonio Huete Jimenez 	uint16_t tag;
587*ed775ee7SAntonio Huete Jimenez 	u_int len;
588*ed775ee7SAntonio Huete Jimenez 	const char *cp;
589*ed775ee7SAntonio Huete Jimenez 	char c;
59041c99275SPeter Avalos 	int first, idx;
591*ed775ee7SAntonio Huete Jimenez 	uint8_t subopt, suboptlen;
59241c99275SPeter Avalos 
593*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("\n\t  Vendor-rfc1048 Extensions");
59441c99275SPeter Avalos 
59541c99275SPeter Avalos 	/* Step over magic cookie */
596*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("\n\t    Magic Cookie 0x%08x", GET_BE_U_4(bp));
59741c99275SPeter Avalos 	bp += sizeof(int32_t);
59841c99275SPeter Avalos 
59941c99275SPeter Avalos 	/* Loop while we there is a tag left in the buffer */
600*ed775ee7SAntonio Huete Jimenez 	while (ND_TTEST_1(bp)) {
601*ed775ee7SAntonio Huete Jimenez 		tag = GET_U_1(bp);
602*ed775ee7SAntonio Huete Jimenez 		bp++;
603411677aeSAaron LI 		if (tag == TAG_PAD && ndo->ndo_vflag < 3)
60441c99275SPeter Avalos 			continue;
605411677aeSAaron LI 		if (tag == TAG_END && ndo->ndo_vflag < 3)
60641c99275SPeter Avalos 			return;
607*ed775ee7SAntonio Huete Jimenez 		cp = tok2str(tag2str, "?Unknown", tag);
60841c99275SPeter Avalos 		c = *cp++;
60941c99275SPeter Avalos 
61041c99275SPeter Avalos 		if (tag == TAG_PAD || tag == TAG_END)
61141c99275SPeter Avalos 			len = 0;
61241c99275SPeter Avalos 		else {
61341c99275SPeter Avalos 			/* Get the length; check for truncation */
614*ed775ee7SAntonio Huete Jimenez 			len = GET_U_1(bp);
615*ed775ee7SAntonio Huete Jimenez 			bp++;
61641c99275SPeter Avalos 		}
61741c99275SPeter Avalos 
618*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n\t    %s (%u), length %u%s", cp, tag, len,
619*ed775ee7SAntonio Huete Jimenez 			  len > 0 ? ": " : "");
62041c99275SPeter Avalos 
621411677aeSAaron LI 		if (tag == TAG_PAD && ndo->ndo_vflag > 2) {
62241c99275SPeter Avalos 			u_int ntag = 1;
623*ed775ee7SAntonio Huete Jimenez 			while (ND_TTEST_1(bp) &&
624*ed775ee7SAntonio Huete Jimenez 			       GET_U_1(bp) == TAG_PAD) {
62541c99275SPeter Avalos 				bp++;
62641c99275SPeter Avalos 				ntag++;
62741c99275SPeter Avalos 			}
62841c99275SPeter Avalos 			if (ntag > 1)
629*ed775ee7SAntonio Huete Jimenez 				ND_PRINT(", occurs %u", ntag);
63041c99275SPeter Avalos 		}
63141c99275SPeter Avalos 
632*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_LEN(bp, len);
63341c99275SPeter Avalos 
63441c99275SPeter Avalos 		if (tag == TAG_DHCP_MESSAGE && len == 1) {
635*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("%s",
636*ed775ee7SAntonio Huete Jimenez 				 tok2str(dhcp_msg_values, "Unknown (%u)", GET_U_1(bp)));
637*ed775ee7SAntonio Huete Jimenez 			bp++;
63841c99275SPeter Avalos 			continue;
63941c99275SPeter Avalos 		}
64041c99275SPeter Avalos 
64141c99275SPeter Avalos 		if (tag == TAG_PARM_REQUEST) {
64241c99275SPeter Avalos 			idx = 0;
643*ed775ee7SAntonio Huete Jimenez 			while (len > 0) {
644*ed775ee7SAntonio Huete Jimenez 				uint8_t innertag = GET_U_1(bp);
645*ed775ee7SAntonio Huete Jimenez 				bp++;
646*ed775ee7SAntonio Huete Jimenez 				len--;
647*ed775ee7SAntonio Huete Jimenez 				cp = tok2str(tag2str, "?Unknown", innertag);
64841c99275SPeter Avalos 				if (idx % 4 == 0)
649*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("\n\t      ");
65041c99275SPeter Avalos 				else
651*ed775ee7SAntonio Huete Jimenez 					ND_PRINT(", ");
652*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%s (%u)", cp + 1, innertag);
65341c99275SPeter Avalos 				idx++;
65441c99275SPeter Avalos 			}
65541c99275SPeter Avalos 			continue;
65641c99275SPeter Avalos 		}
65741c99275SPeter Avalos 
65841c99275SPeter Avalos 		/* Print data */
65941c99275SPeter Avalos 		if (c == '?') {
66041c99275SPeter Avalos 			/* Base default formats for unknown tags on data size */
66141c99275SPeter Avalos 			if (len & 1)
66241c99275SPeter Avalos 				c = 'b';
66341c99275SPeter Avalos 			else if (len & 2)
66441c99275SPeter Avalos 				c = 's';
66541c99275SPeter Avalos 			else
66641c99275SPeter Avalos 				c = 'l';
66741c99275SPeter Avalos 		}
66841c99275SPeter Avalos 		first = 1;
66941c99275SPeter Avalos 		switch (c) {
67041c99275SPeter Avalos 
67141c99275SPeter Avalos 		case 'a':
672*ed775ee7SAntonio Huete Jimenez 			/* ASCII strings */
673*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("\"");
674*ed775ee7SAntonio Huete Jimenez 			if (nd_printn(ndo, bp, len, ndo->ndo_snapend)) {
675*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("\"");
67641c99275SPeter Avalos 				goto trunc;
67741c99275SPeter Avalos 			}
678*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("\"");
67941c99275SPeter Avalos 			bp += len;
68041c99275SPeter Avalos 			len = 0;
68141c99275SPeter Avalos 			break;
68241c99275SPeter Avalos 
68341c99275SPeter Avalos 		case 'i':
68441c99275SPeter Avalos 		case 'l':
68541c99275SPeter Avalos 		case 'L':
68641c99275SPeter Avalos 			/* ip addresses/32-bit words */
687*ed775ee7SAntonio Huete Jimenez 			while (len >= 4) {
68841c99275SPeter Avalos 				if (!first)
689*ed775ee7SAntonio Huete Jimenez 					ND_PRINT(",");
690*ed775ee7SAntonio Huete Jimenez 				if (c == 'i')
691*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("%s", GET_IPADDR_STRING(bp));
692*ed775ee7SAntonio Huete Jimenez 				else if (c == 'L')
693*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("%d", GET_BE_S_4(bp));
69441c99275SPeter Avalos 				else
695*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("%u", GET_BE_U_4(bp));
696*ed775ee7SAntonio Huete Jimenez 				bp += 4;
697*ed775ee7SAntonio Huete Jimenez 				len -= 4;
69841c99275SPeter Avalos 				first = 0;
69941c99275SPeter Avalos 			}
70041c99275SPeter Avalos 			break;
70141c99275SPeter Avalos 
70241c99275SPeter Avalos 		case 'p':
70341c99275SPeter Avalos 			/* IP address pairs */
704*ed775ee7SAntonio Huete Jimenez 			while (len >= 2*4) {
70541c99275SPeter Avalos 				if (!first)
706*ed775ee7SAntonio Huete Jimenez 					ND_PRINT(",");
707*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("(%s:", GET_IPADDR_STRING(bp));
708*ed775ee7SAntonio Huete Jimenez 				bp += 4;
709*ed775ee7SAntonio Huete Jimenez 				len -= 4;
710*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%s)", GET_IPADDR_STRING(bp));
711*ed775ee7SAntonio Huete Jimenez 				bp += 4;
712*ed775ee7SAntonio Huete Jimenez 				len -= 4;
71341c99275SPeter Avalos 				first = 0;
71441c99275SPeter Avalos 			}
71541c99275SPeter Avalos 			break;
71641c99275SPeter Avalos 
71741c99275SPeter Avalos 		case 's':
71841c99275SPeter Avalos 			/* shorts */
719*ed775ee7SAntonio Huete Jimenez 			while (len >= 2) {
72041c99275SPeter Avalos 				if (!first)
721*ed775ee7SAntonio Huete Jimenez 					ND_PRINT(",");
722*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%u", GET_BE_U_2(bp));
723*ed775ee7SAntonio Huete Jimenez 				bp += 2;
724*ed775ee7SAntonio Huete Jimenez 				len -= 2;
72541c99275SPeter Avalos 				first = 0;
72641c99275SPeter Avalos 			}
72741c99275SPeter Avalos 			break;
72841c99275SPeter Avalos 
72941c99275SPeter Avalos 		case 'B':
73041c99275SPeter Avalos 			/* boolean */
73141c99275SPeter Avalos 			while (len > 0) {
732*ed775ee7SAntonio Huete Jimenez 				uint8_t bool_value;
73341c99275SPeter Avalos 				if (!first)
734*ed775ee7SAntonio Huete Jimenez 					ND_PRINT(",");
735*ed775ee7SAntonio Huete Jimenez 				bool_value = GET_U_1(bp);
736*ed775ee7SAntonio Huete Jimenez 				switch (bool_value) {
73741c99275SPeter Avalos 				case 0:
738*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("N");
73941c99275SPeter Avalos 					break;
74041c99275SPeter Avalos 				case 1:
741*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("Y");
74241c99275SPeter Avalos 					break;
74341c99275SPeter Avalos 				default:
744*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("%u?", bool_value);
74541c99275SPeter Avalos 					break;
74641c99275SPeter Avalos 				}
74741c99275SPeter Avalos 				++bp;
74841c99275SPeter Avalos 				--len;
74941c99275SPeter Avalos 				first = 0;
75041c99275SPeter Avalos 			}
75141c99275SPeter Avalos 			break;
75241c99275SPeter Avalos 
75341c99275SPeter Avalos 		case 'b':
75441c99275SPeter Avalos 		case 'x':
75541c99275SPeter Avalos 		default:
75641c99275SPeter Avalos 			/* Bytes */
75741c99275SPeter Avalos 			while (len > 0) {
758*ed775ee7SAntonio Huete Jimenez 				uint8_t byte_value;
75941c99275SPeter Avalos 				if (!first)
760*ed775ee7SAntonio Huete Jimenez 					ND_PRINT(c == 'x' ? ":" : ".");
761*ed775ee7SAntonio Huete Jimenez 				byte_value = GET_U_1(bp);
76241c99275SPeter Avalos 				if (c == 'x')
763*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("%02x", byte_value);
76441c99275SPeter Avalos 				else
765*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("%u", byte_value);
76641c99275SPeter Avalos 				++bp;
76741c99275SPeter Avalos 				--len;
76841c99275SPeter Avalos 				first = 0;
76941c99275SPeter Avalos 			}
77041c99275SPeter Avalos 			break;
77141c99275SPeter Avalos 
77241c99275SPeter Avalos 		case '$':
77341c99275SPeter Avalos 			/* Guys we can't handle with one of the usual cases */
77441c99275SPeter Avalos 			switch (tag) {
77541c99275SPeter Avalos 
77641c99275SPeter Avalos 			case TAG_NETBIOS_NODE:
77741c99275SPeter Avalos 				/* this option should be at least 1 byte long */
77841c99275SPeter Avalos 				if (len < 1) {
779*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("[ERROR: length < 1 bytes]");
78041c99275SPeter Avalos 					break;
78141c99275SPeter Avalos 				}
782*ed775ee7SAntonio Huete Jimenez 				tag = GET_U_1(bp);
783*ed775ee7SAntonio Huete Jimenez 				++bp;
78441c99275SPeter Avalos 				--len;
785*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%s", tok2str(nbo2str, NULL, tag));
78641c99275SPeter Avalos 				break;
78741c99275SPeter Avalos 
78841c99275SPeter Avalos 			case TAG_OPT_OVERLOAD:
78941c99275SPeter Avalos 				/* this option should be at least 1 byte long */
79041c99275SPeter Avalos 				if (len < 1) {
791*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("[ERROR: length < 1 bytes]");
79241c99275SPeter Avalos 					break;
79341c99275SPeter Avalos 				}
794*ed775ee7SAntonio Huete Jimenez 				tag = GET_U_1(bp);
795*ed775ee7SAntonio Huete Jimenez 				++bp;
79641c99275SPeter Avalos 				--len;
797*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%s", tok2str(oo2str, NULL, tag));
79841c99275SPeter Avalos 				break;
79941c99275SPeter Avalos 
80041c99275SPeter Avalos 			case TAG_CLIENT_FQDN:
80141c99275SPeter Avalos 				/* this option should be at least 3 bytes long */
80241c99275SPeter Avalos 				if (len < 3) {
803*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("[ERROR: length < 3 bytes]");
80441c99275SPeter Avalos 					bp += len;
80541c99275SPeter Avalos 					len = 0;
80641c99275SPeter Avalos 					break;
80741c99275SPeter Avalos 				}
808*ed775ee7SAntonio Huete Jimenez 				if (GET_U_1(bp) & 0xf0) {
809*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("[ERROR: MBZ nibble 0x%x != 0] ",
810*ed775ee7SAntonio Huete Jimenez 						 (GET_U_1(bp) & 0xf0) >> 4);
811*ed775ee7SAntonio Huete Jimenez 				}
812*ed775ee7SAntonio Huete Jimenez 				if (GET_U_1(bp) & 0x0f)
813*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("[%s] ",
814*ed775ee7SAntonio Huete Jimenez 						 client_fqdn_flags(GET_U_1(bp)));
81541c99275SPeter Avalos 				bp++;
816*ed775ee7SAntonio Huete Jimenez 				if (GET_U_1(bp) || GET_U_1(bp + 1))
817*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("%u/%u ", GET_U_1(bp),
818*ed775ee7SAntonio Huete Jimenez 						 GET_U_1(bp + 1));
81941c99275SPeter Avalos 				bp += 2;
820*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("\"");
821*ed775ee7SAntonio Huete Jimenez 				if (nd_printn(ndo, bp, len - 3, ndo->ndo_snapend)) {
822*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("\"");
82341c99275SPeter Avalos 					goto trunc;
82441c99275SPeter Avalos 				}
825*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("\"");
82641c99275SPeter Avalos 				bp += len - 3;
82741c99275SPeter Avalos 				len = 0;
82841c99275SPeter Avalos 				break;
82941c99275SPeter Avalos 
83041c99275SPeter Avalos 			case TAG_CLIENT_ID:
831411677aeSAaron LI 			    {
832411677aeSAaron LI 				int type;
83341c99275SPeter Avalos 
83441c99275SPeter Avalos 				/* this option should be at least 1 byte long */
83541c99275SPeter Avalos 				if (len < 1) {
836*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("[ERROR: length < 1 bytes]");
83741c99275SPeter Avalos 					break;
83841c99275SPeter Avalos 				}
839*ed775ee7SAntonio Huete Jimenez 				type = GET_U_1(bp);
840*ed775ee7SAntonio Huete Jimenez 				bp++;
84141c99275SPeter Avalos 				len--;
84241c99275SPeter Avalos 				if (type == 0) {
843*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("\"");
844*ed775ee7SAntonio Huete Jimenez 					if (nd_printn(ndo, bp, len, ndo->ndo_snapend)) {
845*ed775ee7SAntonio Huete Jimenez 						ND_PRINT("\"");
84641c99275SPeter Avalos 						goto trunc;
84741c99275SPeter Avalos 					}
848*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("\"");
84941c99275SPeter Avalos 					bp += len;
85041c99275SPeter Avalos 					len = 0;
85141c99275SPeter Avalos 					break;
85241c99275SPeter Avalos 				} else {
853*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("%s ", tok2str(arp2str, "hardware-type %u,", type));
85441c99275SPeter Avalos 					while (len > 0) {
85541c99275SPeter Avalos 						if (!first)
856*ed775ee7SAntonio Huete Jimenez 							ND_PRINT(":");
857*ed775ee7SAntonio Huete Jimenez 						ND_PRINT("%02x", GET_U_1(bp));
85841c99275SPeter Avalos 						++bp;
85941c99275SPeter Avalos 						--len;
86041c99275SPeter Avalos 						first = 0;
86141c99275SPeter Avalos 					}
86241c99275SPeter Avalos 				}
86341c99275SPeter Avalos 				break;
86441c99275SPeter Avalos 			    }
86541c99275SPeter Avalos 
86641c99275SPeter Avalos 			case TAG_AGENT_CIRCUIT:
86741c99275SPeter Avalos 				while (len >= 2) {
868*ed775ee7SAntonio Huete Jimenez 					subopt = GET_U_1(bp);
869*ed775ee7SAntonio Huete Jimenez 					suboptlen = GET_U_1(bp + 1);
870*ed775ee7SAntonio Huete Jimenez 					bp += 2;
87141c99275SPeter Avalos 					len -= 2;
87241c99275SPeter Avalos 					if (suboptlen > len) {
873*ed775ee7SAntonio Huete Jimenez 						ND_PRINT("\n\t      %s SubOption %u, length %u: length goes past end of option",
87441c99275SPeter Avalos 							  tok2str(agent_suboption_values, "Unknown", subopt),
87541c99275SPeter Avalos 							  subopt,
876*ed775ee7SAntonio Huete Jimenez 							  suboptlen);
87741c99275SPeter Avalos 						bp += len;
87841c99275SPeter Avalos 						len = 0;
87941c99275SPeter Avalos 						break;
88041c99275SPeter Avalos 					}
881*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("\n\t      %s SubOption %u, length %u: ",
88241c99275SPeter Avalos 						  tok2str(agent_suboption_values, "Unknown", subopt),
88341c99275SPeter Avalos 						  subopt,
884*ed775ee7SAntonio Huete Jimenez 						  suboptlen);
88541c99275SPeter Avalos 					switch (subopt) {
88641c99275SPeter Avalos 
887ea7b4bf5SPeter Avalos 					case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
888ea7b4bf5SPeter Avalos 					case AGENT_SUBOPTION_REMOTE_ID:
889ea7b4bf5SPeter Avalos 					case AGENT_SUBOPTION_SUBSCRIBER_ID:
890*ed775ee7SAntonio Huete Jimenez 						if (nd_printn(ndo, bp, suboptlen, ndo->ndo_snapend))
891411677aeSAaron LI 							goto trunc;
89241c99275SPeter Avalos 						break;
89341c99275SPeter Avalos 
89441c99275SPeter Avalos 					default:
895411677aeSAaron LI 						print_unknown_data(ndo, bp, "\n\t\t", suboptlen);
89641c99275SPeter Avalos 					}
89741c99275SPeter Avalos 
89841c99275SPeter Avalos 					len -= suboptlen;
89941c99275SPeter Avalos 					bp += suboptlen;
90041c99275SPeter Avalos 				}
90141c99275SPeter Avalos 				break;
90241c99275SPeter Avalos 
90341c99275SPeter Avalos 			case TAG_CLASSLESS_STATIC_RT:
90441c99275SPeter Avalos 			case TAG_CLASSLESS_STA_RT_MS:
90541c99275SPeter Avalos 			    {
90641c99275SPeter Avalos 				u_int mask_width, significant_octets, i;
90741c99275SPeter Avalos 
90841c99275SPeter Avalos 				/* this option should be at least 5 bytes long */
90941c99275SPeter Avalos 				if (len < 5) {
910*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("[ERROR: length < 5 bytes]");
91141c99275SPeter Avalos 					bp += len;
91241c99275SPeter Avalos 					len = 0;
91341c99275SPeter Avalos 					break;
91441c99275SPeter Avalos 				}
91541c99275SPeter Avalos 				while (len > 0) {
91641c99275SPeter Avalos 					if (!first)
917*ed775ee7SAntonio Huete Jimenez 						ND_PRINT(",");
918*ed775ee7SAntonio Huete Jimenez 					mask_width = GET_U_1(bp);
919*ed775ee7SAntonio Huete Jimenez 					bp++;
92041c99275SPeter Avalos 					len--;
92141c99275SPeter Avalos 					/* mask_width <= 32 */
92241c99275SPeter Avalos 					if (mask_width > 32) {
923*ed775ee7SAntonio Huete Jimenez 						ND_PRINT("[ERROR: Mask width (%u) > 32]", mask_width);
92441c99275SPeter Avalos 						bp += len;
92541c99275SPeter Avalos 						len = 0;
92641c99275SPeter Avalos 						break;
92741c99275SPeter Avalos 					}
92841c99275SPeter Avalos 					significant_octets = (mask_width + 7) / 8;
92941c99275SPeter Avalos 					/* significant octets + router(4) */
93041c99275SPeter Avalos 					if (len < significant_octets + 4) {
931*ed775ee7SAntonio Huete Jimenez 						ND_PRINT("[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4);
93241c99275SPeter Avalos 						bp += len;
93341c99275SPeter Avalos 						len = 0;
93441c99275SPeter Avalos 						break;
93541c99275SPeter Avalos 					}
936*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("(");
93741c99275SPeter Avalos 					if (mask_width == 0)
938*ed775ee7SAntonio Huete Jimenez 						ND_PRINT("default");
93941c99275SPeter Avalos 					else {
94041c99275SPeter Avalos 						for (i = 0; i < significant_octets ; i++) {
94141c99275SPeter Avalos 							if (i > 0)
942*ed775ee7SAntonio Huete Jimenez 								ND_PRINT(".");
943*ed775ee7SAntonio Huete Jimenez 							ND_PRINT("%u",
944*ed775ee7SAntonio Huete Jimenez 								 GET_U_1(bp));
945*ed775ee7SAntonio Huete Jimenez 							bp++;
94641c99275SPeter Avalos 						}
94741c99275SPeter Avalos 						for (i = significant_octets ; i < 4 ; i++)
948*ed775ee7SAntonio Huete Jimenez 							ND_PRINT(".0");
949*ed775ee7SAntonio Huete Jimenez 						ND_PRINT("/%u", mask_width);
95041c99275SPeter Avalos 					}
951*ed775ee7SAntonio Huete Jimenez 					ND_PRINT(":%s)", GET_IPADDR_STRING(bp));
952*ed775ee7SAntonio Huete Jimenez 					bp += 4;
95341c99275SPeter Avalos 					len -= (significant_octets + 4);
95441c99275SPeter Avalos 					first = 0;
95541c99275SPeter Avalos 				}
956411677aeSAaron LI 				break;
957411677aeSAaron LI 			    }
958411677aeSAaron LI 
959411677aeSAaron LI 			case TAG_USER_CLASS:
960411677aeSAaron LI 			    {
961411677aeSAaron LI 				u_int suboptnumber = 1;
962411677aeSAaron LI 
963411677aeSAaron LI 				first = 1;
964411677aeSAaron LI 				if (len < 2) {
965*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("[ERROR: length < 2 bytes]");
966411677aeSAaron LI 					bp += len;
967411677aeSAaron LI 					len = 0;
968411677aeSAaron LI 					break;
969411677aeSAaron LI 				}
970411677aeSAaron LI 				while (len > 0) {
971*ed775ee7SAntonio Huete Jimenez 					suboptlen = GET_U_1(bp);
972*ed775ee7SAntonio Huete Jimenez 					bp++;
973411677aeSAaron LI 					len--;
974*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("\n\t      ");
975*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("instance#%u: ", suboptnumber);
976411677aeSAaron LI 					if (suboptlen == 0) {
977*ed775ee7SAntonio Huete Jimenez 						ND_PRINT("[ERROR: suboption length must be non-zero]");
978411677aeSAaron LI 						bp += len;
979411677aeSAaron LI 						len = 0;
980411677aeSAaron LI 						break;
981411677aeSAaron LI 					}
982411677aeSAaron LI 					if (len < suboptlen) {
983*ed775ee7SAntonio Huete Jimenez 						ND_PRINT("[ERROR: invalid option]");
984411677aeSAaron LI 						bp += len;
985411677aeSAaron LI 						len = 0;
986411677aeSAaron LI 						break;
987411677aeSAaron LI 					}
988*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("\"");
989*ed775ee7SAntonio Huete Jimenez 					if (nd_printn(ndo, bp, suboptlen, ndo->ndo_snapend)) {
990*ed775ee7SAntonio Huete Jimenez 						ND_PRINT("\"");
991411677aeSAaron LI 						goto trunc;
992411677aeSAaron LI 					}
993*ed775ee7SAntonio Huete Jimenez 					ND_PRINT("\"");
994*ed775ee7SAntonio Huete Jimenez 					ND_PRINT(", length %u", suboptlen);
995411677aeSAaron LI 					suboptnumber++;
996411677aeSAaron LI 					len -= suboptlen;
997411677aeSAaron LI 					bp += suboptlen;
99841c99275SPeter Avalos 				}
99941c99275SPeter Avalos 				break;
1000411677aeSAaron LI 			    }
100141c99275SPeter Avalos 
100241c99275SPeter Avalos 			default:
1003*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("[unknown special tag %u, size %u]",
1004*ed775ee7SAntonio Huete Jimenez 					  tag, len);
100541c99275SPeter Avalos 				bp += len;
100641c99275SPeter Avalos 				len = 0;
100741c99275SPeter Avalos 				break;
100841c99275SPeter Avalos 			}
100941c99275SPeter Avalos 			break;
101041c99275SPeter Avalos 		}
101141c99275SPeter Avalos 		/* Data left over? */
101241c99275SPeter Avalos 		if (len) {
1013*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("\n\t  trailing data length %u", len);
101441c99275SPeter Avalos 			bp += len;
101541c99275SPeter Avalos 		}
101641c99275SPeter Avalos 	}
101741c99275SPeter Avalos 	return;
101841c99275SPeter Avalos trunc:
1019*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
102041c99275SPeter Avalos }
102141c99275SPeter Avalos 
1022*ed775ee7SAntonio Huete Jimenez #define PRINTCMUADDR(m, s) { ND_TCHECK_4(cmu->m); \
1023*ed775ee7SAntonio Huete Jimenez     if (GET_IPV4_TO_NETWORK_ORDER(cmu->m) != 0) \
1024*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" %s:%s", s, GET_IPADDR_STRING(cmu->m)); }
1025*ed775ee7SAntonio Huete Jimenez 
102641c99275SPeter Avalos static void
cmu_print(netdissect_options * ndo,const u_char * bp)1027411677aeSAaron LI cmu_print(netdissect_options *ndo,
1028*ed775ee7SAntonio Huete Jimenez 	  const u_char *bp)
102941c99275SPeter Avalos {
1030*ed775ee7SAntonio Huete Jimenez 	const struct cmu_vend *cmu;
1031*ed775ee7SAntonio Huete Jimenez 	uint8_t v_flags;
103241c99275SPeter Avalos 
1033*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" vend-cmu");
103441c99275SPeter Avalos 	cmu = (const struct cmu_vend *)bp;
103541c99275SPeter Avalos 
103641c99275SPeter Avalos 	/* Only print if there are unknown bits */
1037*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_4(cmu->v_flags);
1038*ed775ee7SAntonio Huete Jimenez 	v_flags = GET_U_1(cmu->v_flags);
1039*ed775ee7SAntonio Huete Jimenez 	if ((v_flags & ~(VF_SMASK)) != 0)
1040*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" F:0x%x", v_flags);
104141c99275SPeter Avalos 	PRINTCMUADDR(v_dgate, "DG");
1042*ed775ee7SAntonio Huete Jimenez 	PRINTCMUADDR(v_smask, v_flags & VF_SMASK ? "SM" : "SM*");
104341c99275SPeter Avalos 	PRINTCMUADDR(v_dns1, "NS1");
104441c99275SPeter Avalos 	PRINTCMUADDR(v_dns2, "NS2");
104541c99275SPeter Avalos 	PRINTCMUADDR(v_ins1, "IEN1");
104641c99275SPeter Avalos 	PRINTCMUADDR(v_ins2, "IEN2");
104741c99275SPeter Avalos 	PRINTCMUADDR(v_ts1, "TS1");
104841c99275SPeter Avalos 	PRINTCMUADDR(v_ts2, "TS2");
104941c99275SPeter Avalos 	return;
105041c99275SPeter Avalos 
105141c99275SPeter Avalos trunc:
1052*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
105341c99275SPeter Avalos }
105441c99275SPeter Avalos 
1055*ed775ee7SAntonio Huete Jimenez #undef PRINTCMUADDR
1056*ed775ee7SAntonio Huete Jimenez 
105741c99275SPeter Avalos static char *
client_fqdn_flags(u_int flags)105841c99275SPeter Avalos client_fqdn_flags(u_int flags)
105941c99275SPeter Avalos {
106041c99275SPeter Avalos 	static char buf[8+1];
106141c99275SPeter Avalos 	int i = 0;
106241c99275SPeter Avalos 
106341c99275SPeter Avalos 	if (flags & CLIENT_FQDN_FLAGS_S)
106441c99275SPeter Avalos 		buf[i++] = 'S';
106541c99275SPeter Avalos 	if (flags & CLIENT_FQDN_FLAGS_O)
106641c99275SPeter Avalos 		buf[i++] = 'O';
106741c99275SPeter Avalos 	if (flags & CLIENT_FQDN_FLAGS_E)
106841c99275SPeter Avalos 		buf[i++] = 'E';
106941c99275SPeter Avalos 	if (flags & CLIENT_FQDN_FLAGS_N)
107041c99275SPeter Avalos 		buf[i++] = 'N';
107141c99275SPeter Avalos 	buf[i] = '\0';
107241c99275SPeter Avalos 
107341c99275SPeter Avalos 	return buf;
107441c99275SPeter Avalos }
1075