11b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/* 21b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 31b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * The Regents of the University of California. All rights reserved. 41b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * 51b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Redistribution and use in source and binary forms, with or without 61b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * modification, are permitted provided that: (1) source code distributions 71b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * retain the above copyright notice and this paragraph in its entirety, (2) 81b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * distributions including binary code include the above copyright notice and 91b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * this paragraph in its entirety in the documentation or other materials 101b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * provided with the distribution, and (3) all advertising materials mentioning 111b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * features or use of this software display the following acknowledgement: 121b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * ``This product includes software developed by the University of California, 131b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 141b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * the University nor the names of its contributors may be used to endorse 151b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * or promote products derived from this software without specific prior 161b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * written permission. 171b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 181b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 1955a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 2002e21d6a5b5117d494777a36783909854854f751Jeff Sharkey * 211b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Format and print bootp packets. 223ca7481439c9b65a137d7705d0f4a16766529e75Jeff Sharkey */ 231b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey#ifndef lint 24d4dd7716fb825f29a609c5c4cb31204eea78183aJeff Sharkeystatic const char rcsid[] _U_ = 252e4dce0dd24aa89ca6adf6559f13d3e342ff8558Jeff Sharkey "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.89 2008-04-22 09:45:08 hannes Exp $ (LBL)"; 261b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey#endif 271b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 281b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey#ifdef HAVE_CONFIG_H 291b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey#include "config.h" 301b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey#endif 31630a1712168f402653039e368259cb9480454fa8Jeff Sharkey 321b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey#include <tcpdump-stdinc.h> 33630a1712168f402653039e368259cb9480454fa8Jeff Sharkey 341b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey#include <stdio.h> 351b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey#include <string.h> 361b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 378b2c3a14603d163d7564e6f60286995079687690Jeff Sharkey#include "interface.h" 383256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey#include "addrtoname.h" 391b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey#include "extract.h" 403256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey#include "ether.h" 4155a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey#include "bootp.h" 4255a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey 431b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic void rfc1048_print(const u_char *); 441b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic void cmu_print(const u_char *); 451b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic char *client_fqdn_flags(u_int flags); 461b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 471b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic char tstr[] = " [|bootp]"; 481b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 491b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic const struct tok bootp_flag_values[] = { 501b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 0x8000, "Broadcast" }, 514e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { 0, NULL} 526973634ce61ab7d4c1d51c70be6d51725b89e7b9Jeff Sharkey}; 534e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey 546973634ce61ab7d4c1d51c70be6d51725b89e7b9Jeff Sharkeystatic const struct tok bootp_op_values[] = { 554e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { BOOTPREQUEST, "Request" }, 564e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { BOOTPREPLY, "Reply" }, 574e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { 0, NULL} 58234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey}; 59234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey 6055a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey/* 614e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey * Print bootp requests 621b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 63630a1712168f402653039e368259cb9480454fa8Jeff Sharkeyvoid 64630a1712168f402653039e368259cb9480454fa8Jeff Sharkeybootp_print(register const u_char *cp, u_int length) 65630a1712168f402653039e368259cb9480454fa8Jeff Sharkey{ 66630a1712168f402653039e368259cb9480454fa8Jeff Sharkey register const struct bootp *bp; 67630a1712168f402653039e368259cb9480454fa8Jeff Sharkey static const u_char vm_cmu[4] = VM_CMU; 68630a1712168f402653039e368259cb9480454fa8Jeff Sharkey static const u_char vm_rfc1048[4] = VM_RFC1048; 69630a1712168f402653039e368259cb9480454fa8Jeff Sharkey 70630a1712168f402653039e368259cb9480454fa8Jeff Sharkey bp = (const struct bootp *)cp; 71630a1712168f402653039e368259cb9480454fa8Jeff Sharkey TCHECK(bp->bp_op); 7270c70530bd6793869736ec894498e4ebf5dc9b20Jeff Sharkey 7370c70530bd6793869736ec894498e4ebf5dc9b20Jeff Sharkey printf("BOOTP/DHCP, %s", 748b2c3a14603d163d7564e6f60286995079687690Jeff Sharkey tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op)); 7570c70530bd6793869736ec894498e4ebf5dc9b20Jeff Sharkey 7670c70530bd6793869736ec894498e4ebf5dc9b20Jeff Sharkey if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) { 7770c70530bd6793869736ec894498e4ebf5dc9b20Jeff Sharkey TCHECK2(bp->bp_chaddr[0], 6); 7870c70530bd6793869736ec894498e4ebf5dc9b20Jeff Sharkey printf(" from %s", etheraddr_string(bp->bp_chaddr)); 79630a1712168f402653039e368259cb9480454fa8Jeff Sharkey } 808fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey 818fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey printf(", length %u", length); 821b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 834e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey if (!vflag) 848fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey return; 854e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey 861b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey TCHECK(bp->bp_secs); 871b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 888fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey /* The usual hardware address type is 1 (10Mb Ethernet) */ 898fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey if (bp->bp_htype != 1) 901b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey printf(", htype %d", bp->bp_htype); 918fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey 924e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /* The usual length for 10Mb Ethernet address is 6 bytes */ 938fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey if (bp->bp_htype != 1 || bp->bp_hlen != 6) 944e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey printf(", hlen %d", bp->bp_hlen); 951b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 961b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /* Only print interesting fields */ 978fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey if (bp->bp_hops) 988fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey printf(", hops %d", bp->bp_hops); 991b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey if (EXTRACT_32BITS(&bp->bp_xid)) 1008fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey printf(", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid)); 1014e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey if (EXTRACT_16BITS(&bp->bp_secs)) 1028fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey printf(", secs %d", EXTRACT_16BITS(&bp->bp_secs)); 1034e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey 1041b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey printf(", Flags [%s]", 1051b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags))); 106234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey if (vflag > 1) 107234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey printf(" (0x%04x)", EXTRACT_16BITS(&bp->bp_flags)); 108234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey 109234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey /* Client's ip address */ 110234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey TCHECK(bp->bp_ciaddr); 111234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey if (EXTRACT_32BITS(&bp->bp_ciaddr.s_addr)) 112234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey printf("\n\t Client-IP %s", ipaddr_string(&bp->bp_ciaddr)); 113234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey 1148fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey /* 'your' ip address (bootp client) */ 1158fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey TCHECK(bp->bp_yiaddr); 1161b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey if (EXTRACT_32BITS(&bp->bp_yiaddr.s_addr)) 1178fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey printf("\n\t Your-IP %s", ipaddr_string(&bp->bp_yiaddr)); 118234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey 1198fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey /* Server's ip address */ 1208fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey TCHECK(bp->bp_siaddr); 1218fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey if (EXTRACT_32BITS(&bp->bp_siaddr.s_addr)) 1224e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey printf("\n\t Server-IP %s", ipaddr_string(&bp->bp_siaddr)); 1238fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey 1248fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey /* Gateway's ip address */ 1258fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey TCHECK(bp->bp_giaddr); 1268fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey if (EXTRACT_32BITS(&bp->bp_giaddr.s_addr)) 1278fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey printf("\n\t Gateway-IP %s", ipaddr_string(&bp->bp_giaddr)); 1288fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey 1298fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey /* Client's Ethernet address */ 1308fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey if (bp->bp_htype == 1 && bp->bp_hlen == 6) { 1318fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey TCHECK2(bp->bp_chaddr[0], 6); 1324e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey printf("\n\t Client-Ethernet-Address %s", etheraddr_string(bp->bp_chaddr)); 1331b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1344e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey 1354e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey TCHECK2(bp->bp_sname[0], 1); /* check first char only */ 1364e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey if (*bp->bp_sname) { 1374e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey printf("\n\t sname \""); 1384e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey if (fn_print(bp->bp_sname, snapend)) { 1398fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey putchar('"'); 1404e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey fputs(tstr + 1, stdout); 1414e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return; 14255a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey } 14355a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey putchar('"'); 14455a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey } 14555a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey TCHECK2(bp->bp_file[0], 1); /* check first char only */ 14655a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey if (*bp->bp_file) { 14755a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey printf("\n\t file \""); 14855a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey if (fn_print(bp->bp_file, snapend)) { 14955a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey putchar('"'); 1504e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey fputs(tstr + 1, stdout); 1514e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return; 1523256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey } 1533256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey putchar('"'); 1543256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey } 1553256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey 1563256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey /* Decode the vendor buffer */ 1573256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey TCHECK(bp->bp_vend[0]); 1583256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey if (memcmp((const char *)bp->bp_vend, vm_rfc1048, 1593256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey sizeof(u_int32_t)) == 0) 1603256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey rfc1048_print(bp->bp_vend); 1613256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey else if (memcmp((const char *)bp->bp_vend, vm_cmu, 1623256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey sizeof(u_int32_t)) == 0) 1638fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey cmu_print(bp->bp_vend); 1641b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey else { 1658fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey u_int32_t ul; 1663256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey 1673256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey ul = EXTRACT_32BITS(&bp->bp_vend); 1683256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey if (ul != 0) 1693256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey printf("\n\t Vendor-#0x%x", ul); 1703256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey } 1718fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey 1728fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey return; 1733256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkeytrunc: 1748fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey fputs(tstr, stdout); 1751b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey} 1761b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1774e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey/* 1781b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * The first character specifies the format to print: 1791b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * i - ip address (32 bits) 1803256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey * p - ip address pairs (32 bits + 32 bits) 1818fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey * l - long (32 bits) 1821b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * L - unsigned long (32 bits) 1831b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * s - short (16 bits) 1848fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey * b - period-seperated decimal bytes (variable length) 1851b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * x - colon-seperated hex bytes (variable length) 1861b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * a - ascii string (variable length) 1871b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * B - on/off (8 bits) 1883256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey * $ - special (explicit code to handle) 1898fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey */ 1901b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic const struct tok tag2str[] = { 1911b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/* RFC1048 tags */ 1928fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_PAD, " PAD" }, 1931b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */ 1941b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */ 1951b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */ 1961b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */ 1971b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */ 1981b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */ 1998fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */ 2008fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */ 2018fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */ 2023256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */ 2033256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */ 2043256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_HOSTNAME, "aHostname" }, /* ascii hostname */ 2053256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */ 2063256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_END, " END" }, 2073256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey/* RFC1497 tags */ 2088fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_DUMPPATH, "aDP" }, 2098fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_DOMAINNAME, "aDomain-Name" }, 2108fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_SWAP_SERVER, "iSS" }, 2118fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_ROOTPATH, "aRP" }, 2128fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_EXTPATH, "aEP" }, 2131b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/* RFC2132 tags */ 2141b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_IP_FORWARD, "BIPF" }, 2151b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_NL_SRCRT, "BSRT" }, 2161b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_PFILTERS, "pPF" }, 217e6585b32ea586743258a5457e2184ffc087f2d2fKenny Root { TAG_REASS_SIZE, "sRSZ" }, 2181b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_DEF_TTL, "bTTL" }, 2191b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_MTU_TIMEOUT, "lMTU-Timeout" }, 2201b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_MTU_TABLE, "sMTU-Table" }, 2211b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_INT_MTU, "sMTU" }, 2221b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_LOCAL_SUBNETS, "BLSN" }, 2231b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_BROAD_ADDR, "iBR" }, 2241b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_DO_MASK_DISC, "BMD" }, 225e6585b32ea586743258a5457e2184ffc087f2d2fKenny Root { TAG_SUPPLY_MASK, "BMS" }, 226e6585b32ea586743258a5457e2184ffc087f2d2fKenny Root { TAG_DO_RDISC, "BRouter-Discovery" }, 2271b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_RTR_SOL_ADDR, "iRSA" }, 2281b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_STATIC_ROUTE, "pStatic-Route" }, 2291b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_USE_TRAILERS, "BUT" }, 2301b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_ARP_TIMEOUT, "lAT" }, 2313256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_ETH_ENCAP, "BIE" }, 2323256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_TCP_TTL, "bTT" }, 2333256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_TCP_KEEPALIVE, "lKI" }, 2343256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_KEEPALIVE_GO, "BKG" }, 2353256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_NIS_DOMAIN, "aYD" }, 2363256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_NIS_SERVERS, "iYS" }, 2373256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_NTP_SERVERS, "iNTP" }, 2383256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_VENDOR_OPTS, "bVendor-Option" }, 2393256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_NETBIOS_NS, "iNetbios-Name-Server" }, 2403256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_NETBIOS_DDS, "iWDD" }, 2413256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_NETBIOS_NODE, "$Netbios-Node" }, 2423256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_NETBIOS_SCOPE, "aNetbios-Scope" }, 2431b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_XWIN_FS, "iXFS" }, 2441b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_XWIN_DM, "iXDM" }, 2451b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_NIS_P_DOMAIN, "sN+D" }, 2461b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_NIS_P_SERVERS, "iN+S" }, 2471b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_MOBILE_HOME, "iMH" }, 2481b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_SMPT_SERVER, "iSMTP" }, 2491b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_POP3_SERVER, "iPOP3" }, 2501b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_NNTP_SERVER, "iNNTP" }, 2518fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_WWW_SERVER, "iWWW" }, 2528fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_FINGER_SERVER, "iFG" }, 2538fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_IRC_SERVER, "iIRC" }, 2548fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey { TAG_STREETTALK_SRVR, "iSTS" }, 2551b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_STREETTALK_STDA, "iSTDA" }, 256630a1712168f402653039e368259cb9480454fa8Jeff Sharkey { TAG_REQUESTED_IP, "iRequested-IP" }, 2571b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_IP_LEASE, "lLease-Time" }, 2581b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_OPT_OVERLOAD, "$OO" }, 2591b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_TFTP_SERVER, "aTFTP" }, 2601b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_BOOTFILENAME, "aBF" }, 2611b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_DHCP_MESSAGE, " DHCP-Message" }, 2621b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_SERVER_ID, "iServer-ID" }, 2631b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_PARM_REQUEST, "bParameter-Request" }, 2641b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_MESSAGE, "aMSG" }, 2651b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_MAX_MSG_SIZE, "sMSZ" }, 2661b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_RENEWAL_TIME, "lRN" }, 2671b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_REBIND_TIME, "lRB" }, 2684e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { TAG_VENDOR_CLASS, "aVendor-Class" }, 2694e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { TAG_CLIENT_ID, "$Client-ID" }, 270234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey/* RFC 2485 */ 271234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey { TAG_OPEN_GROUP_UAP, "aUAP" }, 272234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey/* RFC 2563 */ 273234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey { TAG_DISABLE_AUTOCONF, "BNOAUTO" }, 27455a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey/* RFC 2610 */ 27555a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */ 2761b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */ 2771b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/* RFC 2937 */ 2781b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */ 2791b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/* RFC 3011 */ 2801b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_IP4_SUBNET_SELECT, "iSUBNET" }, 2811b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/* RFC 3442 */ 282630a1712168f402653039e368259cb9480454fa8Jeff Sharkey { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" }, 2831b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" }, 2841b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */ 285630a1712168f402653039e368259cb9480454fa8Jeff Sharkey { TAG_USER_CLASS, "aCLASS" }, 286630a1712168f402653039e368259cb9480454fa8Jeff Sharkey { TAG_SLP_NAMING_AUTH, "aSLP-NA" }, 2871b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_CLIENT_FQDN, "$FQDN" }, 288630a1712168f402653039e368259cb9480454fa8Jeff Sharkey { TAG_AGENT_CIRCUIT, "$Agent-Information" }, 2893256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_AGENT_REMOTE, "bARMT" }, 2903256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_AGENT_MASK, "bAMSK" }, 2913256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey { TAG_TZ_STRING, "aTZSTR" }, 2921b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */ 2931b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_AUTH, "bAUTH" }, /* XXX 'b' */ 2941b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_VINES_SERVERS, "iVINES" }, 2951b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_SERVER_RANK, "sRANK" }, 29602e21d6a5b5117d494777a36783909854854f751Jeff Sharkey { TAG_CLIENT_ARCH, "sARCH" }, 2971b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */ 2986973634ce61ab7d4c1d51c70be6d51725b89e7b9Jeff Sharkey { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */ 2991b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_LDAP_URL, "aLDAP" }, 300d4dd7716fb825f29a609c5c4cb31204eea78183aJeff Sharkey { TAG_6OVER4, "i6o4" }, 301630a1712168f402653039e368259cb9480454fa8Jeff Sharkey { TAG_PRINTER_NAME, "aPRTR" }, 302630a1712168f402653039e368259cb9480454fa8Jeff Sharkey { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */ 303630a1712168f402653039e368259cb9480454fa8Jeff Sharkey { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */ 3041b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_NETINFO_PARENT, "iNI" }, 3051b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_NETINFO_PARENT_TAG, "aNITAG" }, 3061b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_URL, "aURL" }, 3071b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */ 3081b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 0, NULL } 3091b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey}; 3101b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/* 2-byte extended tags */ 3111b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic const struct tok xtag2str[] = { 3121b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 0, NULL } 3131b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey}; 3141b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 315630a1712168f402653039e368259cb9480454fa8Jeff Sharkey/* DHCP "options overload" types */ 3161b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic const struct tok oo2str[] = { 3176973634ce61ab7d4c1d51c70be6d51725b89e7b9Jeff Sharkey { 1, "file" }, 3181b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 2, "sname" }, 319d4dd7716fb825f29a609c5c4cb31204eea78183aJeff Sharkey { 3, "file+sname" }, 320630a1712168f402653039e368259cb9480454fa8Jeff Sharkey { 0, NULL } 321630a1712168f402653039e368259cb9480454fa8Jeff Sharkey}; 322630a1712168f402653039e368259cb9480454fa8Jeff Sharkey 323630a1712168f402653039e368259cb9480454fa8Jeff Sharkey/* NETBIOS over TCP/IP node type options */ 3241b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic const struct tok nbo2str[] = { 3251b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 0x1, "b-node" }, 3261b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 0x2, "p-node" }, 3271b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 0x4, "m-node" }, 3281b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 0x8, "h-node" }, 3291b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 0, NULL } 3301b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey}; 3311b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 3321b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/* ARP Hardware types, for Client-ID option */ 3331b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic const struct tok arp2str[] = { 3341b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 0x1, "ether" }, 3351b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { 0x6, "ieee802" }, 3363ca7481439c9b65a137d7705d0f4a16766529e75Jeff Sharkey { 0x7, "arcnet" }, 3373ca7481439c9b65a137d7705d0f4a16766529e75Jeff Sharkey { 0xf, "frelay" }, 338e6585b32ea586743258a5457e2184ffc087f2d2fKenny Root { 0x17, "strip" }, 3392e4dce0dd24aa89ca6adf6559f13d3e342ff8558Jeff Sharkey { 0x18, "ieee1394" }, 3403ca7481439c9b65a137d7705d0f4a16766529e75Jeff Sharkey { 0, NULL } 3413ca7481439c9b65a137d7705d0f4a16766529e75Jeff Sharkey}; 3421b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 3431b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeystatic const struct tok dhcp_msg_values[] = { 3441b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey { DHCPDISCOVER, "Discover" }, 3454e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { DHCPOFFER, "Offer" }, 3464e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { DHCPREQUEST, "Request" }, 3474e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { DHCPDECLINE, "Decline" }, 3484e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { DHCPACK, "ACK" }, 3494e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { DHCPNAK, "NACK" }, 3504e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { DHCPRELEASE, "Release" }, 3514e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { DHCPINFORM, "Inform" }, 3524e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey { 0, NULL } 3534e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey}; 3544e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey 355234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey#define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */ 356234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey#define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */ 357234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey#define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */ 358234766a36af6214644fa8205202287084ca9cf93Jeff Sharkeystatic const struct tok agent_suboption_values[] = { 35970c70530bd6793869736ec894498e4ebf5dc9b20Jeff Sharkey { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" }, 360234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey { AGENT_SUBOPTION_REMOTE_ID, "Remote-ID" }, 361234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey { AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" }, 362234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey { 0, NULL } 363234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey}; 364234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey 365234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey 366234766a36af6214644fa8205202287084ca9cf93Jeff Sharkeystatic void 367234766a36af6214644fa8205202287084ca9cf93Jeff Sharkeyrfc1048_print(register const u_char *bp) 368234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey{ 369234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey register u_int16_t tag; 370234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey register u_int len; 371234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey register const char *cp; 372234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey register char c; 37355a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey int first, idx; 37455a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey u_int32_t ul; 37555a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey u_int16_t us; 37655a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey u_int8_t uc, subopt, suboptlen; 37755a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey 37855a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey printf("\n\t Vendor-rfc1048 Extensions"); 37955a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey 38055a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey /* Step over magic cookie */ 38155a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey printf("\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp)); 38255a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey bp += sizeof(int32_t); 3834e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey 3841b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /* Loop while we there is a tag left in the buffer */ 3851b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey while (TTEST2(*bp, 1)) { 3861b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey tag = *bp++; 3871b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey if (tag == TAG_PAD && vflag < 3) 3881b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey continue; 3891b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey if (tag == TAG_END && vflag < 3) 3901b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return; 3911b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey if (tag == TAG_EXTENDED_OPTION) { 3921b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey TCHECK2(*(bp + 1), 2); 3934e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey tag = EXTRACT_16BITS(bp + 1); 3944e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /* XXX we don't know yet if the IANA will 395234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey * preclude overlap of 1-byte and 2-byte spaces. 396234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey * If not, we need to offset tag after this step. 397234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey */ 398234766a36af6214644fa8205202287084ca9cf93Jeff Sharkey cp = tok2str(xtag2str, "?xT%u", tag); 39955a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey } else 40055a442e58262e253df965d652bd8219c8d1e72d3Jeff Sharkey cp = tok2str(tag2str, "?T%u", tag); 4011b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey c = *cp++; 4021b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 4031b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey if (tag == TAG_PAD || tag == TAG_END) 4041b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey len = 0; 4051b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey else { 406d4dd7716fb825f29a609c5c4cb31204eea78183aJeff Sharkey /* Get the length; check for truncation */ 407d4dd7716fb825f29a609c5c4cb31204eea78183aJeff Sharkey TCHECK2(*bp, 1); 408d4dd7716fb825f29a609c5c4cb31204eea78183aJeff Sharkey len = *bp++; 409d4dd7716fb825f29a609c5c4cb31204eea78183aJeff Sharkey } 410d4dd7716fb825f29a609c5c4cb31204eea78183aJeff Sharkey 411d4dd7716fb825f29a609c5c4cb31204eea78183aJeff Sharkey printf("\n\t %s Option %u, length %u%s", cp, tag, len, 412d4dd7716fb825f29a609c5c4cb31204eea78183aJeff Sharkey len > 0 ? ": " : ""); 4133256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey 4143256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey if (tag == TAG_PAD && vflag > 2) { 4153256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey u_int ntag = 1; 4163256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey while (TTEST2(*bp, 1) && *bp == TAG_PAD) { 4173256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey bp++; 4183256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey ntag++; 4193256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey } 4203256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey if (ntag > 1) 4213256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey printf(", occurs %u", ntag); 4223256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey } 4233256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey 4243256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey if (!TTEST2(*bp, len)) { 4253256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey printf("[|rfc1048 %u]", len); 4263256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey return; 4273256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey } 4283256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey 4293256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey if (tag == TAG_DHCP_MESSAGE && len == 1) { 4303256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey uc = *bp++; 4313256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey printf("%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc)); 4323256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey continue; 4333256601f5e4d94713f59e97b9d4912875c1bdcafJeff Sharkey } 4341b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 4358fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey if (tag == TAG_PARM_REQUEST) { 4361b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey idx = 0; 4371b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey while (len-- > 0) { 4381b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey uc = *bp++; 4391b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey cp = tok2str(tag2str, "?Option %u", uc); 4408fc27e8b87bd1def854a03d84009143b315d4176Jeff Sharkey if (idx % 4 == 0) 4411b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey printf("\n\t "); 4421b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey else 4431b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey printf(", "); 4441b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey printf("%s", cp + 1); 4451b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey idx++; 446 } 447 continue; 448 } 449 450 if (tag == TAG_EXTENDED_REQUEST) { 451 first = 1; 452 while (len > 1) { 453 len -= 2; 454 us = EXTRACT_16BITS(bp); 455 bp += 2; 456 cp = tok2str(xtag2str, "?xT%u", us); 457 if (!first) 458 putchar('+'); 459 printf("%s", cp + 1); 460 first = 0; 461 } 462 continue; 463 } 464 465 /* Print data */ 466 if (c == '?') { 467 /* Base default formats for unknown tags on data size */ 468 if (len & 1) 469 c = 'b'; 470 else if (len & 2) 471 c = 's'; 472 else 473 c = 'l'; 474 } 475 first = 1; 476 switch (c) { 477 478 case 'a': 479 /* ascii strings */ 480 putchar('"'); 481 if (fn_printn(bp, len, snapend)) { 482 putchar('"'); 483 goto trunc; 484 } 485 putchar('"'); 486 bp += len; 487 len = 0; 488 break; 489 490 case 'i': 491 case 'l': 492 case 'L': 493 /* ip addresses/32-bit words */ 494 while (len >= sizeof(ul)) { 495 if (!first) 496 putchar(','); 497 ul = EXTRACT_32BITS(bp); 498 if (c == 'i') { 499 ul = htonl(ul); 500 printf("%s", ipaddr_string(&ul)); 501 } else if (c == 'L') 502 printf("%d", ul); 503 else 504 printf("%u", ul); 505 bp += sizeof(ul); 506 len -= sizeof(ul); 507 first = 0; 508 } 509 break; 510 511 case 'p': 512 /* IP address pairs */ 513 while (len >= 2*sizeof(ul)) { 514 if (!first) 515 putchar(','); 516 memcpy((char *)&ul, (const char *)bp, sizeof(ul)); 517 printf("(%s:", ipaddr_string(&ul)); 518 bp += sizeof(ul); 519 memcpy((char *)&ul, (const char *)bp, sizeof(ul)); 520 printf("%s)", ipaddr_string(&ul)); 521 bp += sizeof(ul); 522 len -= 2*sizeof(ul); 523 first = 0; 524 } 525 break; 526 527 case 's': 528 /* shorts */ 529 while (len >= sizeof(us)) { 530 if (!first) 531 putchar(','); 532 us = EXTRACT_16BITS(bp); 533 printf("%u", us); 534 bp += sizeof(us); 535 len -= sizeof(us); 536 first = 0; 537 } 538 break; 539 540 case 'B': 541 /* boolean */ 542 while (len > 0) { 543 if (!first) 544 putchar(','); 545 switch (*bp) { 546 case 0: 547 putchar('N'); 548 break; 549 case 1: 550 putchar('Y'); 551 break; 552 default: 553 printf("%u?", *bp); 554 break; 555 } 556 ++bp; 557 --len; 558 first = 0; 559 } 560 break; 561 562 case 'b': 563 case 'x': 564 default: 565 /* Bytes */ 566 while (len > 0) { 567 if (!first) 568 putchar(c == 'x' ? ':' : '.'); 569 if (c == 'x') 570 printf("%02x", *bp); 571 else 572 printf("%u", *bp); 573 ++bp; 574 --len; 575 first = 0; 576 } 577 break; 578 579 case '$': 580 /* Guys we can't handle with one of the usual cases */ 581 switch (tag) { 582 583 case TAG_NETBIOS_NODE: 584 /* this option should be at least 1 byte long */ 585 if (len < 1) { 586 printf("ERROR: option %u len %u < 1 bytes", 587 TAG_NETBIOS_NODE, len); 588 break; 589 } 590 tag = *bp++; 591 --len; 592 fputs(tok2str(nbo2str, NULL, tag), stdout); 593 break; 594 595 case TAG_OPT_OVERLOAD: 596 /* this option should be at least 1 byte long */ 597 if (len < 1) { 598 printf("ERROR: option %u len %u < 1 bytes", 599 TAG_OPT_OVERLOAD, len); 600 break; 601 } 602 tag = *bp++; 603 --len; 604 fputs(tok2str(oo2str, NULL, tag), stdout); 605 break; 606 607 case TAG_CLIENT_FQDN: 608 /* this option should be at least 3 bytes long */ 609 if (len < 3) { 610 printf("ERROR: option %u len %u < 3 bytes", 611 TAG_CLIENT_FQDN, len); 612 bp += len; 613 len = 0; 614 break; 615 } 616 if (*bp) 617 printf("[%s] ", client_fqdn_flags(*bp)); 618 bp++; 619 if (*bp || *(bp+1)) 620 printf("%u/%u ", *bp, *(bp+1)); 621 bp += 2; 622 putchar('"'); 623 if (fn_printn(bp, len - 3, snapend)) { 624 putchar('"'); 625 goto trunc; 626 } 627 putchar('"'); 628 bp += len - 3; 629 len = 0; 630 break; 631 632 case TAG_CLIENT_ID: 633 { int type; 634 635 /* this option should be at least 1 byte long */ 636 if (len < 1) { 637 printf("ERROR: option %u len %u < 1 bytes", 638 TAG_CLIENT_ID, len); 639 break; 640 } 641 type = *bp++; 642 len--; 643 if (type == 0) { 644 putchar('"'); 645 if (fn_printn(bp, len, snapend)) { 646 putchar('"'); 647 goto trunc; 648 } 649 putchar('"'); 650 bp += len; 651 len = 0; 652 break; 653 } else { 654 printf("%s ", tok2str(arp2str, "hardware-type %u,", type)); 655 while (len > 0) { 656 if (!first) 657 putchar(':'); 658 printf("%02x", *bp); 659 ++bp; 660 --len; 661 first = 0; 662 } 663 } 664 break; 665 } 666 667 case TAG_AGENT_CIRCUIT: 668 while (len >= 2) { 669 subopt = *bp++; 670 suboptlen = *bp++; 671 len -= 2; 672 if (suboptlen > len) { 673 printf("\n\t %s SubOption %u, length %u: length goes past end of option", 674 tok2str(agent_suboption_values, "Unknown", subopt), 675 subopt, 676 suboptlen); 677 bp += len; 678 len = 0; 679 break; 680 } 681 printf("\n\t %s SubOption %u, length %u: ", 682 tok2str(agent_suboption_values, "Unknown", subopt), 683 subopt, 684 suboptlen); 685 switch (subopt) { 686 687 case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */ 688 case AGENT_SUBOPTION_REMOTE_ID: 689 case AGENT_SUBOPTION_SUBSCRIBER_ID: 690 fn_printn(bp, suboptlen, NULL); 691 break; 692 693 default: 694 print_unknown_data(bp, "\n\t\t", suboptlen); 695 } 696 697 len -= suboptlen; 698 bp += suboptlen; 699 } 700 break; 701 702 case TAG_CLASSLESS_STATIC_RT: 703 case TAG_CLASSLESS_STA_RT_MS: 704 { 705 u_int mask_width, significant_octets, i; 706 707 /* this option should be at least 5 bytes long */ 708 if (len < 5) { 709 printf("ERROR: option %u len %u < 5 bytes", 710 TAG_CLASSLESS_STATIC_RT, len); 711 bp += len; 712 len = 0; 713 break; 714 } 715 while (len > 0) { 716 if (!first) 717 putchar(','); 718 mask_width = *bp++; 719 len--; 720 /* mask_width <= 32 */ 721 if (mask_width > 32) { 722 printf("[ERROR: Mask width (%d) > 32]", mask_width); 723 bp += len; 724 len = 0; 725 break; 726 } 727 significant_octets = (mask_width + 7) / 8; 728 /* significant octets + router(4) */ 729 if (len < significant_octets + 4) { 730 printf("[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4); 731 bp += len; 732 len = 0; 733 break; 734 } 735 putchar('('); 736 if (mask_width == 0) 737 printf("default"); 738 else { 739 for (i = 0; i < significant_octets ; i++) { 740 if (i > 0) 741 putchar('.'); 742 printf("%d", *bp++); 743 } 744 for (i = significant_octets ; i < 4 ; i++) 745 printf(".0"); 746 printf("/%d", mask_width); 747 } 748 memcpy((char *)&ul, (const char *)bp, sizeof(ul)); 749 printf(":%s)", ipaddr_string(&ul)); 750 bp += sizeof(ul); 751 len -= (significant_octets + 4); 752 first = 0; 753 } 754 } 755 break; 756 757 default: 758 printf("[unknown special tag %u, size %u]", 759 tag, len); 760 bp += len; 761 len = 0; 762 break; 763 } 764 break; 765 } 766 /* Data left over? */ 767 if (len) { 768 printf("\n\t trailing data length %u", len); 769 bp += len; 770 } 771 } 772 return; 773trunc: 774 printf("|[rfc1048]"); 775} 776 777static void 778cmu_print(register const u_char *bp) 779{ 780 register const struct cmu_vend *cmu; 781 782#define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \ 783 if (cmu->m.s_addr != 0) \ 784 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); } 785 786 printf(" vend-cmu"); 787 cmu = (const struct cmu_vend *)bp; 788 789 /* Only print if there are unknown bits */ 790 TCHECK(cmu->v_flags); 791 if ((cmu->v_flags & ~(VF_SMASK)) != 0) 792 printf(" F:0x%x", cmu->v_flags); 793 PRINTCMUADDR(v_dgate, "DG"); 794 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*"); 795 PRINTCMUADDR(v_dns1, "NS1"); 796 PRINTCMUADDR(v_dns2, "NS2"); 797 PRINTCMUADDR(v_ins1, "IEN1"); 798 PRINTCMUADDR(v_ins2, "IEN2"); 799 PRINTCMUADDR(v_ts1, "TS1"); 800 PRINTCMUADDR(v_ts2, "TS2"); 801 return; 802 803trunc: 804 fputs(tstr, stdout); 805#undef PRINTCMUADDR 806} 807 808static char * 809client_fqdn_flags(u_int flags) 810{ 811 static char buf[8+1]; 812 int i = 0; 813 814 if (flags & CLIENT_FQDN_FLAGS_S) 815 buf[i++] = 'S'; 816 if (flags & CLIENT_FQDN_FLAGS_O) 817 buf[i++] = 'O'; 818 if (flags & CLIENT_FQDN_FLAGS_E) 819 buf[i++] = 'E'; 820 if (flags & CLIENT_FQDN_FLAGS_N) 821 buf[i++] = 'N'; 822 buf[i] = '\0'; 823 824 return buf; 825} 826