#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>
#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
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 */
break;
case 0x14:
(void)printf("igmp pim");
- pim_print(bp, len);
+ igmp_pim_print(bp, len);
break;
case 0x1e:
print_mresp(bp, len);
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
(void)printf("truncated-ip - %d bytes missing!",
len - length);
len -= hlen;
+ len0 = len;
/*
* If this is fragment zero, hand it to the next higher
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);
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;
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)");
}
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
}
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
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)