X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/f555c163f90c9de17ebcef8313f86404c5174ca9..cbb769e118310cde158fdc05f1cc67bd057dbcb9:/print-bootp.c diff --git a/print-bootp.c b/print-bootp.c index a5fb2552..641b8feb 100644 --- a/print-bootp.c +++ b/print-bootp.c @@ -22,31 +22,30 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.46 1999-10-07 23:47:11 mcr Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.56 2000-12-04 00:00:08 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include #include #include -#if __STDC__ struct mbuf; struct rtentry; -#endif -#include #include -#include #include -#ifdef HAVE_MEMORY_H -#include -#endif #include #include #include "interface.h" #include "addrtoname.h" +#include "extract.h" +#include "ether.h" #include "bootp.h" static void rfc1048_print(const u_char *, u_int); @@ -102,6 +101,8 @@ bootp_print(register const u_char *cp, u_int length, printf(" xid:0x%x", (u_int32_t)ntohl(bp->bp_xid)); if (bp->bp_secs) printf(" secs:%d", ntohs(bp->bp_secs)); + if (bp->bp_flags) + printf(" flags:0x%x", ntohs(bp->bp_flags)); /* Client's ip address */ TCHECK(bp->bp_ciaddr); @@ -173,7 +174,7 @@ bootp_print(register const u_char *cp, u_int length, else { u_int32_t ul; - memcpy((char *)&ul, (char *)bp->bp_vend, sizeof(ul)); + ul = EXTRACT_32BITS(&bp->bp_vend); if (ul != 0) printf("vend-#0x%x", ul); } @@ -188,7 +189,7 @@ static struct tok tag2str[] = { /* RFC1048 tags */ { TAG_PAD, " PAD" }, { TAG_SUBNET_MASK, "iSM" }, /* subnet mask (RFC950) */ - { TAG_TIME_OFFSET, "lTZ" }, /* seconds from UTC */ + { TAG_TIME_OFFSET, "LTZ" }, /* seconds from UTC */ { TAG_GATEWAY, "iDG" }, /* default gateway */ { TAG_TIME_SERVER, "iTS" }, /* time servers (RFC868) */ { TAG_NAME_SERVER, "iIEN" }, /* IEN name servers (IEN116) */ @@ -207,6 +208,102 @@ static struct tok tag2str[] = { { TAG_SWAP_SERVER, "iSS" }, { TAG_ROOTPATH, "aRP" }, { TAG_EXTPATH, "aEP" }, +/* RFC2132 tags */ + { TAG_IP_FORWARD, "BIPF" }, + { TAG_NL_SRCRT, "BSRT" }, + { TAG_PFILTERS, "pPF" }, + { TAG_REASS_SIZE, "sRSZ" }, + { TAG_DEF_TTL, "bTTL" }, + { TAG_MTU_TIMEOUT, "lMA" }, + { TAG_MTU_TABLE, "sMT" }, + { TAG_INT_MTU, "sMTU" }, + { TAG_LOCAL_SUBNETS, "BLSN" }, + { TAG_BROAD_ADDR, "iBR" }, + { TAG_DO_MASK_DISC, "BMD" }, + { TAG_SUPPLY_MASK, "BMS" }, + { TAG_DO_RDISC, "BRD" }, + { TAG_RTR_SOL_ADDR, "iRSA" }, + { TAG_STATIC_ROUTE, "pSR" }, + { TAG_USE_TRAILERS, "BUT" }, + { TAG_ARP_TIMEOUT, "lAT" }, + { TAG_ETH_ENCAP, "BIE" }, + { TAG_TCP_TTL, "bTT" }, + { TAG_TCP_KEEPALIVE, "lKI" }, + { TAG_KEEPALIVE_GO, "BKG" }, + { TAG_NIS_DOMAIN, "aYD" }, + { TAG_NIS_SERVERS, "iYS" }, + { TAG_NTP_SERVERS, "iNTP" }, + { TAG_VENDOR_OPTS, "bVO" }, + { TAG_NETBIOS_NS, "iWNS" }, + { TAG_NETBIOS_DDS, "iWDD" }, + { TAG_NETBIOS_NODE, "bWNT" }, + { TAG_NETBIOS_SCOPE, "aWSC" }, + { TAG_XWIN_FS, "iXFS" }, + { TAG_XWIN_DM, "iXDM" }, + { TAG_NIS_P_DOMAIN, "sN+D" }, + { TAG_NIS_P_SERVERS, "iN+S" }, + { TAG_MOBILE_HOME, "iMH" }, + { TAG_SMPT_SERVER, "iSMTP" }, + { TAG_POP3_SERVER, "iPOP3" }, + { TAG_NNTP_SERVER, "iNNTP" }, + { TAG_WWW_SERVER, "iWWW" }, + { TAG_FINGER_SERVER, "iFG" }, + { TAG_IRC_SERVER, "iIRC" }, + { TAG_STREETTALK_SRVR, "iSTS" }, + { TAG_STREETTALK_STDA, "iSTDA" }, + { TAG_REQUESTED_IP, "iRQ" }, + { TAG_IP_LEASE, "lLT" }, + { TAG_OPT_OVERLOAD, "bOO" }, + { TAG_TFTP_SERVER, "aTFTP" }, + { TAG_BOOTFILENAME, "aBF" }, + { TAG_DHCP_MESSAGE, " DHCP" }, + { TAG_SERVER_ID, "iSID" }, + { TAG_PARM_REQUEST, "bPR" }, + { TAG_MESSAGE, "aMSG" }, + { TAG_MAX_MSG_SIZE, "sMSZ" }, + { TAG_RENEWAL_TIME, "lRN" }, + { TAG_REBIND_TIME, "lRB" }, + { TAG_VENDOR_CLASS, "bVC" }, + { TAG_CLIENT_ID, "xCID" }, +/* RFC 2485 */ + { TAG_OPEN_GROUP_UAP, "aUAP" }, +/* RFC 2563 */ + { TAG_DISABLE_AUTOCONF, "BNOAUTO" }, +/* RFC 2610 */ + { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */ + { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */ +/* RFC 2937 */ + { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */ +/* RFC 3011 */ + { TAG_IP4_SUBNET_SELECT, "iSUBNET" }, +/* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */ + { TAG_USER_CLASS, "aCLASS" }, + { TAG_SLP_NAMING_AUTH, "aSLP-NA" }, + { TAG_CLIENT_FQDN, "bFQDN" }, /* XXX 'b' */ + { TAG_AGENT_CIRCUIT, "bACKT" }, + { TAG_AGENT_REMOTE, "bARMT" }, + { TAG_AGENT_MASK, "bAMSK" }, + { TAG_TZ_STRING, "aTZSTR" }, + { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */ + { TAG_AUTH, "bAUTH" }, /* XXX 'b' */ + { TAG_VINES_SERVERS, "iVINES" }, + { TAG_SERVER_RANK, "sRANK" }, + { TAG_CLIENT_ARCH, "sARCH" }, + { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */ + { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */ + { TAG_LDAP_URL, "aLDAP" }, + { TAG_6OVER4, "i6o4" }, + { TAG_PRINTER_NAME, "aPRTR" }, + { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */ + { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */ + { TAG_NETINFO_PARENT, "iNI" }, + { TAG_NETINFO_PARENT_TAG, "aNITAG" }, + { TAG_URL, "aURL" }, + { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */ + { 0, NULL } +}; +/* 2-byte extended tags */ +static struct tok xtag2str[] = { { 0, NULL } }; @@ -233,7 +330,16 @@ rfc1048_print(register const u_char *bp, register u_int length) continue; if (tag == TAG_END) return; - cp = tok2str(tag2str, "?T%d", tag); + if (tag == TAG_EXTENDED_OPTION) { + TCHECK2(*(bp + 1), 2); + tag = EXTRACT_16BITS(bp + 1); + /* XXX we don't know yet if the IANA will + * preclude overlap of 1-byte and 2-byte spaces. + * If not, we need to offset tag after this step. + */ + cp = tok2str(xtag2str, "?xT%d", tag); + } else + cp = tok2str(tag2str, "?T%d", tag); c = *cp++; printf(" %s:", cp); @@ -248,6 +354,49 @@ rfc1048_print(register const u_char *bp, register u_int length) return; } + if (tag == TAG_DHCP_MESSAGE && len == 1) { + c = *bp++; + switch (c) { + case DHCPDISCOVER: printf("DISCOVER"); break; + case DHCPOFFER: printf("OFFER"); break; + case DHCPREQUEST: printf("REQUEST"); break; + case DHCPDECLINE: printf("DECLINE"); break; + case DHCPACK: printf("ACK"); break; + case DHCPNAK: printf("NACK"); break; + case DHCPRELEASE: printf("RELEASE"); break; + case DHCPINFORM: printf("INFORM"); break; + default: printf("%u", c); break; + } + continue; + } + + if (tag == TAG_PARM_REQUEST) { + first = 1; + while (len-- > 0) { + c = *bp++; + cp = tok2str(tag2str, "?T%d", c); + if (!first) + putchar('+'); + printf("%s", cp + 1); + first = 0; + } + continue; + } + if (tag == TAG_EXTENDED_REQUEST) { + first = 1; + while (len > 1) { + len -= 2; + c = EXTRACT_16BITS(bp); + bp += 2; + cp = tok2str(xtag2str, "?xT%d", c); + if (!first) + putchar('+'); + printf("%s", cp + 1); + first = 0; + } + continue; + } + /* Print data */ size = len; if (c == '?') { @@ -273,13 +422,17 @@ rfc1048_print(register const u_char *bp, register u_int length) case 'i': case 'l': + case 'L': /* ip addresses/32-bit words */ while (size >= sizeof(ul)) { if (!first) putchar(','); - memcpy((char *)&ul, (char *)bp, sizeof(ul)); - if (c == 'i') + ul = EXTRACT_32BITS(bp); + if (c == 'i') { + ul = htonl(ul); printf("%s", ipaddr_string(&ul)); + } else if (c == 'L') + printf("%d", ul); else printf("%u", ul); bp += sizeof(ul); @@ -288,12 +441,28 @@ rfc1048_print(register const u_char *bp, register u_int length) } break; + case 'p': + /* IP address pairs */ + while (size >= 2*sizeof(ul)) { + if (!first) + putchar(','); + memcpy((char *)&ul, (char *)bp, sizeof(ul)); + printf("(%s:", ipaddr_string(&ul)); + bp += sizeof(ul); + memcpy((char *)&ul, (char *)bp, sizeof(ul)); + printf("%s)", ipaddr_string(&ul)); + bp += sizeof(ul); + size -= 2*sizeof(ul); + first = 0; + } + break; + case 's': /* shorts */ while (size >= sizeof(us)) { if (!first) putchar(','); - memcpy((char *)&us, (char *)bp, sizeof(us)); + us = EXTRACT_16BITS(bp); printf("%d", us); bp += sizeof(us); size -= sizeof(us); @@ -301,13 +470,36 @@ rfc1048_print(register const u_char *bp, register u_int length) } break; + case 'B': + /* boolean */ + while (size > 0) { + if (!first) + putchar(','); + switch (*bp) { + case 0: + putchar('N'); + break; + case 1: + putchar('Y'); + break; + default: + printf("%d?", *bp); + break; + } + ++bp; + --size; + first = 0; + } + break; + case 'b': + case 'x': default: /* Bytes */ while (size > 0) { if (!first) - putchar('.'); - printf("%d", *bp); + putchar (c == 'x' ? ':' : '.'); + printf (c == 'x' ? "%02x" : "%d", *bp); ++bp; --size; first = 0; @@ -318,6 +510,9 @@ rfc1048_print(register const u_char *bp, register u_int length) if (size) printf("[len %d]", len); } + return; +trunc: + printf("|[rfc1048]"); } static void