Home | History | Annotate | Line # | Download | only in dist
print-bootp.c revision 1.6
      1  1.1  christos /*
      2  1.1  christos  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
      3  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      4  1.1  christos  *
      5  1.1  christos  * Redistribution and use in source and binary forms, with or without
      6  1.1  christos  * modification, are permitted provided that: (1) source code distributions
      7  1.1  christos  * retain the above copyright notice and this paragraph in its entirety, (2)
      8  1.1  christos  * distributions including binary code include the above copyright notice and
      9  1.1  christos  * this paragraph in its entirety in the documentation or other materials
     10  1.1  christos  * provided with the distribution, and (3) all advertising materials mentioning
     11  1.1  christos  * features or use of this software display the following acknowledgement:
     12  1.1  christos  * ``This product includes software developed by the University of California,
     13  1.1  christos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
     14  1.1  christos  * the University nor the names of its contributors may be used to endorse
     15  1.1  christos  * or promote products derived from this software without specific prior
     16  1.1  christos  * written permission.
     17  1.1  christos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
     18  1.1  christos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
     19  1.1  christos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     20  1.1  christos  *
     21  1.1  christos  * Format and print bootp packets.
     22  1.1  christos  */
     23  1.5  christos 
     24  1.2  christos #include <sys/cdefs.h>
     25  1.1  christos #ifndef lint
     26  1.6  christos __RCSID("$NetBSD: print-bootp.c,v 1.6 2015/03/31 21:59:35 christos Exp $");
     27  1.1  christos #endif
     28  1.1  christos 
     29  1.5  christos #define NETDISSECT_REWORKED
     30  1.1  christos #ifdef HAVE_CONFIG_H
     31  1.1  christos #include "config.h"
     32  1.1  christos #endif
     33  1.1  christos 
     34  1.1  christos #include <tcpdump-stdinc.h>
     35  1.1  christos 
     36  1.1  christos #include <string.h>
     37  1.1  christos 
     38  1.1  christos #include "interface.h"
     39  1.1  christos #include "addrtoname.h"
     40  1.1  christos #include "extract.h"
     41  1.1  christos 
     42  1.5  christos static const char tstr[] = " [|bootp]";
     43  1.5  christos 
     44  1.6  christos /*
     45  1.6  christos  * Bootstrap Protocol (BOOTP).  RFC951 and RFC1048.
     46  1.6  christos  *
     47  1.6  christos  * This file specifies the "implementation-independent" BOOTP protocol
     48  1.6  christos  * information which is common to both client and server.
     49  1.6  christos  *
     50  1.6  christos  * Copyright 1988 by Carnegie Mellon.
     51  1.6  christos  *
     52  1.6  christos  * Permission to use, copy, modify, and distribute this program for any
     53  1.6  christos  * purpose and without fee is hereby granted, provided that this copyright
     54  1.6  christos  * and permission notice appear on all copies and supporting documentation,
     55  1.6  christos  * the name of Carnegie Mellon not be used in advertising or publicity
     56  1.6  christos  * pertaining to distribution of the program without specific prior
     57  1.6  christos  * permission, and notice be given in supporting documentation that copying
     58  1.6  christos  * and distribution is by permission of Carnegie Mellon and Stanford
     59  1.6  christos  * University.  Carnegie Mellon makes no representations about the
     60  1.6  christos  * suitability of this software for any purpose.  It is provided "as is"
     61  1.6  christos  * without express or implied warranty.
     62  1.6  christos  */
     63  1.6  christos 
     64  1.6  christos struct bootp {
     65  1.6  christos 	uint8_t		bp_op;		/* packet opcode type */
     66  1.6  christos 	uint8_t		bp_htype;	/* hardware addr type */
     67  1.6  christos 	uint8_t		bp_hlen;	/* hardware addr length */
     68  1.6  christos 	uint8_t		bp_hops;	/* gateway hops */
     69  1.6  christos 	uint32_t	bp_xid;		/* transaction ID */
     70  1.6  christos 	uint16_t	bp_secs;	/* seconds since boot began */
     71  1.6  christos 	uint16_t	bp_flags;	/* flags - see bootp_flag_values[]
     72  1.6  christos 					   in print-bootp.c */
     73  1.6  christos 	struct in_addr	bp_ciaddr;	/* client IP address */
     74  1.6  christos 	struct in_addr	bp_yiaddr;	/* 'your' IP address */
     75  1.6  christos 	struct in_addr	bp_siaddr;	/* server IP address */
     76  1.6  christos 	struct in_addr	bp_giaddr;	/* gateway IP address */
     77  1.6  christos 	uint8_t		bp_chaddr[16];	/* client hardware address */
     78  1.6  christos 	uint8_t		bp_sname[64];	/* server host name */
     79  1.6  christos 	uint8_t		bp_file[128];	/* boot file name */
     80  1.6  christos 	uint8_t		bp_vend[64];	/* vendor-specific area */
     81  1.6  christos } UNALIGNED;
     82  1.6  christos 
     83  1.6  christos #define BOOTPREPLY	2
     84  1.6  christos #define BOOTPREQUEST	1
     85  1.6  christos 
     86  1.6  christos /*
     87  1.6  christos  * Vendor magic cookie (v_magic) for CMU
     88  1.6  christos  */
     89  1.6  christos #define VM_CMU		"CMU"
     90  1.6  christos 
     91  1.6  christos /*
     92  1.6  christos  * Vendor magic cookie (v_magic) for RFC1048
     93  1.6  christos  */
     94  1.6  christos #define VM_RFC1048	{ 99, 130, 83, 99 }
     95  1.6  christos 
     96  1.6  christos /*
     97  1.6  christos  * RFC1048 tag values used to specify what information is being supplied in
     98  1.6  christos  * the vendor field of the packet.
     99  1.6  christos  */
    100  1.6  christos 
    101  1.6  christos #define TAG_PAD			((uint8_t)   0)
    102  1.6  christos #define TAG_SUBNET_MASK		((uint8_t)   1)
    103  1.6  christos #define TAG_TIME_OFFSET		((uint8_t)   2)
    104  1.6  christos #define TAG_GATEWAY		((uint8_t)   3)
    105  1.6  christos #define TAG_TIME_SERVER		((uint8_t)   4)
    106  1.6  christos #define TAG_NAME_SERVER		((uint8_t)   5)
    107  1.6  christos #define TAG_DOMAIN_SERVER	((uint8_t)   6)
    108  1.6  christos #define TAG_LOG_SERVER		((uint8_t)   7)
    109  1.6  christos #define TAG_COOKIE_SERVER	((uint8_t)   8)
    110  1.6  christos #define TAG_LPR_SERVER		((uint8_t)   9)
    111  1.6  christos #define TAG_IMPRESS_SERVER	((uint8_t)  10)
    112  1.6  christos #define TAG_RLP_SERVER		((uint8_t)  11)
    113  1.6  christos #define TAG_HOSTNAME		((uint8_t)  12)
    114  1.6  christos #define TAG_BOOTSIZE		((uint8_t)  13)
    115  1.6  christos #define TAG_END			((uint8_t) 255)
    116  1.6  christos /* RFC1497 tags */
    117  1.6  christos #define	TAG_DUMPPATH		((uint8_t)  14)
    118  1.6  christos #define	TAG_DOMAINNAME		((uint8_t)  15)
    119  1.6  christos #define	TAG_SWAP_SERVER		((uint8_t)  16)
    120  1.6  christos #define	TAG_ROOTPATH		((uint8_t)  17)
    121  1.6  christos #define	TAG_EXTPATH		((uint8_t)  18)
    122  1.6  christos /* RFC2132 */
    123  1.6  christos #define	TAG_IP_FORWARD		((uint8_t)  19)
    124  1.6  christos #define	TAG_NL_SRCRT		((uint8_t)  20)
    125  1.6  christos #define	TAG_PFILTERS		((uint8_t)  21)
    126  1.6  christos #define	TAG_REASS_SIZE		((uint8_t)  22)
    127  1.6  christos #define	TAG_DEF_TTL		((uint8_t)  23)
    128  1.6  christos #define	TAG_MTU_TIMEOUT		((uint8_t)  24)
    129  1.6  christos #define	TAG_MTU_TABLE		((uint8_t)  25)
    130  1.6  christos #define	TAG_INT_MTU		((uint8_t)  26)
    131  1.6  christos #define	TAG_LOCAL_SUBNETS	((uint8_t)  27)
    132  1.6  christos #define	TAG_BROAD_ADDR		((uint8_t)  28)
    133  1.6  christos #define	TAG_DO_MASK_DISC	((uint8_t)  29)
    134  1.6  christos #define	TAG_SUPPLY_MASK		((uint8_t)  30)
    135  1.6  christos #define	TAG_DO_RDISC		((uint8_t)  31)
    136  1.6  christos #define	TAG_RTR_SOL_ADDR	((uint8_t)  32)
    137  1.6  christos #define	TAG_STATIC_ROUTE	((uint8_t)  33)
    138  1.6  christos #define	TAG_USE_TRAILERS	((uint8_t)  34)
    139  1.6  christos #define	TAG_ARP_TIMEOUT		((uint8_t)  35)
    140  1.6  christos #define	TAG_ETH_ENCAP		((uint8_t)  36)
    141  1.6  christos #define	TAG_TCP_TTL		((uint8_t)  37)
    142  1.6  christos #define	TAG_TCP_KEEPALIVE	((uint8_t)  38)
    143  1.6  christos #define	TAG_KEEPALIVE_GO	((uint8_t)  39)
    144  1.6  christos #define	TAG_NIS_DOMAIN		((uint8_t)  40)
    145  1.6  christos #define	TAG_NIS_SERVERS		((uint8_t)  41)
    146  1.6  christos #define	TAG_NTP_SERVERS		((uint8_t)  42)
    147  1.6  christos #define	TAG_VENDOR_OPTS		((uint8_t)  43)
    148  1.6  christos #define	TAG_NETBIOS_NS		((uint8_t)  44)
    149  1.6  christos #define	TAG_NETBIOS_DDS		((uint8_t)  45)
    150  1.6  christos #define	TAG_NETBIOS_NODE	((uint8_t)  46)
    151  1.6  christos #define	TAG_NETBIOS_SCOPE	((uint8_t)  47)
    152  1.6  christos #define	TAG_XWIN_FS		((uint8_t)  48)
    153  1.6  christos #define	TAG_XWIN_DM		((uint8_t)  49)
    154  1.6  christos #define	TAG_NIS_P_DOMAIN	((uint8_t)  64)
    155  1.6  christos #define	TAG_NIS_P_SERVERS	((uint8_t)  65)
    156  1.6  christos #define	TAG_MOBILE_HOME		((uint8_t)  68)
    157  1.6  christos #define	TAG_SMPT_SERVER		((uint8_t)  69)
    158  1.6  christos #define	TAG_POP3_SERVER		((uint8_t)  70)
    159  1.6  christos #define	TAG_NNTP_SERVER		((uint8_t)  71)
    160  1.6  christos #define	TAG_WWW_SERVER		((uint8_t)  72)
    161  1.6  christos #define	TAG_FINGER_SERVER	((uint8_t)  73)
    162  1.6  christos #define	TAG_IRC_SERVER		((uint8_t)  74)
    163  1.6  christos #define	TAG_STREETTALK_SRVR	((uint8_t)  75)
    164  1.6  christos #define	TAG_STREETTALK_STDA	((uint8_t)  76)
    165  1.6  christos /* DHCP options */
    166  1.6  christos #define	TAG_REQUESTED_IP	((uint8_t)  50)
    167  1.6  christos #define	TAG_IP_LEASE		((uint8_t)  51)
    168  1.6  christos #define	TAG_OPT_OVERLOAD	((uint8_t)  52)
    169  1.6  christos #define	TAG_TFTP_SERVER		((uint8_t)  66)
    170  1.6  christos #define	TAG_BOOTFILENAME	((uint8_t)  67)
    171  1.6  christos #define	TAG_DHCP_MESSAGE	((uint8_t)  53)
    172  1.6  christos #define	TAG_SERVER_ID		((uint8_t)  54)
    173  1.6  christos #define	TAG_PARM_REQUEST	((uint8_t)  55)
    174  1.6  christos #define	TAG_MESSAGE		((uint8_t)  56)
    175  1.6  christos #define	TAG_MAX_MSG_SIZE	((uint8_t)  57)
    176  1.6  christos #define	TAG_RENEWAL_TIME	((uint8_t)  58)
    177  1.6  christos #define	TAG_REBIND_TIME		((uint8_t)  59)
    178  1.6  christos #define	TAG_VENDOR_CLASS	((uint8_t)  60)
    179  1.6  christos #define	TAG_CLIENT_ID		((uint8_t)  61)
    180  1.6  christos /* RFC 2241 */
    181  1.6  christos #define	TAG_NDS_SERVERS		((uint8_t)  85)
    182  1.6  christos #define	TAG_NDS_TREE_NAME	((uint8_t)  86)
    183  1.6  christos #define	TAG_NDS_CONTEXT		((uint8_t)  87)
    184  1.6  christos /* RFC 2242 */
    185  1.6  christos #define	TAG_NDS_IPDOMAIN	((uint8_t)  62)
    186  1.6  christos #define	TAG_NDS_IPINFO		((uint8_t)  63)
    187  1.6  christos /* RFC 2485 */
    188  1.6  christos #define	TAG_OPEN_GROUP_UAP	((uint8_t)  98)
    189  1.6  christos /* RFC 2563 */
    190  1.6  christos #define	TAG_DISABLE_AUTOCONF	((uint8_t) 116)
    191  1.6  christos /* RFC 2610 */
    192  1.6  christos #define	TAG_SLP_DA		((uint8_t)  78)
    193  1.6  christos #define	TAG_SLP_SCOPE		((uint8_t)  79)
    194  1.6  christos /* RFC 2937 */
    195  1.6  christos #define	TAG_NS_SEARCH		((uint8_t) 117)
    196  1.6  christos /* RFC 3004 - The User Class Option for DHCP */
    197  1.6  christos #define	TAG_USER_CLASS		((uint8_t)  77)
    198  1.6  christos /* RFC 3011 */
    199  1.6  christos #define	TAG_IP4_SUBNET_SELECT	((uint8_t) 118)
    200  1.6  christos /* RFC 3442 */
    201  1.6  christos #define TAG_CLASSLESS_STATIC_RT	((uint8_t) 121)
    202  1.6  christos #define TAG_CLASSLESS_STA_RT_MS	((uint8_t) 249)
    203  1.6  christos /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
    204  1.6  christos #define	TAG_TFTP_SERVER_ADDRESS	((uint8_t) 150)
    205  1.6  christos /* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */
    206  1.6  christos #define	TAG_SLP_NAMING_AUTH	((uint8_t)  80)
    207  1.6  christos #define	TAG_CLIENT_FQDN		((uint8_t)  81)
    208  1.6  christos #define	TAG_AGENT_CIRCUIT	((uint8_t)  82)
    209  1.6  christos #define	TAG_AGENT_REMOTE	((uint8_t)  83)
    210  1.6  christos #define	TAG_AGENT_MASK		((uint8_t)  84)
    211  1.6  christos #define	TAG_TZ_STRING		((uint8_t)  88)
    212  1.6  christos #define	TAG_FQDN_OPTION		((uint8_t)  89)
    213  1.6  christos #define	TAG_AUTH		((uint8_t)  90)
    214  1.6  christos #define	TAG_VINES_SERVERS	((uint8_t)  91)
    215  1.6  christos #define	TAG_SERVER_RANK		((uint8_t)  92)
    216  1.6  christos #define	TAG_CLIENT_ARCH		((uint8_t)  93)
    217  1.6  christos #define	TAG_CLIENT_NDI		((uint8_t)  94)
    218  1.6  christos #define	TAG_CLIENT_GUID		((uint8_t)  97)
    219  1.6  christos #define	TAG_LDAP_URL		((uint8_t)  95)
    220  1.6  christos #define	TAG_6OVER4		((uint8_t)  96)
    221  1.6  christos #define	TAG_PRINTER_NAME	((uint8_t) 100)
    222  1.6  christos #define	TAG_MDHCP_SERVER	((uint8_t) 101)
    223  1.6  christos #define	TAG_IPX_COMPAT		((uint8_t) 110)
    224  1.6  christos #define	TAG_NETINFO_PARENT	((uint8_t) 112)
    225  1.6  christos #define	TAG_NETINFO_PARENT_TAG	((uint8_t) 113)
    226  1.6  christos #define	TAG_URL			((uint8_t) 114)
    227  1.6  christos #define	TAG_FAILOVER		((uint8_t) 115)
    228  1.6  christos #define	TAG_EXTENDED_REQUEST	((uint8_t) 126)
    229  1.6  christos #define	TAG_EXTENDED_OPTION	((uint8_t) 127)
    230  1.6  christos 
    231  1.6  christos /* DHCP Message types (values for TAG_DHCP_MESSAGE option) */
    232  1.6  christos #define DHCPDISCOVER	1
    233  1.6  christos #define DHCPOFFER	2
    234  1.6  christos #define DHCPREQUEST	3
    235  1.6  christos #define DHCPDECLINE	4
    236  1.6  christos #define DHCPACK		5
    237  1.6  christos #define DHCPNAK		6
    238  1.6  christos #define DHCPRELEASE	7
    239  1.6  christos #define DHCPINFORM	8
    240  1.6  christos 
    241  1.6  christos /*
    242  1.6  christos  * "vendor" data permitted for CMU bootp clients.
    243  1.6  christos  */
    244  1.6  christos 
    245  1.6  christos struct cmu_vend {
    246  1.6  christos 	uint8_t		v_magic[4];	/* magic number */
    247  1.6  christos 	uint32_t	v_flags;	/* flags/opcodes, etc. */
    248  1.6  christos 	struct in_addr	v_smask;	/* Subnet mask */
    249  1.6  christos 	struct in_addr	v_dgate;	/* Default gateway */
    250  1.6  christos 	struct in_addr	v_dns1, v_dns2; /* Domain name servers */
    251  1.6  christos 	struct in_addr	v_ins1, v_ins2; /* IEN-116 name servers */
    252  1.6  christos 	struct in_addr	v_ts1, v_ts2;	/* Time servers */
    253  1.6  christos 	uint8_t		v_unused[24];	/* currently unused */
    254  1.6  christos } UNALIGNED;
    255  1.6  christos 
    256  1.6  christos 
    257  1.6  christos /* v_flags values */
    258  1.6  christos #define VF_SMASK	1	/* Subnet mask field contains valid data */
    259  1.6  christos 
    260  1.6  christos /* RFC 4702 DHCP Client FQDN Option */
    261  1.6  christos 
    262  1.6  christos #define CLIENT_FQDN_FLAGS_S	0x01
    263  1.6  christos #define CLIENT_FQDN_FLAGS_O	0x02
    264  1.6  christos #define CLIENT_FQDN_FLAGS_E	0x04
    265  1.6  christos #define CLIENT_FQDN_FLAGS_N	0x08
    266  1.6  christos /* end of original bootp.h */
    267  1.6  christos 
    268  1.5  christos static void rfc1048_print(netdissect_options *, const u_char *);
    269  1.5  christos static void cmu_print(netdissect_options *, const u_char *);
    270  1.1  christos static char *client_fqdn_flags(u_int flags);
    271  1.1  christos 
    272  1.1  christos static const struct tok bootp_flag_values[] = {
    273  1.6  christos 	{ 0x8000,	"Broadcast" },
    274  1.6  christos 	{ 0, NULL}
    275  1.1  christos };
    276  1.1  christos 
    277  1.1  christos static const struct tok bootp_op_values[] = {
    278  1.6  christos 	{ BOOTPREQUEST,	"Request" },
    279  1.6  christos 	{ BOOTPREPLY,	"Reply" },
    280  1.6  christos 	{ 0, NULL}
    281  1.1  christos };
    282  1.1  christos 
    283  1.1  christos /*
    284  1.1  christos  * Print bootp requests
    285  1.1  christos  */
    286  1.1  christos void
    287  1.5  christos bootp_print(netdissect_options *ndo,
    288  1.6  christos 	    register const u_char *cp, u_int length)
    289  1.1  christos {
    290  1.1  christos 	register const struct bootp *bp;
    291  1.1  christos 	static const u_char vm_cmu[4] = VM_CMU;
    292  1.1  christos 	static const u_char vm_rfc1048[4] = VM_RFC1048;
    293  1.1  christos 
    294  1.1  christos 	bp = (const struct bootp *)cp;
    295  1.5  christos 	ND_TCHECK(bp->bp_op);
    296  1.1  christos 
    297  1.5  christos 	ND_PRINT((ndo, "BOOTP/DHCP, %s",
    298  1.6  christos 		  tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op)));
    299  1.1  christos 
    300  1.1  christos 	if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
    301  1.5  christos 		ND_TCHECK2(bp->bp_chaddr[0], 6);
    302  1.5  christos 		ND_PRINT((ndo, " from %s", etheraddr_string(ndo, bp->bp_chaddr)));
    303  1.1  christos 	}
    304  1.1  christos 
    305  1.5  christos 	ND_PRINT((ndo, ", length %u", length));
    306  1.1  christos 
    307  1.5  christos 	if (!ndo->ndo_vflag)
    308  1.5  christos 		return;
    309  1.1  christos 
    310  1.5  christos 	ND_TCHECK(bp->bp_secs);
    311  1.1  christos 
    312  1.1  christos 	/* The usual hardware address type is 1 (10Mb Ethernet) */
    313  1.1  christos 	if (bp->bp_htype != 1)
    314  1.5  christos 		ND_PRINT((ndo, ", htype %d", bp->bp_htype));
    315  1.1  christos 
    316  1.1  christos 	/* The usual length for 10Mb Ethernet address is 6 bytes */
    317  1.1  christos 	if (bp->bp_htype != 1 || bp->bp_hlen != 6)
    318  1.5  christos 		ND_PRINT((ndo, ", hlen %d", bp->bp_hlen));
    319  1.1  christos 
    320  1.1  christos 	/* Only print interesting fields */
    321  1.1  christos 	if (bp->bp_hops)
    322  1.5  christos 		ND_PRINT((ndo, ", hops %d", bp->bp_hops));
    323  1.5  christos 	if (EXTRACT_32BITS(&bp->bp_xid))
    324  1.5  christos 		ND_PRINT((ndo, ", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid)));
    325  1.5  christos 	if (EXTRACT_16BITS(&bp->bp_secs))
    326  1.5  christos 		ND_PRINT((ndo, ", secs %d", EXTRACT_16BITS(&bp->bp_secs)));
    327  1.5  christos 
    328  1.5  christos 	ND_PRINT((ndo, ", Flags [%s]",
    329  1.6  christos 		  bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags))));
    330  1.5  christos 	if (ndo->ndo_vflag > 1)
    331  1.5  christos 		ND_PRINT((ndo, " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags)));
    332  1.1  christos 
    333  1.1  christos 	/* Client's ip address */
    334  1.5  christos 	ND_TCHECK(bp->bp_ciaddr);
    335  1.5  christos 	if (EXTRACT_32BITS(&bp->bp_ciaddr.s_addr))
    336  1.5  christos 		ND_PRINT((ndo, "\n\t  Client-IP %s", ipaddr_string(ndo, &bp->bp_ciaddr)));
    337  1.1  christos 
    338  1.1  christos 	/* 'your' ip address (bootp client) */
    339  1.5  christos 	ND_TCHECK(bp->bp_yiaddr);
    340  1.5  christos 	if (EXTRACT_32BITS(&bp->bp_yiaddr.s_addr))
    341  1.5  christos 		ND_PRINT((ndo, "\n\t  Your-IP %s", ipaddr_string(ndo, &bp->bp_yiaddr)));
    342  1.1  christos 
    343  1.1  christos 	/* Server's ip address */
    344  1.5  christos 	ND_TCHECK(bp->bp_siaddr);
    345  1.5  christos 	if (EXTRACT_32BITS(&bp->bp_siaddr.s_addr))
    346  1.5  christos 		ND_PRINT((ndo, "\n\t  Server-IP %s", ipaddr_string(ndo, &bp->bp_siaddr)));
    347  1.1  christos 
    348  1.1  christos 	/* Gateway's ip address */
    349  1.5  christos 	ND_TCHECK(bp->bp_giaddr);
    350  1.5  christos 	if (EXTRACT_32BITS(&bp->bp_giaddr.s_addr))
    351  1.5  christos 		ND_PRINT((ndo, "\n\t  Gateway-IP %s", ipaddr_string(ndo, &bp->bp_giaddr)));
    352  1.1  christos 
    353  1.1  christos 	/* Client's Ethernet address */
    354  1.1  christos 	if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
    355  1.5  christos 		ND_TCHECK2(bp->bp_chaddr[0], 6);
    356  1.5  christos 		ND_PRINT((ndo, "\n\t  Client-Ethernet-Address %s", etheraddr_string(ndo, bp->bp_chaddr)));
    357  1.1  christos 	}
    358  1.1  christos 
    359  1.5  christos 	ND_TCHECK2(bp->bp_sname[0], 1);		/* check first char only */
    360  1.1  christos 	if (*bp->bp_sname) {
    361  1.5  christos 		ND_PRINT((ndo, "\n\t  sname \""));
    362  1.5  christos 		if (fn_print(ndo, bp->bp_sname, ndo->ndo_snapend)) {
    363  1.5  christos 			ND_PRINT((ndo, "\""));
    364  1.5  christos 			ND_PRINT((ndo, "%s", tstr + 1));
    365  1.1  christos 			return;
    366  1.1  christos 		}
    367  1.5  christos 		ND_PRINT((ndo, "\""));
    368  1.1  christos 	}
    369  1.5  christos 	ND_TCHECK2(bp->bp_file[0], 1);		/* check first char only */
    370  1.1  christos 	if (*bp->bp_file) {
    371  1.5  christos 		ND_PRINT((ndo, "\n\t  file \""));
    372  1.5  christos 		if (fn_print(ndo, bp->bp_file, ndo->ndo_snapend)) {
    373  1.5  christos 			ND_PRINT((ndo, "\""));
    374  1.5  christos 			ND_PRINT((ndo, "%s", tstr + 1));
    375  1.1  christos 			return;
    376  1.1  christos 		}
    377  1.5  christos 		ND_PRINT((ndo, "\""));
    378  1.1  christos 	}
    379  1.1  christos 
    380  1.1  christos 	/* Decode the vendor buffer */
    381  1.5  christos 	ND_TCHECK(bp->bp_vend[0]);
    382  1.1  christos 	if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
    383  1.6  christos 		    sizeof(uint32_t)) == 0)
    384  1.5  christos 		rfc1048_print(ndo, bp->bp_vend);
    385  1.1  christos 	else if (memcmp((const char *)bp->bp_vend, vm_cmu,
    386  1.6  christos 			sizeof(uint32_t)) == 0)
    387  1.5  christos 		cmu_print(ndo, bp->bp_vend);
    388  1.1  christos 	else {
    389  1.5  christos 		uint32_t ul;
    390  1.1  christos 
    391  1.1  christos 		ul = EXTRACT_32BITS(&bp->bp_vend);
    392  1.1  christos 		if (ul != 0)
    393  1.5  christos 			ND_PRINT((ndo, "\n\t  Vendor-#0x%x", ul));
    394  1.1  christos 	}
    395  1.1  christos 
    396  1.1  christos 	return;
    397  1.1  christos trunc:
    398  1.5  christos 	ND_PRINT((ndo, "%s", tstr));
    399  1.1  christos }
    400  1.1  christos 
    401  1.1  christos /*
    402  1.1  christos  * The first character specifies the format to print:
    403  1.1  christos  *     i - ip address (32 bits)
    404  1.1  christos  *     p - ip address pairs (32 bits + 32 bits)
    405  1.1  christos  *     l - long (32 bits)
    406  1.1  christos  *     L - unsigned long (32 bits)
    407  1.1  christos  *     s - short (16 bits)
    408  1.1  christos  *     b - period-seperated decimal bytes (variable length)
    409  1.1  christos  *     x - colon-seperated hex bytes (variable length)
    410  1.1  christos  *     a - ascii string (variable length)
    411  1.1  christos  *     B - on/off (8 bits)
    412  1.1  christos  *     $ - special (explicit code to handle)
    413  1.1  christos  */
    414  1.4  christos static const struct tok tag2str[] = {
    415  1.1  christos /* RFC1048 tags */
    416  1.1  christos 	{ TAG_PAD,		" PAD" },
    417  1.1  christos 	{ TAG_SUBNET_MASK,	"iSubnet-Mask" },	/* subnet mask (RFC950) */
    418  1.1  christos 	{ TAG_TIME_OFFSET,	"LTime-Zone" },	/* seconds from UTC */
    419  1.1  christos 	{ TAG_GATEWAY,		"iDefault-Gateway" },	/* default gateway */
    420  1.1  christos 	{ TAG_TIME_SERVER,	"iTime-Server" },	/* time servers (RFC868) */
    421  1.1  christos 	{ TAG_NAME_SERVER,	"iIEN-Name-Server" },	/* IEN name servers (IEN116) */
    422  1.1  christos 	{ TAG_DOMAIN_SERVER,	"iDomain-Name-Server" },	/* domain name (RFC1035) */
    423  1.1  christos 	{ TAG_LOG_SERVER,	"iLOG" },	/* MIT log servers */
    424  1.1  christos 	{ TAG_COOKIE_SERVER,	"iCS" },	/* cookie servers (RFC865) */
    425  1.1  christos 	{ TAG_LPR_SERVER,	"iLPR-Server" },	/* lpr server (RFC1179) */
    426  1.1  christos 	{ TAG_IMPRESS_SERVER,	"iIM" },	/* impress servers (Imagen) */
    427  1.1  christos 	{ TAG_RLP_SERVER,	"iRL" },	/* resource location (RFC887) */
    428  1.1  christos 	{ TAG_HOSTNAME,		"aHostname" },	/* ascii hostname */
    429  1.1  christos 	{ TAG_BOOTSIZE,		"sBS" },	/* 512 byte blocks */
    430  1.1  christos 	{ TAG_END,		" END" },
    431  1.1  christos /* RFC1497 tags */
    432  1.1  christos 	{ TAG_DUMPPATH,		"aDP" },
    433  1.1  christos 	{ TAG_DOMAINNAME,	"aDomain-Name" },
    434  1.1  christos 	{ TAG_SWAP_SERVER,	"iSS" },
    435  1.1  christos 	{ TAG_ROOTPATH,		"aRP" },
    436  1.1  christos 	{ TAG_EXTPATH,		"aEP" },
    437  1.1  christos /* RFC2132 tags */
    438  1.1  christos 	{ TAG_IP_FORWARD,	"BIPF" },
    439  1.1  christos 	{ TAG_NL_SRCRT,		"BSRT" },
    440  1.1  christos 	{ TAG_PFILTERS,		"pPF" },
    441  1.1  christos 	{ TAG_REASS_SIZE,	"sRSZ" },
    442  1.1  christos 	{ TAG_DEF_TTL,		"bTTL" },
    443  1.1  christos 	{ TAG_MTU_TIMEOUT,	"lMTU-Timeout" },
    444  1.1  christos 	{ TAG_MTU_TABLE,	"sMTU-Table" },
    445  1.1  christos 	{ TAG_INT_MTU,		"sMTU" },
    446  1.1  christos 	{ TAG_LOCAL_SUBNETS,	"BLSN" },
    447  1.1  christos 	{ TAG_BROAD_ADDR,	"iBR" },
    448  1.1  christos 	{ TAG_DO_MASK_DISC,	"BMD" },
    449  1.1  christos 	{ TAG_SUPPLY_MASK,	"BMS" },
    450  1.1  christos 	{ TAG_DO_RDISC,		"BRouter-Discovery" },
    451  1.1  christos 	{ TAG_RTR_SOL_ADDR,	"iRSA" },
    452  1.1  christos 	{ TAG_STATIC_ROUTE,	"pStatic-Route" },
    453  1.1  christos 	{ TAG_USE_TRAILERS,	"BUT" },
    454  1.1  christos 	{ TAG_ARP_TIMEOUT,	"lAT" },
    455  1.1  christos 	{ TAG_ETH_ENCAP,	"BIE" },
    456  1.1  christos 	{ TAG_TCP_TTL,		"bTT" },
    457  1.1  christos 	{ TAG_TCP_KEEPALIVE,	"lKI" },
    458  1.1  christos 	{ TAG_KEEPALIVE_GO,	"BKG" },
    459  1.1  christos 	{ TAG_NIS_DOMAIN,	"aYD" },
    460  1.1  christos 	{ TAG_NIS_SERVERS,	"iYS" },
    461  1.1  christos 	{ TAG_NTP_SERVERS,	"iNTP" },
    462  1.1  christos 	{ TAG_VENDOR_OPTS,	"bVendor-Option" },
    463  1.1  christos 	{ TAG_NETBIOS_NS,	"iNetbios-Name-Server" },
    464  1.1  christos 	{ TAG_NETBIOS_DDS,	"iWDD" },
    465  1.1  christos 	{ TAG_NETBIOS_NODE,	"$Netbios-Node" },
    466  1.1  christos 	{ TAG_NETBIOS_SCOPE,	"aNetbios-Scope" },
    467  1.1  christos 	{ TAG_XWIN_FS,		"iXFS" },
    468  1.1  christos 	{ TAG_XWIN_DM,		"iXDM" },
    469  1.1  christos 	{ TAG_NIS_P_DOMAIN,	"sN+D" },
    470  1.1  christos 	{ TAG_NIS_P_SERVERS,	"iN+S" },
    471  1.1  christos 	{ TAG_MOBILE_HOME,	"iMH" },
    472  1.1  christos 	{ TAG_SMPT_SERVER,	"iSMTP" },
    473  1.1  christos 	{ TAG_POP3_SERVER,	"iPOP3" },
    474  1.1  christos 	{ TAG_NNTP_SERVER,	"iNNTP" },
    475  1.1  christos 	{ TAG_WWW_SERVER,	"iWWW" },
    476  1.1  christos 	{ TAG_FINGER_SERVER,	"iFG" },
    477  1.1  christos 	{ TAG_IRC_SERVER,	"iIRC" },
    478  1.1  christos 	{ TAG_STREETTALK_SRVR,	"iSTS" },
    479  1.1  christos 	{ TAG_STREETTALK_STDA,	"iSTDA" },
    480  1.1  christos 	{ TAG_REQUESTED_IP,	"iRequested-IP" },
    481  1.1  christos 	{ TAG_IP_LEASE,		"lLease-Time" },
    482  1.1  christos 	{ TAG_OPT_OVERLOAD,	"$OO" },
    483  1.1  christos 	{ TAG_TFTP_SERVER,	"aTFTP" },
    484  1.1  christos 	{ TAG_BOOTFILENAME,	"aBF" },
    485  1.1  christos 	{ TAG_DHCP_MESSAGE,	" DHCP-Message" },
    486  1.1  christos 	{ TAG_SERVER_ID,	"iServer-ID" },
    487  1.1  christos 	{ TAG_PARM_REQUEST,	"bParameter-Request" },
    488  1.1  christos 	{ TAG_MESSAGE,		"aMSG" },
    489  1.1  christos 	{ TAG_MAX_MSG_SIZE,	"sMSZ" },
    490  1.1  christos 	{ TAG_RENEWAL_TIME,	"lRN" },
    491  1.1  christos 	{ TAG_REBIND_TIME,	"lRB" },
    492  1.1  christos 	{ TAG_VENDOR_CLASS,	"aVendor-Class" },
    493  1.1  christos 	{ TAG_CLIENT_ID,	"$Client-ID" },
    494  1.1  christos /* RFC 2485 */
    495  1.1  christos 	{ TAG_OPEN_GROUP_UAP,	"aUAP" },
    496  1.1  christos /* RFC 2563 */
    497  1.1  christos 	{ TAG_DISABLE_AUTOCONF,	"BNOAUTO" },
    498  1.1  christos /* RFC 2610 */
    499  1.1  christos 	{ TAG_SLP_DA,		"bSLP-DA" },	/*"b" is a little wrong */
    500  1.1  christos 	{ TAG_SLP_SCOPE,	"bSLP-SCOPE" },	/*"b" is a little wrong */
    501  1.1  christos /* RFC 2937 */
    502  1.1  christos 	{ TAG_NS_SEARCH,	"sNSSEARCH" },	/* XXX 's' */
    503  1.6  christos /* RFC 3004 - The User Class Option for DHCP */
    504  1.6  christos 	{ TAG_USER_CLASS,	"$User-Class" },
    505  1.1  christos /* RFC 3011 */
    506  1.1  christos 	{ TAG_IP4_SUBNET_SELECT, "iSUBNET" },
    507  1.1  christos /* RFC 3442 */
    508  1.1  christos 	{ TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
    509  1.1  christos 	{ TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
    510  1.6  christos /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
    511  1.6  christos 	{ TAG_TFTP_SERVER_ADDRESS, "iTFTP-Server-Address" },
    512  1.1  christos /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
    513  1.1  christos 	{ TAG_SLP_NAMING_AUTH,	"aSLP-NA" },
    514  1.1  christos 	{ TAG_CLIENT_FQDN,	"$FQDN" },
    515  1.1  christos 	{ TAG_AGENT_CIRCUIT,	"$Agent-Information" },
    516  1.1  christos 	{ TAG_AGENT_REMOTE,	"bARMT" },
    517  1.1  christos 	{ TAG_AGENT_MASK,	"bAMSK" },
    518  1.1  christos 	{ TAG_TZ_STRING,	"aTZSTR" },
    519  1.1  christos 	{ TAG_FQDN_OPTION,	"bFQDNS" },	/* XXX 'b' */
    520  1.1  christos 	{ TAG_AUTH,		"bAUTH" },	/* XXX 'b' */
    521  1.1  christos 	{ TAG_VINES_SERVERS,	"iVINES" },
    522  1.1  christos 	{ TAG_SERVER_RANK,	"sRANK" },
    523  1.1  christos 	{ TAG_CLIENT_ARCH,	"sARCH" },
    524  1.1  christos 	{ TAG_CLIENT_NDI,	"bNDI" },	/* XXX 'b' */
    525  1.1  christos 	{ TAG_CLIENT_GUID,	"bGUID" },	/* XXX 'b' */
    526  1.1  christos 	{ TAG_LDAP_URL,		"aLDAP" },
    527  1.1  christos 	{ TAG_6OVER4,		"i6o4" },
    528  1.1  christos 	{ TAG_PRINTER_NAME,	"aPRTR" },
    529  1.1  christos 	{ TAG_MDHCP_SERVER,	"bMDHCP" },	/* XXX 'b' */
    530  1.1  christos 	{ TAG_IPX_COMPAT,	"bIPX" },	/* XXX 'b' */
    531  1.1  christos 	{ TAG_NETINFO_PARENT,	"iNI" },
    532  1.1  christos 	{ TAG_NETINFO_PARENT_TAG, "aNITAG" },
    533  1.1  christos 	{ TAG_URL,		"aURL" },
    534  1.1  christos 	{ TAG_FAILOVER,		"bFAIL" },	/* XXX 'b' */
    535  1.6  christos 	{ 0, NULL }
    536  1.1  christos };
    537  1.1  christos /* 2-byte extended tags */
    538  1.4  christos static const struct tok xtag2str[] = {
    539  1.6  christos 	{ 0, NULL }
    540  1.1  christos };
    541  1.1  christos 
    542  1.1  christos /* DHCP "options overload" types */
    543  1.4  christos static const struct tok oo2str[] = {
    544  1.6  christos 	{ 1,	"file" },
    545  1.6  christos 	{ 2,	"sname" },
    546  1.6  christos 	{ 3,	"file+sname" },
    547  1.6  christos 	{ 0, NULL }
    548  1.1  christos };
    549  1.1  christos 
    550  1.1  christos /* NETBIOS over TCP/IP node type options */
    551  1.4  christos static const struct tok nbo2str[] = {
    552  1.6  christos 	{ 0x1,	"b-node" },
    553  1.6  christos 	{ 0x2,	"p-node" },
    554  1.6  christos 	{ 0x4,	"m-node" },
    555  1.6  christos 	{ 0x8,	"h-node" },
    556  1.6  christos 	{ 0, NULL }
    557  1.1  christos };
    558  1.1  christos 
    559  1.1  christos /* ARP Hardware types, for Client-ID option */
    560  1.4  christos static const struct tok arp2str[] = {
    561  1.6  christos 	{ 0x1,	"ether" },
    562  1.6  christos 	{ 0x6,	"ieee802" },
    563  1.6  christos 	{ 0x7,	"arcnet" },
    564  1.6  christos 	{ 0xf,	"frelay" },
    565  1.6  christos 	{ 0x17,	"strip" },
    566  1.6  christos 	{ 0x18,	"ieee1394" },
    567  1.6  christos 	{ 0, NULL }
    568  1.1  christos };
    569  1.1  christos 
    570  1.4  christos static const struct tok dhcp_msg_values[] = {
    571  1.6  christos 	{ DHCPDISCOVER,	"Discover" },
    572  1.6  christos 	{ DHCPOFFER,	"Offer" },
    573  1.6  christos 	{ DHCPREQUEST,	"Request" },
    574  1.6  christos 	{ DHCPDECLINE,	"Decline" },
    575  1.6  christos 	{ DHCPACK,	"ACK" },
    576  1.6  christos 	{ DHCPNAK,	"NACK" },
    577  1.6  christos 	{ DHCPRELEASE,	"Release" },
    578  1.6  christos 	{ DHCPINFORM,	"Inform" },
    579  1.6  christos 	{ 0, NULL }
    580  1.1  christos };
    581  1.1  christos 
    582  1.6  christos #define AGENT_SUBOPTION_CIRCUIT_ID	1	/* RFC 3046 */
    583  1.6  christos #define AGENT_SUBOPTION_REMOTE_ID	2	/* RFC 3046 */
    584  1.6  christos #define AGENT_SUBOPTION_SUBSCRIBER_ID	6	/* RFC 3993 */
    585  1.4  christos static const struct tok agent_suboption_values[] = {
    586  1.6  christos 	{ AGENT_SUBOPTION_CIRCUIT_ID,    "Circuit-ID" },
    587  1.6  christos 	{ AGENT_SUBOPTION_REMOTE_ID,     "Remote-ID" },
    588  1.6  christos 	{ AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" },
    589  1.6  christos 	{ 0, NULL }
    590  1.1  christos };
    591  1.1  christos 
    592  1.1  christos 
    593  1.1  christos static void
    594  1.5  christos rfc1048_print(netdissect_options *ndo,
    595  1.6  christos 	      register const u_char *bp)
    596  1.1  christos {
    597  1.5  christos 	register uint16_t tag;
    598  1.1  christos 	register u_int len;
    599  1.1  christos 	register const char *cp;
    600  1.1  christos 	register char c;
    601  1.1  christos 	int first, idx;
    602  1.5  christos 	uint32_t ul;
    603  1.5  christos 	uint16_t us;
    604  1.5  christos 	uint8_t uc, subopt, suboptlen;
    605  1.1  christos 
    606  1.5  christos 	ND_PRINT((ndo, "\n\t  Vendor-rfc1048 Extensions"));
    607  1.1  christos 
    608  1.1  christos 	/* Step over magic cookie */
    609  1.5  christos 	ND_PRINT((ndo, "\n\t    Magic Cookie 0x%08x", EXTRACT_32BITS(bp)));
    610  1.1  christos 	bp += sizeof(int32_t);
    611  1.1  christos 
    612  1.1  christos 	/* Loop while we there is a tag left in the buffer */
    613  1.5  christos 	while (ND_TTEST2(*bp, 1)) {
    614  1.1  christos 		tag = *bp++;
    615  1.5  christos 		if (tag == TAG_PAD && ndo->ndo_vflag < 3)
    616  1.1  christos 			continue;
    617  1.5  christos 		if (tag == TAG_END && ndo->ndo_vflag < 3)
    618  1.1  christos 			return;
    619  1.1  christos 		if (tag == TAG_EXTENDED_OPTION) {
    620  1.5  christos 			ND_TCHECK2(*(bp + 1), 2);
    621  1.1  christos 			tag = EXTRACT_16BITS(bp + 1);
    622  1.1  christos 			/* XXX we don't know yet if the IANA will
    623  1.1  christos 			 * preclude overlap of 1-byte and 2-byte spaces.
    624  1.1  christos 			 * If not, we need to offset tag after this step.
    625  1.1  christos 			 */
    626  1.1  christos 			cp = tok2str(xtag2str, "?xT%u", tag);
    627  1.1  christos 		} else
    628  1.1  christos 			cp = tok2str(tag2str, "?T%u", tag);
    629  1.1  christos 		c = *cp++;
    630  1.1  christos 
    631  1.1  christos 		if (tag == TAG_PAD || tag == TAG_END)
    632  1.1  christos 			len = 0;
    633  1.1  christos 		else {
    634  1.1  christos 			/* Get the length; check for truncation */
    635  1.5  christos 			ND_TCHECK2(*bp, 1);
    636  1.1  christos 			len = *bp++;
    637  1.1  christos 		}
    638  1.1  christos 
    639  1.5  christos 		ND_PRINT((ndo, "\n\t    %s Option %u, length %u%s", cp, tag, len,
    640  1.6  christos 			  len > 0 ? ": " : ""));
    641  1.1  christos 
    642  1.5  christos 		if (tag == TAG_PAD && ndo->ndo_vflag > 2) {
    643  1.1  christos 			u_int ntag = 1;
    644  1.5  christos 			while (ND_TTEST2(*bp, 1) && *bp == TAG_PAD) {
    645  1.1  christos 				bp++;
    646  1.1  christos 				ntag++;
    647  1.1  christos 			}
    648  1.1  christos 			if (ntag > 1)
    649  1.5  christos 				ND_PRINT((ndo, ", occurs %u", ntag));
    650  1.1  christos 		}
    651  1.1  christos 
    652  1.5  christos 		if (!ND_TTEST2(*bp, len)) {
    653  1.5  christos 			ND_PRINT((ndo, "[|rfc1048 %u]", len));
    654  1.1  christos 			return;
    655  1.1  christos 		}
    656  1.1  christos 
    657  1.1  christos 		if (tag == TAG_DHCP_MESSAGE && len == 1) {
    658  1.1  christos 			uc = *bp++;
    659  1.5  christos 			ND_PRINT((ndo, "%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc)));
    660  1.5  christos 			continue;
    661  1.1  christos 		}
    662  1.1  christos 
    663  1.1  christos 		if (tag == TAG_PARM_REQUEST) {
    664  1.1  christos 			idx = 0;
    665  1.1  christos 			while (len-- > 0) {
    666  1.1  christos 				uc = *bp++;
    667  1.1  christos 				cp = tok2str(tag2str, "?Option %u", uc);
    668  1.1  christos 				if (idx % 4 == 0)
    669  1.5  christos 					ND_PRINT((ndo, "\n\t      "));
    670  1.1  christos 				else
    671  1.5  christos 					ND_PRINT((ndo, ", "));
    672  1.5  christos 				ND_PRINT((ndo, "%s", cp + 1));
    673  1.1  christos 				idx++;
    674  1.1  christos 			}
    675  1.1  christos 			continue;
    676  1.1  christos 		}
    677  1.1  christos 
    678  1.1  christos 		if (tag == TAG_EXTENDED_REQUEST) {
    679  1.1  christos 			first = 1;
    680  1.1  christos 			while (len > 1) {
    681  1.1  christos 				len -= 2;
    682  1.1  christos 				us = EXTRACT_16BITS(bp);
    683  1.1  christos 				bp += 2;
    684  1.1  christos 				cp = tok2str(xtag2str, "?xT%u", us);
    685  1.1  christos 				if (!first)
    686  1.5  christos 					ND_PRINT((ndo, "+"));
    687  1.5  christos 				ND_PRINT((ndo, "%s", cp + 1));
    688  1.1  christos 				first = 0;
    689  1.1  christos 			}
    690  1.1  christos 			continue;
    691  1.1  christos 		}
    692  1.1  christos 
    693  1.1  christos 		/* Print data */
    694  1.1  christos 		if (c == '?') {
    695  1.1  christos 			/* Base default formats for unknown tags on data size */
    696  1.1  christos 			if (len & 1)
    697  1.1  christos 				c = 'b';
    698  1.1  christos 			else if (len & 2)
    699  1.1  christos 				c = 's';
    700  1.1  christos 			else
    701  1.1  christos 				c = 'l';
    702  1.1  christos 		}
    703  1.1  christos 		first = 1;
    704  1.1  christos 		switch (c) {
    705  1.1  christos 
    706  1.1  christos 		case 'a':
    707  1.1  christos 			/* ascii strings */
    708  1.5  christos 			ND_PRINT((ndo, "\""));
    709  1.5  christos 			if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) {
    710  1.5  christos 				ND_PRINT((ndo, "\""));
    711  1.1  christos 				goto trunc;
    712  1.1  christos 			}
    713  1.5  christos 			ND_PRINT((ndo, "\""));
    714  1.1  christos 			bp += len;
    715  1.1  christos 			len = 0;
    716  1.1  christos 			break;
    717  1.1  christos 
    718  1.1  christos 		case 'i':
    719  1.1  christos 		case 'l':
    720  1.1  christos 		case 'L':
    721  1.1  christos 			/* ip addresses/32-bit words */
    722  1.1  christos 			while (len >= sizeof(ul)) {
    723  1.1  christos 				if (!first)
    724  1.5  christos 					ND_PRINT((ndo, ","));
    725  1.1  christos 				ul = EXTRACT_32BITS(bp);
    726  1.1  christos 				if (c == 'i') {
    727  1.1  christos 					ul = htonl(ul);
    728  1.5  christos 					ND_PRINT((ndo, "%s", ipaddr_string(ndo, &ul)));
    729  1.1  christos 				} else if (c == 'L')
    730  1.5  christos 					ND_PRINT((ndo, "%d", ul));
    731  1.1  christos 				else
    732  1.5  christos 					ND_PRINT((ndo, "%u", ul));
    733  1.1  christos 				bp += sizeof(ul);
    734  1.1  christos 				len -= sizeof(ul);
    735  1.1  christos 				first = 0;
    736  1.1  christos 			}
    737  1.1  christos 			break;
    738  1.1  christos 
    739  1.1  christos 		case 'p':
    740  1.1  christos 			/* IP address pairs */
    741  1.1  christos 			while (len >= 2*sizeof(ul)) {
    742  1.1  christos 				if (!first)
    743  1.5  christos 					ND_PRINT((ndo, ","));
    744  1.1  christos 				memcpy((char *)&ul, (const char *)bp, sizeof(ul));
    745  1.5  christos 				ND_PRINT((ndo, "(%s:", ipaddr_string(ndo, &ul)));
    746  1.1  christos 				bp += sizeof(ul);
    747  1.1  christos 				memcpy((char *)&ul, (const char *)bp, sizeof(ul));
    748  1.5  christos 				ND_PRINT((ndo, "%s)", ipaddr_string(ndo, &ul)));
    749  1.1  christos 				bp += sizeof(ul);
    750  1.1  christos 				len -= 2*sizeof(ul);
    751  1.1  christos 				first = 0;
    752  1.1  christos 			}
    753  1.1  christos 			break;
    754  1.1  christos 
    755  1.1  christos 		case 's':
    756  1.1  christos 			/* shorts */
    757  1.1  christos 			while (len >= sizeof(us)) {
    758  1.1  christos 				if (!first)
    759  1.5  christos 					ND_PRINT((ndo, ","));
    760  1.1  christos 				us = EXTRACT_16BITS(bp);
    761  1.5  christos 				ND_PRINT((ndo, "%u", us));
    762  1.1  christos 				bp += sizeof(us);
    763  1.1  christos 				len -= sizeof(us);
    764  1.1  christos 				first = 0;
    765  1.1  christos 			}
    766  1.1  christos 			break;
    767  1.1  christos 
    768  1.1  christos 		case 'B':
    769  1.1  christos 			/* boolean */
    770  1.1  christos 			while (len > 0) {
    771  1.1  christos 				if (!first)
    772  1.5  christos 					ND_PRINT((ndo, ","));
    773  1.1  christos 				switch (*bp) {
    774  1.1  christos 				case 0:
    775  1.5  christos 					ND_PRINT((ndo, "N"));
    776  1.1  christos 					break;
    777  1.1  christos 				case 1:
    778  1.5  christos 					ND_PRINT((ndo, "Y"));
    779  1.1  christos 					break;
    780  1.1  christos 				default:
    781  1.5  christos 					ND_PRINT((ndo, "%u?", *bp));
    782  1.1  christos 					break;
    783  1.1  christos 				}
    784  1.1  christos 				++bp;
    785  1.1  christos 				--len;
    786  1.1  christos 				first = 0;
    787  1.1  christos 			}
    788  1.1  christos 			break;
    789  1.1  christos 
    790  1.1  christos 		case 'b':
    791  1.1  christos 		case 'x':
    792  1.1  christos 		default:
    793  1.1  christos 			/* Bytes */
    794  1.1  christos 			while (len > 0) {
    795  1.1  christos 				if (!first)
    796  1.5  christos 					ND_PRINT((ndo, c == 'x' ? ":" : "."));
    797  1.1  christos 				if (c == 'x')
    798  1.5  christos 					ND_PRINT((ndo, "%02x", *bp));
    799  1.1  christos 				else
    800  1.5  christos 					ND_PRINT((ndo, "%u", *bp));
    801  1.1  christos 				++bp;
    802  1.1  christos 				--len;
    803  1.1  christos 				first = 0;
    804  1.1  christos 			}
    805  1.1  christos 			break;
    806  1.1  christos 
    807  1.1  christos 		case '$':
    808  1.1  christos 			/* Guys we can't handle with one of the usual cases */
    809  1.1  christos 			switch (tag) {
    810  1.1  christos 
    811  1.1  christos 			case TAG_NETBIOS_NODE:
    812  1.1  christos 				/* this option should be at least 1 byte long */
    813  1.6  christos 				if (len < 1) {
    814  1.6  christos 					ND_PRINT((ndo, "ERROR: length < 1 bytes"));
    815  1.1  christos 					break;
    816  1.1  christos 				}
    817  1.1  christos 				tag = *bp++;
    818  1.1  christos 				--len;
    819  1.5  christos 				ND_PRINT((ndo, "%s", tok2str(nbo2str, NULL, tag)));
    820  1.1  christos 				break;
    821  1.1  christos 
    822  1.1  christos 			case TAG_OPT_OVERLOAD:
    823  1.1  christos 				/* this option should be at least 1 byte long */
    824  1.6  christos 				if (len < 1) {
    825  1.6  christos 					ND_PRINT((ndo, "ERROR: length < 1 bytes"));
    826  1.1  christos 					break;
    827  1.1  christos 				}
    828  1.1  christos 				tag = *bp++;
    829  1.1  christos 				--len;
    830  1.5  christos 				ND_PRINT((ndo, "%s", tok2str(oo2str, NULL, tag)));
    831  1.1  christos 				break;
    832  1.1  christos 
    833  1.1  christos 			case TAG_CLIENT_FQDN:
    834  1.1  christos 				/* this option should be at least 3 bytes long */
    835  1.6  christos 				if (len < 3) {
    836  1.6  christos 					ND_PRINT((ndo, "ERROR: length < 3 bytes"));
    837  1.1  christos 					bp += len;
    838  1.1  christos 					len = 0;
    839  1.1  christos 					break;
    840  1.1  christos 				}
    841  1.1  christos 				if (*bp)
    842  1.5  christos 					ND_PRINT((ndo, "[%s] ", client_fqdn_flags(*bp)));
    843  1.1  christos 				bp++;
    844  1.1  christos 				if (*bp || *(bp+1))
    845  1.5  christos 					ND_PRINT((ndo, "%u/%u ", *bp, *(bp+1)));
    846  1.1  christos 				bp += 2;
    847  1.5  christos 				ND_PRINT((ndo, "\""));
    848  1.5  christos 				if (fn_printn(ndo, bp, len - 3, ndo->ndo_snapend)) {
    849  1.5  christos 					ND_PRINT((ndo, "\""));
    850  1.1  christos 					goto trunc;
    851  1.1  christos 				}
    852  1.5  christos 				ND_PRINT((ndo, "\""));
    853  1.1  christos 				bp += len - 3;
    854  1.1  christos 				len = 0;
    855  1.1  christos 				break;
    856  1.1  christos 
    857  1.1  christos 			case TAG_CLIENT_ID:
    858  1.6  christos 			    {
    859  1.6  christos 				int type;
    860  1.1  christos 
    861  1.1  christos 				/* this option should be at least 1 byte long */
    862  1.6  christos 				if (len < 1) {
    863  1.6  christos 					ND_PRINT((ndo, "ERROR: length < 1 bytes"));
    864  1.1  christos 					break;
    865  1.1  christos 				}
    866  1.1  christos 				type = *bp++;
    867  1.1  christos 				len--;
    868  1.1  christos 				if (type == 0) {
    869  1.5  christos 					ND_PRINT((ndo, "\""));
    870  1.5  christos 					if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) {
    871  1.5  christos 						ND_PRINT((ndo, "\""));
    872  1.1  christos 						goto trunc;
    873  1.1  christos 					}
    874  1.5  christos 					ND_PRINT((ndo, "\""));
    875  1.1  christos 					bp += len;
    876  1.1  christos 					len = 0;
    877  1.1  christos 					break;
    878  1.1  christos 				} else {
    879  1.5  christos 					ND_PRINT((ndo, "%s ", tok2str(arp2str, "hardware-type %u,", type)));
    880  1.1  christos 					while (len > 0) {
    881  1.1  christos 						if (!first)
    882  1.5  christos 							ND_PRINT((ndo, ":"));
    883  1.5  christos 						ND_PRINT((ndo, "%02x", *bp));
    884  1.1  christos 						++bp;
    885  1.1  christos 						--len;
    886  1.1  christos 						first = 0;
    887  1.1  christos 					}
    888  1.1  christos 				}
    889  1.1  christos 				break;
    890  1.1  christos 			    }
    891  1.1  christos 
    892  1.1  christos 			case TAG_AGENT_CIRCUIT:
    893  1.1  christos 				while (len >= 2) {
    894  1.1  christos 					subopt = *bp++;
    895  1.1  christos 					suboptlen = *bp++;
    896  1.1  christos 					len -= 2;
    897  1.1  christos 					if (suboptlen > len) {
    898  1.5  christos 						ND_PRINT((ndo, "\n\t      %s SubOption %u, length %u: length goes past end of option",
    899  1.6  christos 							  tok2str(agent_suboption_values, "Unknown", subopt),
    900  1.6  christos 							  subopt,
    901  1.6  christos 							  suboptlen));
    902  1.1  christos 						bp += len;
    903  1.1  christos 						len = 0;
    904  1.1  christos 						break;
    905  1.1  christos 					}
    906  1.5  christos 					ND_PRINT((ndo, "\n\t      %s SubOption %u, length %u: ",
    907  1.6  christos 						  tok2str(agent_suboption_values, "Unknown", subopt),
    908  1.6  christos 						  subopt,
    909  1.6  christos 						  suboptlen));
    910  1.1  christos 					switch (subopt) {
    911  1.1  christos 
    912  1.5  christos 					case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
    913  1.5  christos 					case AGENT_SUBOPTION_REMOTE_ID:
    914  1.5  christos 					case AGENT_SUBOPTION_SUBSCRIBER_ID:
    915  1.6  christos 						if (fn_printn(ndo, bp, suboptlen, ndo->ndo_snapend))
    916  1.6  christos 							goto trunc;
    917  1.5  christos 						break;
    918  1.1  christos 
    919  1.1  christos 					default:
    920  1.5  christos 						print_unknown_data(ndo, bp, "\n\t\t", suboptlen);
    921  1.1  christos 					}
    922  1.1  christos 
    923  1.1  christos 					len -= suboptlen;
    924  1.1  christos 					bp += suboptlen;
    925  1.6  christos 				}
    926  1.6  christos 				break;
    927  1.1  christos 
    928  1.1  christos 			case TAG_CLASSLESS_STATIC_RT:
    929  1.1  christos 			case TAG_CLASSLESS_STA_RT_MS:
    930  1.6  christos 			    {
    931  1.1  christos 				u_int mask_width, significant_octets, i;
    932  1.1  christos 
    933  1.1  christos 				/* this option should be at least 5 bytes long */
    934  1.6  christos 				if (len < 5) {
    935  1.6  christos 					ND_PRINT((ndo, "ERROR: length < 5 bytes"));
    936  1.1  christos 					bp += len;
    937  1.1  christos 					len = 0;
    938  1.1  christos 					break;
    939  1.1  christos 				}
    940  1.1  christos 				while (len > 0) {
    941  1.1  christos 					if (!first)
    942  1.5  christos 						ND_PRINT((ndo, ","));
    943  1.1  christos 					mask_width = *bp++;
    944  1.1  christos 					len--;
    945  1.1  christos 					/* mask_width <= 32 */
    946  1.1  christos 					if (mask_width > 32) {
    947  1.6  christos 						ND_PRINT((ndo, "[ERROR: Mask width (%d) > 32]", mask_width));
    948  1.1  christos 						bp += len;
    949  1.1  christos 						len = 0;
    950  1.1  christos 						break;
    951  1.1  christos 					}
    952  1.1  christos 					significant_octets = (mask_width + 7) / 8;
    953  1.1  christos 					/* significant octets + router(4) */
    954  1.1  christos 					if (len < significant_octets + 4) {
    955  1.6  christos 						ND_PRINT((ndo, "[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4));
    956  1.1  christos 						bp += len;
    957  1.1  christos 						len = 0;
    958  1.1  christos 						break;
    959  1.1  christos 					}
    960  1.5  christos 					ND_PRINT((ndo, "("));
    961  1.1  christos 					if (mask_width == 0)
    962  1.5  christos 						ND_PRINT((ndo, "default"));
    963  1.1  christos 					else {
    964  1.1  christos 						for (i = 0; i < significant_octets ; i++) {
    965  1.1  christos 							if (i > 0)
    966  1.5  christos 								ND_PRINT((ndo, "."));
    967  1.5  christos 							ND_PRINT((ndo, "%d", *bp++));
    968  1.1  christos 						}
    969  1.1  christos 						for (i = significant_octets ; i < 4 ; i++)
    970  1.5  christos 							ND_PRINT((ndo, ".0"));
    971  1.5  christos 						ND_PRINT((ndo, "/%d", mask_width));
    972  1.1  christos 					}
    973  1.1  christos 					memcpy((char *)&ul, (const char *)bp, sizeof(ul));
    974  1.5  christos 					ND_PRINT((ndo, ":%s)", ipaddr_string(ndo, &ul)));
    975  1.1  christos 					bp += sizeof(ul);
    976  1.1  christos 					len -= (significant_octets + 4);
    977  1.1  christos 					first = 0;
    978  1.1  christos 				}
    979  1.6  christos 				break;
    980  1.6  christos 			    }
    981  1.6  christos 
    982  1.6  christos 			case TAG_USER_CLASS:
    983  1.6  christos 			    {
    984  1.6  christos 				u_int suboptnumber = 1;
    985  1.6  christos 
    986  1.6  christos 				first = 1;
    987  1.6  christos 				if (len < 2) {
    988  1.6  christos 					ND_PRINT((ndo, "ERROR: length < 2 bytes"));
    989  1.6  christos 					bp += len;
    990  1.6  christos 					len = 0;
    991  1.6  christos 					break;
    992  1.6  christos 				}
    993  1.6  christos 				while (len > 0) {
    994  1.6  christos 					suboptlen = *bp++;
    995  1.6  christos 					len--;
    996  1.6  christos 					ND_PRINT((ndo, "\n\t      "));
    997  1.6  christos 					ND_PRINT((ndo, "instance#%u: ", suboptnumber));
    998  1.6  christos 					if (suboptlen == 0) {
    999  1.6  christos 						ND_PRINT((ndo, "ERROR: suboption length must be non-zero"));
   1000  1.6  christos 						bp += len;
   1001  1.6  christos 						len = 0;
   1002  1.6  christos 						break;
   1003  1.6  christos 					}
   1004  1.6  christos 					if (len < suboptlen) {
   1005  1.6  christos 						ND_PRINT((ndo, "ERROR: malformed option"));
   1006  1.6  christos 						bp += len;
   1007  1.6  christos 						len = 0;
   1008  1.6  christos 						break;
   1009  1.6  christos 					}
   1010  1.6  christos 					ND_PRINT((ndo, "\""));
   1011  1.6  christos 					if (fn_printn(ndo, bp, suboptlen, ndo->ndo_snapend)) {
   1012  1.6  christos 						ND_PRINT((ndo, "\""));
   1013  1.6  christos 						goto trunc;
   1014  1.6  christos 					}
   1015  1.6  christos 					ND_PRINT((ndo, "\""));
   1016  1.6  christos 					ND_PRINT((ndo, ", length %d", suboptlen));
   1017  1.6  christos 					suboptnumber++;
   1018  1.6  christos 					len -= suboptlen;
   1019  1.6  christos 					bp += suboptlen;
   1020  1.6  christos 				}
   1021  1.6  christos 				break;
   1022  1.6  christos 			    }
   1023  1.1  christos 
   1024  1.1  christos 			default:
   1025  1.5  christos 				ND_PRINT((ndo, "[unknown special tag %u, size %u]",
   1026  1.6  christos 					  tag, len));
   1027  1.1  christos 				bp += len;
   1028  1.1  christos 				len = 0;
   1029  1.1  christos 				break;
   1030  1.1  christos 			}
   1031  1.1  christos 			break;
   1032  1.1  christos 		}
   1033  1.1  christos 		/* Data left over? */
   1034  1.1  christos 		if (len) {
   1035  1.5  christos 			ND_PRINT((ndo, "\n\t  trailing data length %u", len));
   1036  1.1  christos 			bp += len;
   1037  1.1  christos 		}
   1038  1.1  christos 	}
   1039  1.1  christos 	return;
   1040  1.1  christos trunc:
   1041  1.5  christos 	ND_PRINT((ndo, "|[rfc1048]"));
   1042  1.1  christos }
   1043  1.1  christos 
   1044  1.1  christos static void
   1045  1.5  christos cmu_print(netdissect_options *ndo,
   1046  1.6  christos 	  register const u_char *bp)
   1047  1.1  christos {
   1048  1.1  christos 	register const struct cmu_vend *cmu;
   1049  1.1  christos 
   1050  1.5  christos #define PRINTCMUADDR(m, s) { ND_TCHECK(cmu->m); \
   1051  1.1  christos     if (cmu->m.s_addr != 0) \
   1052  1.5  christos 	ND_PRINT((ndo, " %s:%s", s, ipaddr_string(ndo, &cmu->m.s_addr))); }
   1053  1.1  christos 
   1054  1.5  christos 	ND_PRINT((ndo, " vend-cmu"));
   1055  1.1  christos 	cmu = (const struct cmu_vend *)bp;
   1056  1.1  christos 
   1057  1.1  christos 	/* Only print if there are unknown bits */
   1058  1.5  christos 	ND_TCHECK(cmu->v_flags);
   1059  1.1  christos 	if ((cmu->v_flags & ~(VF_SMASK)) != 0)
   1060  1.5  christos 		ND_PRINT((ndo, " F:0x%x", cmu->v_flags));
   1061  1.1  christos 	PRINTCMUADDR(v_dgate, "DG");
   1062  1.1  christos 	PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
   1063  1.1  christos 	PRINTCMUADDR(v_dns1, "NS1");
   1064  1.1  christos 	PRINTCMUADDR(v_dns2, "NS2");
   1065  1.1  christos 	PRINTCMUADDR(v_ins1, "IEN1");
   1066  1.1  christos 	PRINTCMUADDR(v_ins2, "IEN2");
   1067  1.1  christos 	PRINTCMUADDR(v_ts1, "TS1");
   1068  1.1  christos 	PRINTCMUADDR(v_ts2, "TS2");
   1069  1.1  christos 	return;
   1070  1.1  christos 
   1071  1.1  christos trunc:
   1072  1.5  christos 	ND_PRINT((ndo, "%s", tstr));
   1073  1.1  christos #undef PRINTCMUADDR
   1074  1.1  christos }
   1075  1.1  christos 
   1076  1.1  christos static char *
   1077  1.1  christos client_fqdn_flags(u_int flags)
   1078  1.1  christos {
   1079  1.1  christos 	static char buf[8+1];
   1080  1.1  christos 	int i = 0;
   1081  1.1  christos 
   1082  1.1  christos 	if (flags & CLIENT_FQDN_FLAGS_S)
   1083  1.1  christos 		buf[i++] = 'S';
   1084  1.1  christos 	if (flags & CLIENT_FQDN_FLAGS_O)
   1085  1.1  christos 		buf[i++] = 'O';
   1086  1.1  christos 	if (flags & CLIENT_FQDN_FLAGS_E)
   1087  1.1  christos 		buf[i++] = 'E';
   1088  1.1  christos 	if (flags & CLIENT_FQDN_FLAGS_N)
   1089  1.1  christos 		buf[i++] = 'N';
   1090  1.1  christos 	buf[i] = '\0';
   1091  1.1  christos 
   1092  1.1  christos 	return buf;
   1093  1.1  christos }
   1094