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