diff options
Diffstat (limited to 'contrib/tcpdump/print-ip6.c')
-rw-r--r-- | contrib/tcpdump/print-ip6.c | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/contrib/tcpdump/print-ip6.c b/contrib/tcpdump/print-ip6.c index 71cd41c..04dee43 100644 --- a/contrib/tcpdump/print-ip6.c +++ b/contrib/tcpdump/print-ip6.c @@ -17,11 +17,13 @@ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * $FreeBSD$ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.16 2000/11/17 19:08:15 itojun Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.2.2.1 2000/01/11 06:58:25 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -36,16 +38,23 @@ static const char rcsid[] = #include <sys/socket.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> #include <stdio.h> +#ifdef __STDC__ #include <stdlib.h> +#endif #include <unistd.h> -#include <string.h> #include "interface.h" #include "addrtoname.h" -#include "ip6.h" +#include <netinet/ip6.h> /* * print an IP6 datagram. @@ -54,30 +63,29 @@ void ip6_print(register const u_char *bp, register int length) { register const struct ip6_hdr *ip6; - register int advance; + register int hlen; register int len; register const u_char *cp; int nh; - int fragmented = 0; u_int flow; ip6 = (const struct ip6_hdr *)bp; -#ifdef LBL_ALIGN +#ifdef TCPDUMP_ALIGN /* - * The IP6 header is not 16-byte aligned, so copy into abuf. + * The IP header is not word aligned, so copy into abuf. * This will never happen with BPF. It does happen raw packet * dumps from -r. */ - if ((u_long)ip6 & 15) { + if ((int)ip & (sizeof(long)-1)) { static u_char *abuf; - if (abuf == NULL) - abuf = malloc(snaplen); - memcpy(abuf, ip6, min(length, snaplen)); - snapend += abuf - (u_char *)ip6; + if (abuf == 0) + abuf = (u_char *)malloc(snaplen); + bcopy((char *)ip, (char *)abuf, min(length, snaplen)); + snapend += abuf - (u_char *)ip; packetp = abuf; - ip6 = (struct ip6_hdr *)abuf; + ip = (struct ip6_hdr *)abuf; } #endif if ((u_char *)(ip6 + 1) > snapend) { @@ -88,17 +96,17 @@ ip6_print(register const u_char *bp, register int length) (void)printf("truncated-ip6 %d", length); return; } - advance = sizeof(struct ip6_hdr); + hlen = sizeof(struct ip6_hdr); len = ntohs(ip6->ip6_plen); - if (length < len + advance) + if (length < len + hlen) (void)printf("truncated-ip6 - %d bytes missing!", - len + advance - length); + len + hlen - length); cp = (const u_char *)ip6; nh = ip6->ip6_nxt; while (cp < snapend) { - cp += advance; + cp += hlen; if (cp == (u_char *)(ip6 + 1) && nh != IPPROTO_TCP && nh != IPPROTO_UDP) { @@ -108,43 +116,42 @@ ip6_print(register const u_char *bp, register int length) switch (nh) { case IPPROTO_HOPOPTS: - advance = hbhopt_print(cp); + hlen = hbhopt_print(cp); nh = *cp; break; case IPPROTO_DSTOPTS: - advance = dstopt_print(cp); + hlen = dstopt_print(cp); nh = *cp; break; case IPPROTO_FRAGMENT: - advance = frag6_print(cp, (const u_char *)ip6); - if (snapend <= cp + advance) + hlen = frag6_print(cp, (const u_char *)ip6); + if (snapend <= cp + hlen) goto end; nh = *cp; - fragmented = 1; break; case IPPROTO_ROUTING: - advance = rt6_print(cp, (const u_char *)ip6); + hlen = rt6_print(cp, (const u_char *)ip6); nh = *cp; break; case IPPROTO_TCP: tcp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp), - (const u_char *)ip6, fragmented); + (const u_char *)ip6); goto end; case IPPROTO_UDP: udp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp), - (const u_char *)ip6, fragmented); + (const u_char *)ip6); goto end; case IPPROTO_ICMPV6: icmp6_print(cp, (const u_char *)ip6); goto end; case IPPROTO_AH: - advance = ah_print(cp, (const u_char *)ip6); + hlen = ah_print(cp, (const u_char *)ip6); nh = *cp; break; case IPPROTO_ESP: { int enh; - advance = esp_print(cp, (const u_char *)ip6, &enh); + cp += esp_print(cp, (const u_char *)ip6, &enh); if (enh < 0) goto end; nh = enh & 0xff; @@ -156,16 +163,12 @@ ip6_print(register const u_char *bp, register int length) case IPPROTO_IPCOMP: { int enh; - advance = ipcomp_print(cp, (const u_char *)ip6, &enh); + cp += ipcomp_print(cp, (const u_char *)ip6, &enh); if (enh < 0) goto end; nh = enh & 0xff; break; } - -#ifndef IPPROTO_PIM -#define IPPROTO_PIM 103 -#endif case IPPROTO_PIM: pim_print(cp, len); goto end; |