X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/77352e05a50ec1c58ad1bf06688b2db440fcdee1..c52bf5af8c28f0eda17083aa38d14b7d5b3a7c4d:/print-bootp.c diff --git a/print-bootp.c b/print-bootp.c index 04f767ee..ed7c76ab 100644 --- a/print-bootp.c +++ b/print-bootp.c @@ -22,23 +22,15 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.59 2001-07-04 21:18:12 fenner Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.68 2002-12-11 07:13:58 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include -#include -#include +#include -struct mbuf; -struct rtentry; - -#include - -#include #include #include @@ -48,8 +40,8 @@ struct rtentry; #include "ether.h" #include "bootp.h" -static void rfc1048_print(const u_char *, u_int); -static void cmu_print(const u_char *, u_int); +static void rfc1048_print(const u_char *); +static void cmu_print(const u_char *); static char tstr[] = " [|bootp]"; @@ -57,72 +49,77 @@ static char tstr[] = " [|bootp]"; * Print bootp requests */ void -bootp_print(register const u_char *cp, u_int length, - u_short sport, u_short dport) +bootp_print(register const u_char *cp, u_short sport, u_short dport, u_int length) { register const struct bootp *bp; - static u_char vm_cmu[4] = VM_CMU; - static u_char vm_rfc1048[4] = VM_RFC1048; + static const u_char vm_cmu[4] = VM_CMU; + static const u_char vm_rfc1048[4] = VM_RFC1048; + + printf("BOOTP/DHCP, length: %u",length); - bp = (struct bootp *)cp; + if (!vflag) + return; + + bp = (const struct bootp *)cp; TCHECK(bp->bp_op); switch (bp->bp_op) { case BOOTREQUEST: /* Usually, a request goes from a client to a server */ - if (sport != IPPORT_BOOTPC || dport != IPPORT_BOOTPS) - printf(" (request)"); + if (sport == IPPORT_BOOTPC && dport == IPPORT_BOOTPS) + printf("\n\tRequest"); break; case BOOTREPLY: /* Usually, a reply goes from a server to a client */ - if (sport != IPPORT_BOOTPS || dport != IPPORT_BOOTPC) - printf(" (reply)"); + if (sport == IPPORT_BOOTPS && dport == IPPORT_BOOTPC) + printf("\n\tReply"); break; default: - printf(" bootp-#%d", bp->bp_op); + printf("\n\tbootp-#%d", bp->bp_op); + break; } TCHECK(bp->bp_secs); /* The usual hardware address type is 1 (10Mb Ethernet) */ if (bp->bp_htype != 1) - printf(" htype-#%d", bp->bp_htype); + printf(", htype-#%d", bp->bp_htype); /* The usual length for 10Mb Ethernet address is 6 bytes */ if (bp->bp_htype != 1 || bp->bp_hlen != 6) - printf(" hlen:%d", bp->bp_hlen); + printf(", hlen:%d", bp->bp_hlen); /* Only print interesting fields */ if (bp->bp_hops) - printf(" hops:%d", bp->bp_hops); + printf(", hops:%d", bp->bp_hops); if (bp->bp_xid) - printf(" xid:0x%x", (u_int32_t)ntohl(bp->bp_xid)); + printf(", xid:0x%x", EXTRACT_32BITS(&bp->bp_xid)); if (bp->bp_secs) - printf(" secs:%d", ntohs(bp->bp_secs)); + printf(", secs:%d", EXTRACT_16BITS(&bp->bp_secs)); if (bp->bp_flags) - printf(" flags:0x%x", ntohs(bp->bp_flags)); + printf(", flags:0x%x", EXTRACT_16BITS(&bp->bp_flags)); /* Client's ip address */ TCHECK(bp->bp_ciaddr); if (bp->bp_ciaddr.s_addr) - printf(" C:%s", ipaddr_string(&bp->bp_ciaddr)); + printf("\n\t Client IP: %s", ipaddr_string(&bp->bp_ciaddr)); /* 'your' ip address (bootp client) */ TCHECK(bp->bp_yiaddr); if (bp->bp_yiaddr.s_addr) - printf(" Y:%s", ipaddr_string(&bp->bp_yiaddr)); + printf("\n\t Your IP: %s", ipaddr_string(&bp->bp_yiaddr)); /* Server's ip address */ TCHECK(bp->bp_siaddr); if (bp->bp_siaddr.s_addr) - printf(" S:%s", ipaddr_string(&bp->bp_siaddr)); + printf("\n\t Server IP: %s", ipaddr_string(&bp->bp_siaddr)); /* Gateway's ip address */ TCHECK(bp->bp_giaddr); if (bp->bp_giaddr.s_addr) - printf(" G:%s", ipaddr_string(&bp->bp_giaddr)); + printf("\n\t Gateway IP: %s", ipaddr_string(&bp->bp_giaddr)); /* Client's Ethernet address */ if (bp->bp_htype == 1 && bp->bp_hlen == 6) { @@ -130,20 +127,20 @@ bootp_print(register const u_char *cp, u_int length, register const char *e; TCHECK2(bp->bp_chaddr[0], 6); - eh = (struct ether_header *)packetp; + eh = (const struct ether_header *)packetp; if (bp->bp_op == BOOTREQUEST) e = (const char *)ESRC(eh); else if (bp->bp_op == BOOTREPLY) e = (const char *)EDST(eh); else - e = 0; - if (e == 0 || memcmp((char *)bp->bp_chaddr, e, 6) != 0) - printf(" ether %s", etheraddr_string(bp->bp_chaddr)); + e = NULL; + if ( bp->bp_chaddr != NULL ) + printf("\n\t Client Ethernet Address: %s", etheraddr_string(bp->bp_chaddr)); } TCHECK2(bp->bp_sname[0], 1); /* check first char only */ if (*bp->bp_sname) { - printf(" sname \""); + printf("\n\t sname \""); if (fn_print(bp->bp_sname, snapend)) { putchar('"'); fputs(tstr + 1, stdout); @@ -153,7 +150,7 @@ bootp_print(register const u_char *cp, u_int length, } TCHECK2(bp->bp_sname[0], 1); /* check first char only */ if (*bp->bp_file) { - printf(" file \""); + printf("\n\t file \""); if (fn_print(bp->bp_file, snapend)) { putchar('"'); fputs(tstr + 1, stdout); @@ -164,19 +161,18 @@ bootp_print(register const u_char *cp, u_int length, /* Decode the vendor buffer */ TCHECK(bp->bp_vend[0]); - length -= sizeof(*bp) - sizeof(bp->bp_vend); - if (memcmp((char *)bp->bp_vend, (char *)vm_rfc1048, + if (memcmp((const char *)bp->bp_vend, vm_rfc1048, sizeof(u_int32_t)) == 0) - rfc1048_print(bp->bp_vend, length); - else if (memcmp((char *)bp->bp_vend, (char *)vm_cmu, + rfc1048_print(bp->bp_vend); + else if (memcmp((const char *)bp->bp_vend, vm_cmu, sizeof(u_int32_t)) == 0) - cmu_print(bp->bp_vend, length); + cmu_print(bp->bp_vend); else { u_int32_t ul; ul = EXTRACT_32BITS(&bp->bp_vend); if (ul != 0) - printf("vend-#0x%x", ul); + printf("\n\t Vendor-#0x%x", ul); } return; @@ -348,17 +344,18 @@ static struct tok arp2str[] = { }; static void -rfc1048_print(register const u_char *bp, register u_int length) +rfc1048_print(register const u_char *bp) { - register u_char tag; + register u_int16_t tag; register u_int len, size; register const char *cp; register char c; int first; u_int32_t ul; - u_short us; + u_int16_t us; + u_int8_t uc; - printf(" vend-rfc1048"); + printf("\n\t Vendor-rfc1048:"); /* Step over magic cookie */ bp += sizeof(int32_t); @@ -377,11 +374,11 @@ rfc1048_print(register const u_char *bp, register u_int length) * 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); + cp = tok2str(xtag2str, "?xT%u", tag); } else - cp = tok2str(tag2str, "?T%d", tag); + cp = tok2str(tag2str, "?T%u", tag); c = *cp++; - printf(" %s:", cp); + printf("\n\t %s:", cp); /* Get the length; check for truncation */ if (bp + 1 >= snapend) { @@ -395,8 +392,8 @@ rfc1048_print(register const u_char *bp, register u_int length) } if (tag == TAG_DHCP_MESSAGE && len == 1) { - c = *bp++; - switch (c) { + uc = *bp++; + switch (uc) { case DHCPDISCOVER: printf("DISCOVER"); break; case DHCPOFFER: printf("OFFER"); break; case DHCPREQUEST: printf("REQUEST"); break; @@ -405,7 +402,7 @@ rfc1048_print(register const u_char *bp, register u_int length) case DHCPNAK: printf("NACK"); break; case DHCPRELEASE: printf("RELEASE"); break; case DHCPINFORM: printf("INFORM"); break; - default: printf("%u", c); break; + default: printf("%u", uc); break; } continue; } @@ -413,8 +410,8 @@ rfc1048_print(register const u_char *bp, register u_int length) if (tag == TAG_PARM_REQUEST) { first = 1; while (len-- > 0) { - c = *bp++; - cp = tok2str(tag2str, "?T%d", c); + uc = *bp++; + cp = tok2str(tag2str, "?T%u", uc); if (!first) putchar('+'); printf("%s", cp + 1); @@ -426,9 +423,9 @@ rfc1048_print(register const u_char *bp, register u_int length) first = 1; while (len > 1) { len -= 2; - c = EXTRACT_16BITS(bp); + us = EXTRACT_16BITS(bp); bp += 2; - cp = tok2str(xtag2str, "?xT%d", c); + cp = tok2str(xtag2str, "?xT%u", us); if (!first) putchar('+'); printf("%s", cp + 1); @@ -486,10 +483,10 @@ rfc1048_print(register const u_char *bp, register u_int length) while (size >= 2*sizeof(ul)) { if (!first) putchar(','); - memcpy((char *)&ul, (char *)bp, sizeof(ul)); + memcpy((char *)&ul, (const char *)bp, sizeof(ul)); printf("(%s:", ipaddr_string(&ul)); bp += sizeof(ul); - memcpy((char *)&ul, (char *)bp, sizeof(ul)); + memcpy((char *)&ul, (const char *)bp, sizeof(ul)); printf("%s)", ipaddr_string(&ul)); bp += sizeof(ul); size -= 2*sizeof(ul); @@ -503,7 +500,7 @@ rfc1048_print(register const u_char *bp, register u_int length) if (!first) putchar(','); us = EXTRACT_16BITS(bp); - printf("%d", us); + printf("%u", us); bp += sizeof(us); size -= sizeof(us); first = 0; @@ -523,7 +520,7 @@ rfc1048_print(register const u_char *bp, register u_int length) putchar('Y'); break; default: - printf("%d?", *bp); + printf("%u?", *bp); break; } ++bp; @@ -542,7 +539,7 @@ rfc1048_print(register const u_char *bp, register u_int length) if (c == 'x') printf("%02x", *bp); else - printf("%d", *bp); + printf("%u", *bp); ++bp; --size; first = 0; @@ -569,7 +566,7 @@ rfc1048_print(register const u_char *bp, register u_int length) if (*bp++) printf("[svrreg]"); if (*bp) - printf("%d/%d/", *bp, *(bp+1)); + printf("%u/%u/", *bp, *(bp+1)); bp += 2; putchar('"'); (void)fn_printn(bp, size - 3, NULL); @@ -583,7 +580,7 @@ rfc1048_print(register const u_char *bp, register u_int length) size--; if (type == 0) { putchar('"'); - (void)fn_printn(bp, size, NULL); + (void)fn_printn(bp, size, NULL); putchar('"'); break; } else { @@ -601,7 +598,7 @@ rfc1048_print(register const u_char *bp, register u_int length) } default: - printf("[unknown special tag %d, size %d]", + printf("[unknown special tag %u, size %u]", tag, size); bp += size; size = 0; @@ -611,7 +608,7 @@ rfc1048_print(register const u_char *bp, register u_int length) } /* Data left over? */ if (size) - printf("[len %d]", len); + printf("[len %u]", len); } return; trunc: @@ -619,7 +616,7 @@ trunc: } static void -cmu_print(register const u_char *bp, register u_int length) +cmu_print(register const u_char *bp) { register const struct cmu_vend *cmu; @@ -628,7 +625,7 @@ cmu_print(register const u_char *bp, register u_int length) printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); } printf(" vend-cmu"); - cmu = (struct cmu_vend *)bp; + cmu = (const struct cmu_vend *)bp; /* Only print if there are unknown bits */ TCHECK(cmu->v_flags);