]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ip.c
The payload of an SCTP DATA chunk is *not* necessarily ASCII text, so it
[tcpdump] / print-ip.c
index 8d1bbdad08a2efdc94778ba01be548ee504fcf93..c14d2fc2977bdedfb5a39166fbd23261cbe2b74f 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.99 2001-08-20 17:52:39 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.102 2001-11-16 02:17:36 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -34,6 +34,7 @@ static const char rcsid[] =
 
 #include <netinet/in.h>
 
+#include <netdb.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -217,7 +218,7 @@ ip_optprint(register const u_char *cp, u_int length)
  * don't modifiy the packet.
  */
 u_short
-in_cksum(const u_short *addr, register int len, int csum)
+in_cksum(const u_short *addr, register u_int len, int csum)
 {
        int nleft = len;
        const u_short *w = addr;
@@ -257,13 +258,12 @@ ip_print(register const u_char *bp, register u_int length)
        register const u_char *cp;
        u_char nh;
        int advance;
+       struct protoent *proto;
 
        ip = (const struct ip *)bp;
 #ifdef LBL_ALIGN
        /*
         * If the IP header is not aligned, copy into abuf.
-        * This will never happen with BPF.  It does happen raw packet
-        * dumps from -r.
         */
        if ((long)ip & 3) {
                static u_char *abuf = NULL;
@@ -408,7 +408,7 @@ again:
 #define IPPROTO_IGMP 2
 #endif
                case IPPROTO_IGMP:
-                       igmp_print(cp, len, (const u_char *)ip);
+                       igmp_print(cp, len);
                        break;
 
                case 4:
@@ -461,7 +461,11 @@ again:
                        break;
 
                default:
-                       (void)printf(" ip-proto-%d %d", nh, len);
+                       if ((proto = getprotobynumber(nh)) != NULL)
+                               (void)printf(" %s", proto->p_name);
+                       else
+                               (void)printf(" ip-proto-%d", nh);
+                       printf(" %d", len);
                        break;
                }
        }
@@ -480,11 +484,17 @@ again:
        if (off & 0x3fff) {
                /*
                 * if this isn't the first frag, we're missing the
-                * next level protocol header.  print the ip addr.
+                * next level protocol header.  print the ip addr
+                * and the protocol.
                 */
-               if (off & 0x1fff)
+               if (off & 0x1fff) {
                        (void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
                                      ipaddr_string(&ip->ip_dst));
+                       if ((proto = getprotobynumber(ip->ip_p)) != NULL)
+                               (void)printf(" %s", proto->p_name);
+                       else
+                               (void)printf(" ip-proto-%d", ip->ip_p);
+               }
 #ifndef IP_MF
 #define IP_MF 0x2000
 #endif /* IP_MF */