]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ip.c
add tracefiles for infinite loop testing
[tcpdump] / print-ip.c
index f1f08d2753c4d33f24ee9e4a2346061d551fa669..745ab3c36649c0e2070227389201305ad6847a30 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.128.2.5 2004-03-24 01:27:29 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.128.2.9 2005-01-12 11:27:07 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -72,7 +72,7 @@ ip_printroute(const char *type, register const u_char *cp, u_int length)
 }
 
 /*
- * If source-routing is present, return the final destination.
+ * If source-routing is present and valid, return the final destination.
  * Otherwise, return IP destination.
  *
  * This is used for UDP and TCP pseudo-header in the checksum
@@ -94,14 +94,15 @@ ip_finddst(const struct ip *ip)
 
                TCHECK(*cp);
                tt = *cp;
-               if (tt == IPOPT_NOP || tt == IPOPT_EOL)
+               if (tt == IPOPT_EOL)
+                       break;
+               else if (tt == IPOPT_NOP)
                        len = 1;
                else {
                        TCHECK(cp[1]);
                        len = cp[1];
-               }
-               if (len < 2) {
-                       return 0;
+                       if (len < 2)
+                               break;
                }
                TCHECK2(*cp, len);
                switch (tt) {
@@ -109,15 +110,14 @@ ip_finddst(const struct ip *ip)
                case IPOPT_SSRR:
                case IPOPT_LSRR:
                        if (len < 7)
-                               return 0;
+                               break;
                        memcpy(&retval, cp + len - 4, 4);
                        return retval;
                }
        }
-       return ip->ip_dst.s_addr;
-
 trunc:
-       return 0;
+       memcpy(&retval, &ip->ip_dst.s_addr, sizeof(u_int32_t));
+       return retval;
 }
 
 static void
@@ -200,12 +200,12 @@ ip_optprint(register const u_char *cp, u_int length)
                else {
                        TCHECK(cp[1]);
                        len = cp[1];
+                       if (len < 2) {
+                               printf("[|ip op len %d]", len);
+                               return;
+                       }
+                       TCHECK2(*cp, len);
                }
-               if (len < 2) {
-                       printf("[|ip op len %d]", len);
-                       return;
-               }
-               TCHECK2(*cp, len);
                switch (tt) {
 
                case IPOPT_EOL:
@@ -396,7 +396,7 @@ ip_print(register const u_char *bp, register u_int length)
                return;
        }
        if (length < sizeof (struct ip)) {
-               (void)printf("truncated-ip %d", length);
+               (void)printf("truncated-ip %u", length);
                return;
        }
        hlen = IP_HL(ip) * 4;
@@ -551,7 +551,7 @@ again:
                        break;
 
                case IPPROTO_EGP:
-                       egp_print(cp);
+                       egp_print(cp, len);
                        break;
 
                case IPPROTO_OSPF: