print-ip6.c (98527) | print-ip6.c (127675) |
---|---|
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 98527 2002-06-21 00:49:02Z fenner $ | 21 * $FreeBSD: head/contrib/tcpdump/print-ip6.c 127675 2004-03-31 14:57:24Z bms $ |
22 */ 23 24#ifndef lint | 22 */ 23 24#ifndef lint |
25static const char rcsid[] = 26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.21 2001/11/16 02:17:36 itojun Exp $"; | 25static const char rcsid[] _U_ = 26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.32.2.8 2003/11/24 20:31:22 guy Exp $"; |
27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#ifdef INET6 34 | 27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#ifdef INET6 34 |
35#include <sys/param.h> 36#include <sys/time.h> 37#include <sys/types.h> 38#include <sys/socket.h> | 35#include <tcpdump-stdinc.h> |
39 | 36 |
40#include <netinet/in.h> 41 | |
42#include <stdio.h> 43#include <stdlib.h> | 37#include <stdio.h> 38#include <stdlib.h> |
44#include <unistd.h> | |
45#include <string.h> 46 47#include "interface.h" 48#include "addrtoname.h" | 39#include <string.h> 40 41#include "interface.h" 42#include "addrtoname.h" |
43#include "extract.h" |
|
49 50#include "ip6.h" | 44 45#include "ip6.h" |
46#include "ipproto.h" |
|
51 52/* 53 * print an IP6 datagram. 54 */ 55void 56ip6_print(register const u_char *bp, register u_int length) 57{ 58 register const struct ip6_hdr *ip6; 59 register int advance; | 47 48/* 49 * print an IP6 datagram. 50 */ 51void 52ip6_print(register const u_char *bp, register u_int length) 53{ 54 register const struct ip6_hdr *ip6; 55 register int advance; |
60 register u_int len; | 56 u_int len; 57 const u_char *ipend; |
61 register const u_char *cp; | 58 register const u_char *cp; |
59 register u_int payload_len; |
|
62 int nh; 63 int fragmented = 0; 64 u_int flow; | 60 int nh; 61 int fragmented = 0; 62 u_int flow; |
65 | 63 |
66 ip6 = (const struct ip6_hdr *)bp; 67 | 64 ip6 = (const struct ip6_hdr *)bp; 65 |
68#ifdef LBL_ALIGN 69 /* 70 * The IP6 header is not 16-byte aligned, so copy into abuf. 71 */ 72 if ((u_long)ip6 & 15) { 73 static u_char *abuf; 74 75 if (abuf == NULL) { 76 abuf = malloc(snaplen); 77 if (abuf == NULL) 78 error("ip6_print: malloc"); 79 } 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; 85 } 86#endif | |
87 TCHECK(*ip6); 88 if (length < sizeof (struct ip6_hdr)) { 89 (void)printf("truncated-ip6 %d", length); 90 return; 91 } | 66 TCHECK(*ip6); 67 if (length < sizeof (struct ip6_hdr)) { 68 (void)printf("truncated-ip6 %d", length); 69 return; 70 } |
92 advance = sizeof(struct ip6_hdr); | |
93 | 71 |
94 len = ntohs(ip6->ip6_plen); 95 if (length < len + advance) | 72 payload_len = EXTRACT_16BITS(&ip6->ip6_plen); 73 len = payload_len + sizeof(struct ip6_hdr); 74 if (length < len) |
96 (void)printf("truncated-ip6 - %d bytes missing!", | 75 (void)printf("truncated-ip6 - %d bytes missing!", |
97 len + advance - length); | 76 len - length); |
98 | 77 |
78 /* 79 * Cut off the snapshot length to the end of the IP payload. 80 */ 81 ipend = bp + len; 82 if (ipend < snapend) 83 snapend = ipend; 84 |
|
99 cp = (const u_char *)ip6; | 85 cp = (const u_char *)ip6; |
86 advance = sizeof(struct ip6_hdr); |
|
100 nh = ip6->ip6_nxt; | 87 nh = ip6->ip6_nxt; |
101 while (cp < snapend) { | 88 while (cp < snapend && advance > 0) { |
102 cp += advance; | 89 cp += advance; |
90 len -= advance; |
|
103 | 91 |
104 if (cp == (const u_char *)(ip6 + 1) 105 && nh != IPPROTO_TCP && nh != IPPROTO_UDP) { | 92 if (cp == (const u_char *)(ip6 + 1) && 93 nh != IPPROTO_TCP && nh != IPPROTO_UDP && 94 nh != IPPROTO_SCTP) { |
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); 113 nh = *cp; --- 4 unchanged lines hidden (view full) --- 118 break; 119 case IPPROTO_FRAGMENT: 120 advance = frag6_print(cp, (const u_char *)ip6); 121 if (snapend <= cp + advance) 122 goto end; 123 nh = *cp; 124 fragmented = 1; 125 break; | 95 (void)printf("%s > %s: ", ip6addr_string(&ip6->ip6_src), 96 ip6addr_string(&ip6->ip6_dst)); 97 } 98 99 switch (nh) { 100 case IPPROTO_HOPOPTS: 101 advance = hbhopt_print(cp); 102 nh = *cp; --- 4 unchanged lines hidden (view full) --- 107 break; 108 case IPPROTO_FRAGMENT: 109 advance = frag6_print(cp, (const u_char *)ip6); 110 if (snapend <= cp + advance) 111 goto end; 112 nh = *cp; 113 fragmented = 1; 114 break; |
115 116 case IPPROTO_MOBILITY_OLD: 117 case IPPROTO_MOBILITY: 118 /* 119 * XXX - we don't use "advance"; the current 120 * "Mobility Support in IPv6" draft 121 * (draft-ietf-mobileip-ipv6-24) says that 122 * the next header field in a mobility header 123 * should be IPPROTO_NONE, but speaks of 124 * the possiblity of a future extension in 125 * which payload can be piggybacked atop a 126 * mobility header. 127 */ 128 advance = mobility_print(cp, (const u_char *)ip6); 129 nh = *cp; 130 goto end; |
|
126 case IPPROTO_ROUTING: 127 advance = rt6_print(cp, (const u_char *)ip6); 128 nh = *cp; 129 break; | 131 case IPPROTO_ROUTING: 132 advance = rt6_print(cp, (const u_char *)ip6); 133 nh = *cp; 134 break; |
135 case IPPROTO_SCTP: 136 sctp_print(cp, (const u_char *)ip6, len); 137 goto end; |
|
130 case IPPROTO_TCP: | 138 case IPPROTO_TCP: |
131 tcp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp), 132 (const u_char *)ip6, fragmented); | 139 tcp_print(cp, len, (const u_char *)ip6, fragmented); |
133 goto end; 134 case IPPROTO_UDP: | 140 goto end; 141 case IPPROTO_UDP: |
135 udp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp), 136 (const u_char *)ip6, fragmented); | 142 udp_print(cp, len, (const u_char *)ip6, fragmented); |
137 goto end; 138 case IPPROTO_ICMPV6: | 143 goto end; 144 case IPPROTO_ICMPV6: |
139 icmp6_print(cp, (const u_char *)ip6); | 145 icmp6_print(cp, len, (const u_char *)ip6, fragmented); |
140 goto end; 141 case IPPROTO_AH: | 146 goto end; 147 case IPPROTO_AH: |
142 advance = ah_print(cp, (const u_char *)ip6); | 148 advance = ah_print(cp); |
143 nh = *cp; 144 break; 145 case IPPROTO_ESP: 146 { 147 int enh, padlen; 148 advance = esp_print(cp, (const u_char *)ip6, &enh, &padlen); | 149 nh = *cp; 150 break; 151 case IPPROTO_ESP: 152 { 153 int enh, padlen; 154 advance = esp_print(cp, (const u_char *)ip6, &enh, &padlen); |
149 if (enh < 0) 150 goto end; | |
151 nh = enh & 0xff; 152 len -= padlen; 153 break; 154 } | 155 nh = enh & 0xff; 156 len -= padlen; 157 break; 158 } |
155#ifndef IPPROTO_IPCOMP 156#define IPPROTO_IPCOMP 108 157#endif | |
158 case IPPROTO_IPCOMP: 159 { 160 int enh; | 159 case IPPROTO_IPCOMP: 160 { 161 int enh; |
161 advance = ipcomp_print(cp, (const u_char *)ip6, &enh); 162 if (enh < 0) 163 goto end; | 162 advance = ipcomp_print(cp, &enh); |
164 nh = enh & 0xff; 165 break; 166 } 167 | 163 nh = enh & 0xff; 164 break; 165 } 166 |
168#ifndef IPPROTO_PIM 169#define IPPROTO_PIM 103 170#endif | |
171 case IPPROTO_PIM: 172 pim_print(cp, len); 173 goto end; | 167 case IPPROTO_PIM: 168 pim_print(cp, len); 169 goto end; |
174#ifndef IPPROTO_OSPF 175#define IPPROTO_OSPF 89 176#endif | |
177 case IPPROTO_OSPF: 178 ospf6_print(cp, len); 179 goto end; | 170 case IPPROTO_OSPF: 171 ospf6_print(cp, len); 172 goto end; |
173 |
|
180 case IPPROTO_IPV6: 181 ip6_print(cp, len); 182 goto end; | 174 case IPPROTO_IPV6: 175 ip6_print(cp, len); 176 goto end; |
183#ifndef IPPROTO_IPV4 184#define IPPROTO_IPV4 4 185#endif | 177 |
186 case IPPROTO_IPV4: 187 ip_print(cp, len); 188 goto end; | 178 case IPPROTO_IPV4: 179 ip_print(cp, len); 180 goto end; |
181 |
|
189 case IPPROTO_NONE: 190 (void)printf("no next header"); 191 goto end; 192 193 default: 194 (void)printf("ip-proto-%d %d", ip6->ip6_nxt, len); 195 goto end; 196 } 197 } 198 199 end: | 182 case IPPROTO_NONE: 183 (void)printf("no next header"); 184 goto end; 185 186 default: 187 (void)printf("ip-proto-%d %d", ip6->ip6_nxt, len); 188 goto end; 189 } 190 } 191 192 end: |
200 201 flow = ntohl(ip6->ip6_flow); | 193 194 flow = EXTRACT_32BITS(&ip6->ip6_flow); |
202#if 0 203 /* rfc1883 */ 204 if (flow & 0x0f000000) 205 (void)printf(" [pri 0x%x]", (flow & 0x0f000000) >> 24); 206 if (flow & 0x00ffffff) 207 (void)printf(" [flowlabel 0x%x]", flow & 0x00ffffff); 208#else 209 /* RFC 2460 */ 210 if (flow & 0x0ff00000) 211 (void)printf(" [class 0x%x]", (flow & 0x0ff00000) >> 20); 212 if (flow & 0x000fffff) 213 (void)printf(" [flowlabel 0x%x]", flow & 0x000fffff); 214#endif 215 216 if (ip6->ip6_hlim <= 1) | 195#if 0 196 /* rfc1883 */ 197 if (flow & 0x0f000000) 198 (void)printf(" [pri 0x%x]", (flow & 0x0f000000) >> 24); 199 if (flow & 0x00ffffff) 200 (void)printf(" [flowlabel 0x%x]", flow & 0x00ffffff); 201#else 202 /* RFC 2460 */ 203 if (flow & 0x0ff00000) 204 (void)printf(" [class 0x%x]", (flow & 0x0ff00000) >> 20); 205 if (flow & 0x000fffff) 206 (void)printf(" [flowlabel 0x%x]", flow & 0x000fffff); 207#endif 208 209 if (ip6->ip6_hlim <= 1) |
217 (void)printf(" [hlim %d]", (int)ip6->ip6_hlim); | 210 (void)printf(" [hlim %u]", ip6->ip6_hlim); |
218 219 if (vflag) { 220 printf(" ("); | 211 212 if (vflag) { 213 printf(" ("); |
221 (void)printf("len %d", len); | 214 (void)printf("len %u", payload_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]"); 229} 230 231#endif /* INET6 */ | 215 if (ip6->ip6_hlim > 1) 216 (void)printf(", hlim %d", (int)ip6->ip6_hlim); 217 printf(")"); 218 } 219 return; 220trunc: 221 (void)printf("[|ip6]"); 222} 223 224#endif /* INET6 */ |