]> The Tcpdump Group git mirrors - tcpdump/commitdiff
per bill fenners suggestion:
authorhannes <hannes>
Mon, 28 Apr 2003 07:43:03 +0000 (07:43 +0000)
committerhannes <hannes>
Mon, 28 Apr 2003 07:43:03 +0000 (07:43 +0000)
  lets print a little more useful information in non-verbose mode like
  - Request/Reply indication
  - hardware adress

bootp.h
print-bootp.c

diff --git a/bootp.h b/bootp.h
index a27e358d48cfcfb3c22f90af56c116df7e709671..35f6297eaa8fc797b474e3490d7bf8792d1b1d90 100644 (file)
--- a/bootp.h
+++ b/bootp.h
@@ -1,4 +1,4 @@
-/* @(#) $Header: /tcpdump/master/tcpdump/bootp.h,v 1.13 2002-12-11 07:13:50 guy Exp $ (LBL) */
+/* @(#) $Header: /tcpdump/master/tcpdump/bootp.h,v 1.14 2003-04-28 07:43:03 hannes Exp $ (LBL) */
 /*
  * Bootstrap Protocol (BOOTP).  RFC951 and RFC1048.
  *
@@ -27,7 +27,7 @@ struct bootp {
        u_int8_t        bp_hops;        /* gateway hops */
        u_int32_t       bp_xid;         /* transaction ID */
        u_int16_t       bp_secs;        /* seconds since boot began */
-       u_int16_t       bp_flags;       /* flags: 0x8000 is broadcast */
+       u_int16_t       bp_flags;       /* flags - see bootp_flag_values[] */
        struct in_addr  bp_ciaddr;      /* client IP address */
        struct in_addr  bp_yiaddr;      /* 'your' IP address */
        struct in_addr  bp_siaddr;      /* server IP address */
@@ -38,15 +38,25 @@ struct bootp {
        u_int8_t        bp_vend[64];    /* vendor-specific area */
 };
 
+static const struct tok bootp_flag_values[] = {
+    { 0x8000,                   "Broadcast" },
+    { 0, NULL}
+};
+
 /*
  * UDP port numbers, server and client.
  */
 #define        IPPORT_BOOTPS           67
 #define        IPPORT_BOOTPC           68
 
-#define BOOTREPLY              2
-#define BOOTREQUEST            1
+#define BOOTPREPLY             2
+#define BOOTPREQUEST           1
 
+static const struct tok bootp_op_values[] = {
+    { BOOTPREQUEST,             "Request" },
+    { BOOTPREPLY,               "Reply" },
+    { 0, NULL}
+};
 
 /*
  * Vendor magic cookie (v_magic) for CMU
index ac9609af0164cecfc819adeaad953f8aabc39887..b4864007ab025d60c044a3331547050627cdaecb 100644 (file)
@@ -22,7 +22,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.71 2003-03-16 23:43:41 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.72 2003-04-28 07:43:03 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -55,32 +55,22 @@ bootp_print(register const u_char *cp, u_short sport, u_short dport, u_int lengt
        static const u_char vm_cmu[4] = VM_CMU;
        static const u_char vm_rfc1048[4] = VM_RFC1048;
 
-        printf("BOOTP/DHCP, length: %u",length);
-
-        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("\n\tRequest");
-               break;
-
-       case BOOTREPLY:
-               /* Usually, a reply goes from a server to a client */
-               if (sport == IPPORT_BOOTPS && dport == IPPORT_BOOTPC)
-                       printf("\n\tReply");
-               break;
-
-       default:
-               printf("\n\tbootp-#%d", bp->bp_op);
-                break;
+
+        printf("BOOTP/DHCP, %s",
+              tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op));
+
+       if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
+               TCHECK2(bp->bp_chaddr[0], 6);
+               printf(" from %s", etheraddr_string(bp->bp_chaddr));
        }
 
+        printf(", length: %u", length);
+
+        if (!vflag)
+            return;
+
        TCHECK(bp->bp_secs);
 
        /* The usual hardware address type is 1 (10Mb Ethernet) */
@@ -98,8 +88,11 @@ bootp_print(register const u_char *cp, u_short sport, u_short dport, u_int lengt
                printf(", xid:0x%x", EXTRACT_32BITS(&bp->bp_xid));
        if (bp->bp_secs)
                printf(", secs:%d", EXTRACT_16BITS(&bp->bp_secs));
-       if (bp->bp_flags)
-               printf(", flags:0x%x", EXTRACT_16BITS(&bp->bp_flags));
+
+       printf(", flags: [%s]",
+              bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags)));
+       if (vflag>1)
+         printf( " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags));
 
        /* Client's ip address */
        TCHECK(bp->bp_ciaddr);