print-ip6.c (75118) | print-ip6.c (98527) |
---|---|
1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 4 unchanged lines hidden (view full) --- 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * | 1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 4 unchanged lines hidden (view full) --- 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * |
21 * $FreeBSD: head/contrib/tcpdump/print-ip6.c 75118 2001-04-03 07:50:46Z fenner $ | 21 * $FreeBSD: head/contrib/tcpdump/print-ip6.c 98527 2002-06-21 00:49:02Z fenner $ |
22 */ 23 24#ifndef lint 25static const char rcsid[] = | 22 */ 23 24#ifndef lint 25static const char rcsid[] = |
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.16 2000/11/17 19:08:15 itojun Exp $"; | 26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.21 2001/11/16 02:17:36 itojun Exp $"; |
27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#ifdef INET6 34 --- 13 unchanged lines hidden (view full) --- 48#include "addrtoname.h" 49 50#include "ip6.h" 51 52/* 53 * print an IP6 datagram. 54 */ 55void | 27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#ifdef INET6 34 --- 13 unchanged lines hidden (view full) --- 48#include "addrtoname.h" 49 50#include "ip6.h" 51 52/* 53 * print an IP6 datagram. 54 */ 55void |
56ip6_print(register const u_char *bp, register int length) | 56ip6_print(register const u_char *bp, register u_int length) |
57{ 58 register const struct ip6_hdr *ip6; 59 register int advance; | 57{ 58 register const struct ip6_hdr *ip6; 59 register int advance; |
60 register int len; | 60 register u_int len; |
61 register const u_char *cp; 62 int nh; 63 int fragmented = 0; 64 u_int flow; 65 66 ip6 = (const struct ip6_hdr *)bp; 67 68#ifdef LBL_ALIGN 69 /* 70 * The IP6 header is not 16-byte aligned, so copy into abuf. | 61 register const u_char *cp; 62 int nh; 63 int fragmented = 0; 64 u_int flow; 65 66 ip6 = (const struct ip6_hdr *)bp; 67 68#ifdef LBL_ALIGN 69 /* 70 * The IP6 header is not 16-byte aligned, so copy into abuf. |
71 * This will never happen with BPF. It does happen raw packet 72 * dumps from -r. | |
73 */ 74 if ((u_long)ip6 & 15) { 75 static u_char *abuf; 76 | 71 */ 72 if ((u_long)ip6 & 15) { 73 static u_char *abuf; 74 |
77 if (abuf == NULL) | 75 if (abuf == NULL) { |
78 abuf = malloc(snaplen); | 76 abuf = malloc(snaplen); |
77 if (abuf == NULL) 78 error("ip6_print: malloc"); 79 } |
|
79 memcpy(abuf, ip6, min(length, snaplen)); 80 snapend += abuf - (u_char *)ip6; 81 packetp = abuf; 82 ip6 = (struct ip6_hdr *)abuf; | 80 memcpy(abuf, ip6, min(length, snaplen)); 81 snapend += abuf - (u_char *)ip6; 82 packetp = abuf; 83 ip6 = (struct ip6_hdr *)abuf; |
84 bp = abuf; |
|
83 } 84#endif | 85 } 86#endif |
85 if ((u_char *)(ip6 + 1) > snapend) { 86 printf("[|ip6]"); 87 return; 88 } | 87 TCHECK(*ip6); |
89 if (length < sizeof (struct ip6_hdr)) { 90 (void)printf("truncated-ip6 %d", length); 91 return; 92 } 93 advance = sizeof(struct ip6_hdr); 94 95 len = ntohs(ip6->ip6_plen); 96 if (length < len + advance) 97 (void)printf("truncated-ip6 - %d bytes missing!", 98 len + advance - length); 99 100 cp = (const u_char *)ip6; 101 nh = ip6->ip6_nxt; 102 while (cp < snapend) { 103 cp += advance; 104 | 88 if (length < sizeof (struct ip6_hdr)) { 89 (void)printf("truncated-ip6 %d", length); 90 return; 91 } 92 advance = sizeof(struct ip6_hdr); 93 94 len = ntohs(ip6->ip6_plen); 95 if (length < len + advance) 96 (void)printf("truncated-ip6 - %d bytes missing!", 97 len + advance - length); 98 99 cp = (const u_char *)ip6; 100 nh = ip6->ip6_nxt; 101 while (cp < snapend) { 102 cp += advance; 103 |
105 if (cp == (u_char *)(ip6 + 1) | 104 if (cp == (const u_char *)(ip6 + 1) |
106 && nh != IPPROTO_TCP && nh != IPPROTO_UDP) { 107 (void)printf("%s > %s: ", ip6addr_string(&ip6->ip6_src), 108 ip6addr_string(&ip6->ip6_dst)); 109 } 110 111 switch (nh) { 112 case IPPROTO_HOPOPTS: 113 advance = hbhopt_print(cp); --- 26 unchanged lines hidden (view full) --- 140 icmp6_print(cp, (const u_char *)ip6); 141 goto end; 142 case IPPROTO_AH: 143 advance = ah_print(cp, (const u_char *)ip6); 144 nh = *cp; 145 break; 146 case IPPROTO_ESP: 147 { | 105 && nh != IPPROTO_TCP && nh != IPPROTO_UDP) { 106 (void)printf("%s > %s: ", ip6addr_string(&ip6->ip6_src), 107 ip6addr_string(&ip6->ip6_dst)); 108 } 109 110 switch (nh) { 111 case IPPROTO_HOPOPTS: 112 advance = hbhopt_print(cp); --- 26 unchanged lines hidden (view full) --- 139 icmp6_print(cp, (const u_char *)ip6); 140 goto end; 141 case IPPROTO_AH: 142 advance = ah_print(cp, (const u_char *)ip6); 143 nh = *cp; 144 break; 145 case IPPROTO_ESP: 146 { |
148 int enh; 149 advance = esp_print(cp, (const u_char *)ip6, &enh); | 147 int enh, padlen; 148 advance = esp_print(cp, (const u_char *)ip6, &enh, &padlen); |
150 if (enh < 0) 151 goto end; 152 nh = enh & 0xff; | 149 if (enh < 0) 150 goto end; 151 nh = enh & 0xff; |
152 len -= padlen; |
|
153 break; 154 } 155#ifndef IPPROTO_IPCOMP 156#define IPPROTO_IPCOMP 108 157#endif 158 case IPPROTO_IPCOMP: 159 { 160 int enh; --- 57 unchanged lines hidden (view full) --- 218 219 if (vflag) { 220 printf(" ("); 221 (void)printf("len %d", len); 222 if (ip6->ip6_hlim > 1) 223 (void)printf(", hlim %d", (int)ip6->ip6_hlim); 224 printf(")"); 225 } | 153 break; 154 } 155#ifndef IPPROTO_IPCOMP 156#define IPPROTO_IPCOMP 108 157#endif 158 case IPPROTO_IPCOMP: 159 { 160 int enh; --- 57 unchanged lines hidden (view full) --- 218 219 if (vflag) { 220 printf(" ("); 221 (void)printf("len %d", len); 222 if (ip6->ip6_hlim > 1) 223 (void)printf(", hlim %d", (int)ip6->ip6_hlim); 224 printf(")"); 225 } |
226 return; 227trunc: 228 (void)printf("[|ip6]"); |
|
226} 227 228#endif /* INET6 */ | 229} 230 231#endif /* INET6 */ |