]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ip.c
Bring in KAME IPv6 tcpdump. replaces esp/ah/isakmp decoder.
[tcpdump] / print-ip.c
index 0d8f9308a43eac837a5a4578948e2677e1d1fb59..9ae000e73444d4e554d1b22fbee25625ec585e07 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.69 1999-10-17 22:18:01 mcr Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.70 1999-10-30 05:11:14 itojun Exp $ (LBL)";
 #endif
 
 #include <sys/param.h>
@@ -31,7 +31,9 @@ static const char rcsid[] =
 #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
@@ -64,7 +66,7 @@ struct tr_query {
        u_int  tr_src;                  /* traceroute source */
        u_int  tr_dst;                  /* traceroute destination */
        u_int  tr_raddr;                /* traceroute response address */
-#ifdef WORDS_BIGENDIAN
+#if defined(WORDS_BIGENDIAN) || (defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN))
        struct {
                u_int   ttl : 8;        /* traceroute response ttl */
                u_int   qid : 24;       /* traceroute query id */
@@ -181,7 +183,7 @@ igmp_print(register const u_char *bp, register u_int len,
                break;
        case 0x14:
                (void)printf("igmp pim");
-               pim_print(bp, len);
+               igmp_pim_print(bp, len);
                break;
        case 0x1e:
                print_mresp(bp, len);
@@ -333,8 +335,10 @@ void
 ip_print(register const u_char *bp, register u_int length)
 {
        register const struct ip *ip;
-       register u_int hlen, len, off;
+       register u_int hlen, len, len0, off;
        register const u_char *cp;
+       u_char nh;
+       int advance;
 
        ip = (const struct ip *)bp;
 #ifdef LBL_ALIGN
@@ -378,6 +382,7 @@ ip_print(register const u_char *bp, register u_int length)
                (void)printf("truncated-ip - %d bytes missing!",
                        len - length);
        len -= hlen;
+       len0 = len;
 
        /*
         * If this is fragment zero, hand it to the next higher
@@ -386,7 +391,48 @@ ip_print(register const u_char *bp, register u_int length)
        off = ntohs(ip->ip_off);
        if ((off & 0x1fff) == 0) {
                cp = (const u_char *)ip + hlen;
-               switch (ip->ip_p) {
+               nh = ip->ip_p;
+
+               if (nh != IPPROTO_TCP && nh != IPPROTO_UDP) {
+                       (void)printf("%s > %s: ", ipaddr_string(&ip->ip_src),
+                               ipaddr_string(&ip->ip_dst));
+               }
+again:
+               switch (nh) {
+
+               case IPPROTO_AH:
+                       nh = *cp;
+                       advance = ah_print(cp, (const u_char *)ip);
+                       cp += advance;
+                       len -= advance;
+                       goto again;
+
+               case IPPROTO_ESP:
+                   {
+                       int enh;
+                       advance = esp_print(cp, (const u_char *)ip, &enh);
+                       cp += advance;
+                       len -= advance;
+                       if (enh < 0)
+                               break;
+                       nh = enh & 0xff;
+                       goto again;
+                   }
+
+#ifndef IPPROTO_IPCOMP
+#define IPPROTO_IPCOMP 108
+#endif
+               case IPPROTO_IPCOMP:
+                   {
+                       int enh;
+                       advance = ipcomp_print(cp, (const u_char *)ip, &enh);
+                       cp += advance;
+                       len -= advance;
+                       if (enh < 0)
+                               break;
+                       nh = enh & 0xff;
+                       goto again;
+                   }
 
                case IPPROTO_TCP:
                        tcp_print(cp, len, (const u_char *)ip);
@@ -408,8 +454,10 @@ ip_print(register const u_char *bp, register u_int length)
                        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;
 
@@ -433,10 +481,12 @@ ip_print(register const u_char *bp, register u_int length)
 
                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)");
@@ -444,6 +494,27 @@ ip_print(register const u_char *bp, register u_int length)
                        }
                        break;
 
+#ifdef INET6
+#ifndef IP6PROTO_ENCAP
+#define IP6PROTO_ENCAP 41
+#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*/
+
+
 #ifndef IPPROTO_GRE
 #define IPPROTO_GRE 47
 #endif
@@ -460,18 +531,41 @@ ip_print(register const u_char *bp, register u_int length)
                        }
                        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;
+
+               case IPPROTO_PIM:
+                       pim_print(cp, len);
+                       break;
+
                default:
+#if 0
                        (void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
                                ipaddr_string(&ip->ip_dst));
-                       (void)printf(" ip-proto-%d %d", ip->ip_p, len);
+#endif
+                       (void)printf(" ip-proto-%d %d", nh, len);
                        break;
                }
        }
+
        /*
         * for fragmented datagrams, print id:size@offset.  On all
         * but the last stick a "+".  For unfragmented datagrams, note
         * the don't fragment flag.
         */
+       len = len0;     /* get the original length */
        if (off & 0x3fff) {
                /*
                 * if this isn't the first frag, we're missing the
@@ -480,7 +574,7 @@ ip_print(register const u_char *bp, register u_int length)
                if (off & 0x1fff)
                        (void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
                                      ipaddr_string(&ip->ip_dst));
-               (void)printf(" (frag %d:%d@%d%s)", ntohs(ip->ip_id), len,
+               (void)printf(" (frag %d:%u@%d%s)", ntohs(ip->ip_id), len,
                        (off & 0x1fff) * 8,
                        (off & IP_MF)? "+" : "");
        } else if (off & IP_DF)