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