]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ip.c
Get rid of an extra newline.
[tcpdump] / print-ip.c
index d37c47ea2cff2efb6de66b340fb5df64b35b8550..c24f5d520a34598ca1a5b4e320f0475f8ae91647 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.93 2001-01-28 08:18:27 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.104 2002-05-29 09:47:04 guy 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, u_short 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;
@@ -301,7 +301,7 @@ ip_print(register const u_char *bp, register u_int length)
 
        len = ntohs(ip->ip_len);
        if (length < len)
-               (void)printf("truncated-ip - %d bytes missing!",
+               (void)printf("truncated-ip - %d bytes missing! ",
                        len - length);
        len -= hlen;
        len0 = len;
@@ -315,7 +315,11 @@ ip_print(register const u_char *bp, register u_int length)
                cp = (const u_char *)ip + hlen;
                nh = ip->ip_p;
 
-               if (nh != IPPROTO_TCP && nh != IPPROTO_UDP) {
+#ifndef IPPROTO_SCTP
+#define IPPROTO_SCTP 132
+#endif
+               if (nh != IPPROTO_TCP && nh != IPPROTO_UDP &&
+                   nh != IPPROTO_SCTP) {
                        (void)printf("%s > %s: ", ipaddr_string(&ip->ip_src),
                                ipaddr_string(&ip->ip_dst));
                }
@@ -337,10 +341,10 @@ again:
 #endif
                case IPPROTO_ESP:
                    {
-                       int enh;
-                       advance = esp_print(cp, (const u_char *)ip, &enh);
+                       int enh, padlen;
+                       advance = esp_print(cp, (const u_char *)ip, &enh, &padlen);
                        cp += advance;
-                       len -= advance;
+                       len -= advance + padlen;
                        if (enh < 0)
                                break;
                        nh = enh & 0xff;
@@ -362,6 +366,10 @@ again:
                        goto again;
                    }
 
+               case IPPROTO_SCTP:
+                       sctp_print(cp, (const u_char *)ip, len);
+                       break;
+
                case IPPROTO_TCP:
                        tcp_print(cp, len, (const u_char *)ip, (off &~ 0x6000));
                        break;
@@ -382,10 +390,6 @@ again:
                        break;
 
                case IPPROTO_ND:
-#if 0
-                       (void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
-                               ipaddr_string(&ip->ip_dst));
-#endif
                        (void)printf(" nd %d", len);
                        break;
 
@@ -404,20 +408,14 @@ again:
 #define IPPROTO_IGMP 2
 #endif
                case IPPROTO_IGMP:
-                       igmp_print(cp, len, (const u_char *)ip);
+                       igmp_print(cp, len);
                        break;
 
                case 4:
                        /* DVMRP multicast tunnel (ip-in-ip encapsulation) */
-#if 0
-                       if (vflag)
-                               (void)printf("%s > %s: ",
-                                            ipaddr_string(&ip->ip_src),
-                                            ipaddr_string(&ip->ip_dst));
-#endif
                        ip_print(cp, len);
                        if (! vflag) {
-                               printf(" (ipip)");
+                               printf(" (ipip-proto-4)");
                                return;
                        }
                        break;
@@ -428,17 +426,7 @@ again:
 #endif
                case IP6PROTO_ENCAP:
                        /* ip6-in-ip encapsulation */
-#if 0
-                       if (vflag)
-                               (void)printf("%s > %s: ",
-                                            ipaddr_string(&ip->ip_src),
-                                            ipaddr_string(&ip->ip_dst));
-#endif
                        ip6_print(cp, len);
-                       if (! vflag) {
-                               printf(" (encap)");
-                               return;
-                       }
                        break;
 #endif /*INET6*/
 
@@ -447,31 +435,15 @@ again:
 #define IPPROTO_GRE 47
 #endif
                case IPPROTO_GRE:
-                       if (vflag)
-                               (void)printf("gre %s > %s: ",
-                                            ipaddr_string(&ip->ip_src),
-                                            ipaddr_string(&ip->ip_dst));
                        /* do it */
                        gre_print(cp, len);
-                       if (! vflag) {
-                               printf(" (gre encap)");
-                               return;
-                       }
                        break;
 
 #ifndef IPPROTO_MOBILE
 #define IPPROTO_MOBILE 55
 #endif
                case IPPROTO_MOBILE:
-                       if (vflag)
-                               (void)printf("mobile %s > %s: ",
-                                            ipaddr_string(&ip->ip_src),
-                                            ipaddr_string(&ip->ip_dst));
                        mobile_print(cp, len);
-                       if (! vflag) {
-                               printf(" (mobile encap)");
-                               return;
-                       }
                        break;
 
 #ifndef IPPROTO_PIM
@@ -485,19 +457,15 @@ again:
 #define IPPROTO_VRRP   112
 #endif
                case IPPROTO_VRRP:
-                       if (vflag)
-                               (void)printf("vrrp %s > %s: ",
-                                            ipaddr_string(&ip->ip_src),
-                                            ipaddr_string(&ip->ip_dst));
                        vrrp_print(cp, len, ip->ip_ttl);
                        break;
 
                default:
-#if 0
-                       (void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
-                               ipaddr_string(&ip->ip_dst));
-#endif
-                       (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;
                }
        }
@@ -516,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 */
@@ -537,10 +511,17 @@ again:
        if (ip->ip_tos) {
                (void)printf(" [tos 0x%x", (int)ip->ip_tos);
                /* ECN bits */
-               if (ip->ip_tos&0x02) {
-                       (void)printf(",ECT");
-                       if (ip->ip_tos&0x01)
+               if (ip->ip_tos & 0x03) {
+                       switch (ip->ip_tos & 0x03) {
+                       case 1:
+                               (void)printf(",ECT(1)");
+                               break;
+                       case 2:
+                               (void)printf(",ECT(0)");
+                               break;
+                       case 3:
                                (void)printf(",CE");
+                       }
                }
                (void)printf("] ");
        }
@@ -566,8 +547,9 @@ again:
                if ((u_char *)ip + hlen <= snapend) {
                        sum = in_cksum((const u_short *)ip, hlen, 0);
                        if (sum != 0) {
-                               (void)printf("%sbad cksum %x!", sep,
-                                            ntohs(ip->ip_sum));
+                               (void)printf("%sbad cksum %x (->%x)!", sep,
+                                            ntohs(ip->ip_sum),
+                                            ntohs(ip->ip_sum)-sum);
                                sep = ", ";
                        }
                }