]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ip.c
Patch sent to Debian by Roderick Schertler <[email protected]> to print
[tcpdump] / print-ip.c
index 2ae036afe3966bb08283e70fa02cb08122f94079..505cf847b665b9f5b9c6969aa44357ef7cf93dc2 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.79 1999-12-22 06:27:21 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.89 2000-10-03 02:54:58 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -33,16 +33,7 @@ static const char rcsid[] =
 #include <sys/socket.h>
 
 #include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_var.h>
-#include <netinet/udp.h>
-#include <netinet/udp_var.h>
-#include <netinet/tcp.h>
-
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -52,6 +43,8 @@ static const char rcsid[] =
 #include "interface.h"
 #include "extract.h"                   /* must come after interface.h */
 
+#include "ip.h"
+
 /* Compatibility */
 #ifndef        IPPROTO_ND
 #define        IPPROTO_ND      77
@@ -299,7 +292,15 @@ ip_optprint(register const u_char *cp, u_int length)
        for (; length > 0; cp += len, length -= len) {
                int tt = *cp;
 
-               len = (tt == IPOPT_NOP || tt == IPOPT_EOL) ? 1 : cp[1];
+               if (tt == IPOPT_NOP || tt == IPOPT_EOL)
+                       len = 1;
+               else {
+                       if (&cp[1] >= snapend) {
+                               printf("[|ip]");
+                               return;
+                       }
+                       len = cp[1];
+               }
                if (len <= 0) {
                        printf("[|ip op len %d]", len);
                        return;
@@ -442,7 +443,11 @@ ip_print(register const u_char *bp, register u_int length)
                (void)printf("truncated-ip %d", length);
                return;
        }
-       hlen = ip->ip_hl * 4;
+       hlen = IP_HL(ip) * 4;
+       if (hlen < sizeof (struct ip)) {
+               (void)printf("bad-hlen %d", hlen);
+               return;
+       }
 
        len = ntohs(ip->ip_len);
        if (length < len)
@@ -626,6 +631,13 @@ again:
                        pim_print(cp, len);
                        break;
 
+#ifndef IPPROTO_VRRP
+#define IPPROTO_VRRP   112
+#endif
+               case IPPROTO_VRRP:
+                       vrrp_print(cp, len, ip->ip_ttl);
+                       break;
+
                default:
 #if 0
                        (void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
@@ -695,6 +707,8 @@ again:
                        (void)printf("%sid %d", sep, (int)ntohs(ip->ip_id));
                        sep = ", ";
                }
+               (void)printf("%slen %d", sep, (int)ntohs(ip->ip_len));
+               sep = ", ";
                if ((u_char *)ip + hlen <= snapend) {
                        sum = in_cksum((const u_short *)ip, hlen, 0);
                        if (sum != 0) {
@@ -710,3 +724,29 @@ again:
                printf(")");
        }
 }
+
+void
+ipN_print(register const u_char *bp, register u_int length)
+{
+       struct ip *ip, hdr;
+
+       ip = (struct ip *)bp;
+       if (length < 4) {
+               (void)printf("truncated-ip %d", length);
+               return;
+       }
+       memcpy (&hdr, (char *)ip, 4);
+       switch (IP_V(&hdr)) {
+       case 4:
+           ip_print (bp, length);
+           return;
+#ifdef INET6
+       case 6:
+           ip6_print (bp, length);
+           return;
+#endif
+       default:
+           (void)printf("unknown ip %d", IP_V(&hdr));
+           return;
+       }
+}