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 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning 11 * features or use of this software display the following acknowledgement: 12 * ``This product includes software developed by the University of California, 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 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning 11 * features or use of this software display the following acknowledgement: 12 * ``This product includes software developed by the University of California, 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 57278 2000-02-17 03:30:04Z fenner $
| 21 * $FreeBSD: head/contrib/tcpdump/print-ip6.c 75118 2001-04-03 07:50:46Z 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.2.2.1 2000/01/11 06:58:25 fenner Exp $";
| 26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.16 2000/11/17 19:08:15 itojun Exp $";
|
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> 39 40#include <netinet/in.h>
| 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> 39 40#include <netinet/in.h>
|
41#include <netinet/in_systm.h> 42#include <netinet/ip.h> 43#include <netinet/ip_var.h> 44#include <netinet/udp.h> 45#include <netinet/udp_var.h> 46#include <netinet/tcp.h>
| |
47 48#include <stdio.h>
| 41 42#include <stdio.h>
|
49#ifdef __STDC__
| |
50#include <stdlib.h>
| 43#include <stdlib.h>
|
51#endif
| |
52#include <unistd.h>
| 44#include <unistd.h>
|
| 45#include <string.h>
|
53 54#include "interface.h" 55#include "addrtoname.h" 56
| 46 47#include "interface.h" 48#include "addrtoname.h" 49
|
57#include <netinet/ip6.h>
| 50#include "ip6.h"
|
58 59/* 60 * print an IP6 datagram. 61 */ 62void 63ip6_print(register const u_char *bp, register int length) 64{ 65 register const struct ip6_hdr *ip6;
| 51 52/* 53 * print an IP6 datagram. 54 */ 55void 56ip6_print(register const u_char *bp, register int length) 57{ 58 register const struct ip6_hdr *ip6;
|
66 register int hlen;
| 59 register int advance;
|
67 register int len; 68 register const u_char *cp; 69 int nh;
| 60 register int len; 61 register const u_char *cp; 62 int nh;
|
| 63 int fragmented = 0;
|
70 u_int flow; 71 72 ip6 = (const struct ip6_hdr *)bp; 73
| 64 u_int flow; 65 66 ip6 = (const struct ip6_hdr *)bp; 67
|
74#ifdef TCPDUMP_ALIGN
| 68#ifdef LBL_ALIGN
|
75 /*
| 69 /*
|
76 * The IP header is not word aligned, so copy into abuf.
| 70 * The IP6 header is not 16-byte aligned, so copy into abuf.
|
77 * This will never happen with BPF. It does happen raw packet 78 * dumps from -r. 79 */
| 71 * This will never happen with BPF. It does happen raw packet 72 * dumps from -r. 73 */
|
80 if ((int)ip & (sizeof(long)-1)) {
| 74 if ((u_long)ip6 & 15) {
|
81 static u_char *abuf; 82
| 75 static u_char *abuf; 76
|
83 if (abuf == 0) 84 abuf = (u_char *)malloc(snaplen); 85 bcopy((char *)ip, (char *)abuf, min(length, snaplen)); 86 snapend += abuf - (u_char *)ip;
| 77 if (abuf == NULL) 78 abuf = malloc(snaplen); 79 memcpy(abuf, ip6, min(length, snaplen)); 80 snapend += abuf - (u_char *)ip6;
|
87 packetp = abuf;
| 81 packetp = abuf;
|
88 ip = (struct ip6_hdr *)abuf;
| 82 ip6 = (struct ip6_hdr *)abuf;
|
89 } 90#endif 91 if ((u_char *)(ip6 + 1) > snapend) { 92 printf("[|ip6]"); 93 return; 94 } 95 if (length < sizeof (struct ip6_hdr)) { 96 (void)printf("truncated-ip6 %d", length); 97 return; 98 }
| 83 } 84#endif 85 if ((u_char *)(ip6 + 1) > snapend) { 86 printf("[|ip6]"); 87 return; 88 } 89 if (length < sizeof (struct ip6_hdr)) { 90 (void)printf("truncated-ip6 %d", length); 91 return; 92 }
|
99 hlen = sizeof(struct ip6_hdr);
| 93 advance = sizeof(struct ip6_hdr);
|
100 101 len = ntohs(ip6->ip6_plen);
| 94 95 len = ntohs(ip6->ip6_plen);
|
102 if (length < len + hlen)
| 96 if (length < len + advance)
|
103 (void)printf("truncated-ip6 - %d bytes missing!",
| 97 (void)printf("truncated-ip6 - %d bytes missing!",
|
104 len + hlen - length);
| 98 len + advance - length);
|
105 106 cp = (const u_char *)ip6; 107 nh = ip6->ip6_nxt; 108 while (cp < snapend) {
| 99 100 cp = (const u_char *)ip6; 101 nh = ip6->ip6_nxt; 102 while (cp < snapend) {
|
109 cp += hlen;
| 103 cp += advance;
|
110 111 if (cp == (u_char *)(ip6 + 1) 112 && nh != IPPROTO_TCP && nh != IPPROTO_UDP) { 113 (void)printf("%s > %s: ", ip6addr_string(&ip6->ip6_src), 114 ip6addr_string(&ip6->ip6_dst)); 115 } 116 117 switch (nh) { 118 case IPPROTO_HOPOPTS:
| 104 105 if (cp == (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:
|
119 hlen = hbhopt_print(cp);
| 113 advance = hbhopt_print(cp);
|
120 nh = *cp; 121 break; 122 case IPPROTO_DSTOPTS:
| 114 nh = *cp; 115 break; 116 case IPPROTO_DSTOPTS:
|
123 hlen = dstopt_print(cp);
| 117 advance = dstopt_print(cp);
|
124 nh = *cp; 125 break; 126 case IPPROTO_FRAGMENT:
| 118 nh = *cp; 119 break; 120 case IPPROTO_FRAGMENT:
|
127 hlen = frag6_print(cp, (const u_char *)ip6); 128 if (snapend <= cp + hlen)
| 121 advance = frag6_print(cp, (const u_char *)ip6); 122 if (snapend <= cp + advance)
|
129 goto end; 130 nh = *cp;
| 123 goto end; 124 nh = *cp;
|
| 125 fragmented = 1;
|
131 break; 132 case IPPROTO_ROUTING:
| 126 break; 127 case IPPROTO_ROUTING:
|
133 hlen = rt6_print(cp, (const u_char *)ip6);
| 128 advance = rt6_print(cp, (const u_char *)ip6);
|
134 nh = *cp; 135 break; 136 case IPPROTO_TCP: 137 tcp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp),
| 129 nh = *cp; 130 break; 131 case IPPROTO_TCP: 132 tcp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp),
|
138 (const u_char *)ip6);
| 133 (const u_char *)ip6, fragmented);
|
139 goto end; 140 case IPPROTO_UDP: 141 udp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp),
| 134 goto end; 135 case IPPROTO_UDP: 136 udp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp),
|
142 (const u_char *)ip6);
| 137 (const u_char *)ip6, fragmented);
|
143 goto end; 144 case IPPROTO_ICMPV6: 145 icmp6_print(cp, (const u_char *)ip6); 146 goto end; 147 case IPPROTO_AH:
| 138 goto end; 139 case IPPROTO_ICMPV6: 140 icmp6_print(cp, (const u_char *)ip6); 141 goto end; 142 case IPPROTO_AH:
|
148 hlen = ah_print(cp, (const u_char *)ip6);
| 143 advance = ah_print(cp, (const u_char *)ip6);
|
149 nh = *cp; 150 break; 151 case IPPROTO_ESP: 152 { 153 int enh;
| 144 nh = *cp; 145 break; 146 case IPPROTO_ESP: 147 { 148 int enh;
|
154 cp += esp_print(cp, (const u_char *)ip6, &enh);
| 149 advance = esp_print(cp, (const u_char *)ip6, &enh);
|
155 if (enh < 0) 156 goto end; 157 nh = enh & 0xff; 158 break; 159 } 160#ifndef IPPROTO_IPCOMP 161#define IPPROTO_IPCOMP 108 162#endif 163 case IPPROTO_IPCOMP: 164 { 165 int enh;
| 150 if (enh < 0) 151 goto end; 152 nh = enh & 0xff; 153 break; 154 } 155#ifndef IPPROTO_IPCOMP 156#define IPPROTO_IPCOMP 108 157#endif 158 case IPPROTO_IPCOMP: 159 { 160 int enh;
|
166 cp += ipcomp_print(cp, (const u_char *)ip6, &enh);
| 161 advance = ipcomp_print(cp, (const u_char *)ip6, &enh);
|
167 if (enh < 0) 168 goto end; 169 nh = enh & 0xff; 170 break; 171 }
| 162 if (enh < 0) 163 goto end; 164 nh = enh & 0xff; 165 break; 166 }
|
| 167 168#ifndef IPPROTO_PIM 169#define IPPROTO_PIM 103 170#endif
|
172 case IPPROTO_PIM: 173 pim_print(cp, len); 174 goto end; 175#ifndef IPPROTO_OSPF 176#define IPPROTO_OSPF 89 177#endif 178 case IPPROTO_OSPF: 179 ospf6_print(cp, len); 180 goto end; 181 case IPPROTO_IPV6: 182 ip6_print(cp, len); 183 goto end; 184#ifndef IPPROTO_IPV4 185#define IPPROTO_IPV4 4 186#endif 187 case IPPROTO_IPV4: 188 ip_print(cp, len); 189 goto end; 190 case IPPROTO_NONE: 191 (void)printf("no next header"); 192 goto end; 193 194 default: 195 (void)printf("ip-proto-%d %d", ip6->ip6_nxt, len); 196 goto end; 197 } 198 } 199 200 end: 201 202 flow = ntohl(ip6->ip6_flow); 203#if 0 204 /* rfc1883 */ 205 if (flow & 0x0f000000) 206 (void)printf(" [pri 0x%x]", (flow & 0x0f000000) >> 24); 207 if (flow & 0x00ffffff) 208 (void)printf(" [flowlabel 0x%x]", flow & 0x00ffffff); 209#else 210 /* RFC 2460 */ 211 if (flow & 0x0ff00000) 212 (void)printf(" [class 0x%x]", (flow & 0x0ff00000) >> 20); 213 if (flow & 0x000fffff) 214 (void)printf(" [flowlabel 0x%x]", flow & 0x000fffff); 215#endif 216 217 if (ip6->ip6_hlim <= 1) 218 (void)printf(" [hlim %d]", (int)ip6->ip6_hlim); 219 220 if (vflag) { 221 printf(" ("); 222 (void)printf("len %d", len); 223 if (ip6->ip6_hlim > 1) 224 (void)printf(", hlim %d", (int)ip6->ip6_hlim); 225 printf(")"); 226 } 227} 228 229#endif /* INET6 */
| 171 case IPPROTO_PIM: 172 pim_print(cp, len); 173 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; 180 case IPPROTO_IPV6: 181 ip6_print(cp, len); 182 goto end; 183#ifndef IPPROTO_IPV4 184#define IPPROTO_IPV4 4 185#endif 186 case IPPROTO_IPV4: 187 ip_print(cp, len); 188 goto end; 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: 200 201 flow = ntohl(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) 217 (void)printf(" [hlim %d]", (int)ip6->ip6_hlim); 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} 227 228#endif /* INET6 */
|