X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/3cd171317f54bc968808d49e3ca87b6c49ccdcdd..b9cef7b4dda394a1fe0038a0ca69f9d18118dc4e:/print-bootp.c diff --git a/print-bootp.c b/print-bootp.c index ec1052b1..04f767ee 100644 --- a/print-bootp.c +++ b/print-bootp.c @@ -22,7 +22,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.49 2000-07-01 03:39:01 assar Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.59 2001-07-04 21:18:12 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -35,10 +35,8 @@ static const char rcsid[] = struct mbuf; struct rtentry; -#include #include -#include #include #include @@ -46,6 +44,8 @@ struct rtentry; #include "interface.h" #include "addrtoname.h" +#include "extract.h" +#include "ether.h" #include "bootp.h" static void rfc1048_print(const u_char *, u_int); @@ -174,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); } @@ -184,12 +184,24 @@ trunc: fputs(tstr, stdout); } -/* The first character specifies the format to print */ +/* + * The first character specifies the format to print: + * i - ip address (32 bits) + * p - ip address pairs (32 bits + 32 bits) + * l - long (32 bits) + * L - unsigned long (32 bits) + * s - short (16 bits) + * b - period-seperated decimal bytes (variable length) + * x - colon-seperated hex bytes (variable length) + * a - ascii string (variable length) + * B - on/off (8 bits) + * $ - special (explicit code to handle) + */ 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) */ @@ -236,7 +248,7 @@ static struct tok tag2str[] = { { TAG_VENDOR_OPTS, "bVO" }, { TAG_NETBIOS_NS, "iWNS" }, { TAG_NETBIOS_DDS, "iWDD" }, - { TAG_NETBIOS_NODE, "bWNT" }, + { TAG_NETBIOS_NODE, "$WNT" }, { TAG_NETBIOS_SCOPE, "aWSC" }, { TAG_XWIN_FS, "iXFS" }, { TAG_XWIN_DM, "iXDM" }, @@ -253,7 +265,7 @@ static struct tok tag2str[] = { { TAG_STREETTALK_STDA, "iSTDA" }, { TAG_REQUESTED_IP, "iRQ" }, { TAG_IP_LEASE, "lLT" }, - { TAG_OPT_OVERLOAD, "bOO" }, + { TAG_OPT_OVERLOAD, "$OO" }, { TAG_TFTP_SERVER, "aTFTP" }, { TAG_BOOTFILENAME, "aBF" }, { TAG_DHCP_MESSAGE, " DHCP" }, @@ -263,8 +275,75 @@ static struct tok tag2str[] = { { TAG_MAX_MSG_SIZE, "sMSZ" }, { TAG_RENEWAL_TIME, "lRN" }, { TAG_REBIND_TIME, "lRB" }, - { TAG_VENDOR_CLASS, "bVC" }, - { TAG_CLIENT_ID, "bCID" }, + { TAG_VENDOR_CLASS, "aVC" }, + { TAG_CLIENT_ID, "$CID" }, +/* 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, "$FQDN" }, + { 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 } +}; + +/* DHCP "options overload" types */ +static struct tok oo2str[] = { + { 1, "file" }, + { 2, "sname" }, + { 3, "file+sname" }, + { 0, NULL } +}; + +/* NETBIOS over TCP/IP node type options */ +static struct tok nbo2str[] = { + { 0x1, "b-node" }, + { 0x2, "p-node" }, + { 0x4, "m-node" }, + { 0x8, "h-node" }, + { 0, NULL } +}; + +/* ARP Hardware types, for Client-ID option */ +static struct tok arp2str[] = { + { 0x1, "ether" }, + { 0x6, "ieee802" }, + { 0x7, "arcnet" }, + { 0xf, "frelay" }, + { 0x17, "strip" }, + { 0x18, "ieee1394" }, { 0, NULL } }; @@ -291,7 +370,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); @@ -326,7 +414,21 @@ rfc1048_print(register const u_char *bp, register u_int length) first = 1; while (len-- > 0) { c = *bp++; - cp = tok2str(tag2str, "?%d", c); + 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); @@ -360,13 +462,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); @@ -396,7 +502,7 @@ rfc1048_print(register const u_char *bp, register u_int length) 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); @@ -427,33 +533,99 @@ rfc1048_print(register const u_char *bp, register u_int length) break; case 'b': + case 'x': default: /* Bytes */ while (size > 0) { if (!first) - putchar('.'); - printf("%d", *bp); + putchar(c == 'x' ? ':' : '.'); + if (c == 'x') + printf("%02x", *bp); + else + printf("%d", *bp); ++bp; --size; first = 0; } break; + + case '$': + /* Guys we can't handle with one of the usual cases */ + switch (tag) { + + case TAG_NETBIOS_NODE: + tag = *bp++; + --size; + fputs(tok2str(nbo2str, NULL, tag), stdout); + break; + + case TAG_OPT_OVERLOAD: + tag = *bp++; + --size; + fputs(tok2str(oo2str, NULL, tag), stdout); + break; + + case TAG_CLIENT_FQDN: + if (*bp++) + printf("[svrreg]"); + if (*bp) + printf("%d/%d/", *bp, *(bp+1)); + bp += 2; + putchar('"'); + (void)fn_printn(bp, size - 3, NULL); + putchar('"'); + bp += size - 3; + size = 0; + break; + + case TAG_CLIENT_ID: + { int type = *bp++; + size--; + if (type == 0) { + putchar('"'); + (void)fn_printn(bp, size, NULL); + putchar('"'); + break; + } else { + printf("[%s]", tok2str(arp2str, "type-%d", type)); + } + while (size > 0) { + if (!first) + putchar(':'); + printf("%02x", *bp); + ++bp; + --size; + first = 0; + } + break; + } + + default: + printf("[unknown special tag %d, size %d]", + tag, size); + bp += size; + size = 0; + break; + } + break; } /* Data left over? */ if (size) printf("[len %d]", len); } + return; +trunc: + printf("|[rfc1048]"); } static void cmu_print(register const u_char *bp, register u_int length) { register const struct cmu_vend *cmu; - char *fmt = " %s:%s"; #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \ if (cmu->m.s_addr != 0) \ - printf(fmt, s, ipaddr_string(&cmu->m.s_addr)); } + printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); } printf(" vend-cmu"); cmu = (struct cmu_vend *)bp;