print-icmp.c (56896) | print-icmp.c (66644) |
---|---|
1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996 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, 1993, 1994, 1995, 1996 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-icmp.c 56896 2000-01-30 01:05:24Z fenner $ | 21 * $FreeBSD: head/contrib/tcpdump/print-icmp.c 66644 2000-10-05 02:49:49Z kris $ |
22 */ 23 24#ifndef lint 25static const char rcsid[] = 26 "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.43 1999/11/22 04:28:21 fenner Exp $ (LBL)"; 27#endif 28 29#ifdef HAVE_CONFIG_H --- 142 unchanged lines hidden (view full) --- 172{ 173 register char *cp; 174 register const struct icmp *dp; 175 register const struct ip *ip; 176 register const char *str, *fmt; 177 register const struct ip *oip; 178 register const struct udphdr *ouh; 179 register u_int hlen, dport, mtu; | 22 */ 23 24#ifndef lint 25static const char rcsid[] = 26 "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.43 1999/11/22 04:28:21 fenner Exp $ (LBL)"; 27#endif 28 29#ifdef HAVE_CONFIG_H --- 142 unchanged lines hidden (view full) --- 172{ 173 register char *cp; 174 register const struct icmp *dp; 175 register const struct ip *ip; 176 register const char *str, *fmt; 177 register const struct ip *oip; 178 register const struct udphdr *ouh; 179 register u_int hlen, dport, mtu; |
180 char buf[256]; | 180 char buf[MAXHOSTNAMELEN + 100]; |
181 182 dp = (struct icmp *)bp; 183 ip = (struct ip *)bp2; 184 str = buf; 185 186#if 0 187 (void)printf("%s > %s: ", 188 ipaddr_string(&ip->ip_src), --- 4 unchanged lines hidden (view full) --- 193 switch (dp->icmp_type) { 194 195 case ICMP_UNREACH: 196 TCHECK(dp->icmp_ip.ip_dst); 197 switch (dp->icmp_code) { 198 199 case ICMP_UNREACH_PROTOCOL: 200 TCHECK(dp->icmp_ip.ip_p); | 181 182 dp = (struct icmp *)bp; 183 ip = (struct ip *)bp2; 184 str = buf; 185 186#if 0 187 (void)printf("%s > %s: ", 188 ipaddr_string(&ip->ip_src), --- 4 unchanged lines hidden (view full) --- 193 switch (dp->icmp_type) { 194 195 case ICMP_UNREACH: 196 TCHECK(dp->icmp_ip.ip_dst); 197 switch (dp->icmp_code) { 198 199 case ICMP_UNREACH_PROTOCOL: 200 TCHECK(dp->icmp_ip.ip_p); |
201 (void)sprintf(buf, "%s protocol %d unreachable", | 201 (void)snprintf(buf, sizeof(buf), "%s protocol %d unreachable", |
202 ipaddr_string(&dp->icmp_ip.ip_dst), 203 dp->icmp_ip.ip_p); 204 break; 205 206 case ICMP_UNREACH_PORT: 207 TCHECK(dp->icmp_ip.ip_p); 208 oip = &dp->icmp_ip; 209 hlen = oip->ip_hl * 4; 210 ouh = (struct udphdr *)(((u_char *)oip) + hlen); 211 dport = ntohs(ouh->uh_dport); 212 switch (oip->ip_p) { 213 214 case IPPROTO_TCP: | 202 ipaddr_string(&dp->icmp_ip.ip_dst), 203 dp->icmp_ip.ip_p); 204 break; 205 206 case ICMP_UNREACH_PORT: 207 TCHECK(dp->icmp_ip.ip_p); 208 oip = &dp->icmp_ip; 209 hlen = oip->ip_hl * 4; 210 ouh = (struct udphdr *)(((u_char *)oip) + hlen); 211 dport = ntohs(ouh->uh_dport); 212 switch (oip->ip_p) { 213 214 case IPPROTO_TCP: |
215 (void)sprintf(buf, | 215 (void)snprintf(buf, sizeof(buf), |
216 "%s tcp port %s unreachable", 217 ipaddr_string(&oip->ip_dst), 218 tcpport_string(dport)); 219 break; 220 221 case IPPROTO_UDP: | 216 "%s tcp port %s unreachable", 217 ipaddr_string(&oip->ip_dst), 218 tcpport_string(dport)); 219 break; 220 221 case IPPROTO_UDP: |
222 (void)sprintf(buf, | 222 (void)snprintf(buf, sizeof(buf), |
223 "%s udp port %s unreachable", 224 ipaddr_string(&oip->ip_dst), 225 udpport_string(dport)); 226 break; 227 228 default: | 223 "%s udp port %s unreachable", 224 ipaddr_string(&oip->ip_dst), 225 udpport_string(dport)); 226 break; 227 228 default: |
229 (void)sprintf(buf, | 229 (void)snprintf(buf, sizeof(buf), |
230 "%s protocol %d port %d unreachable", 231 ipaddr_string(&oip->ip_dst), 232 oip->ip_p, dport); 233 break; 234 } 235 break; 236 237 case ICMP_UNREACH_NEEDFRAG: 238 { 239 register const struct mtu_discovery *mp; 240 241 mp = (struct mtu_discovery *)&dp->icmp_void; 242 mtu = EXTRACT_16BITS(&mp->nexthopmtu); 243 if (mtu) | 230 "%s protocol %d port %d unreachable", 231 ipaddr_string(&oip->ip_dst), 232 oip->ip_p, dport); 233 break; 234 } 235 break; 236 237 case ICMP_UNREACH_NEEDFRAG: 238 { 239 register const struct mtu_discovery *mp; 240 241 mp = (struct mtu_discovery *)&dp->icmp_void; 242 mtu = EXTRACT_16BITS(&mp->nexthopmtu); 243 if (mtu) |
244 (void)sprintf(buf, | 244 (void)snprintf(buf, sizeof(buf), |
245 "%s unreachable - need to frag (mtu %d)", 246 ipaddr_string(&dp->icmp_ip.ip_dst), mtu); 247 else | 245 "%s unreachable - need to frag (mtu %d)", 246 ipaddr_string(&dp->icmp_ip.ip_dst), mtu); 247 else |
248 (void)sprintf(buf, | 248 (void)snprintf(buf, sizeof(buf), |
249 "%s unreachable - need to frag", 250 ipaddr_string(&dp->icmp_ip.ip_dst)); 251 } 252 break; 253 254 default: 255 fmt = tok2str(unreach2str, "#%d %%s unreachable", 256 dp->icmp_code); | 249 "%s unreachable - need to frag", 250 ipaddr_string(&dp->icmp_ip.ip_dst)); 251 } 252 break; 253 254 default: 255 fmt = tok2str(unreach2str, "#%d %%s unreachable", 256 dp->icmp_code); |
257 (void)sprintf(buf, fmt, | 257 (void)snprintf(buf, sizeof(buf), fmt, |
258 ipaddr_string(&dp->icmp_ip.ip_dst)); 259 break; 260 } 261 break; 262 263 case ICMP_REDIRECT: 264 TCHECK(dp->icmp_ip.ip_dst); 265 fmt = tok2str(type2str, "redirect-#%d %%s to net %%s", 266 dp->icmp_code); | 258 ipaddr_string(&dp->icmp_ip.ip_dst)); 259 break; 260 } 261 break; 262 263 case ICMP_REDIRECT: 264 TCHECK(dp->icmp_ip.ip_dst); 265 fmt = tok2str(type2str, "redirect-#%d %%s to net %%s", 266 dp->icmp_code); |
267 (void)sprintf(buf, fmt, | 267 (void)snprintf(buf, sizeof(buf), fmt, |
268 ipaddr_string(&dp->icmp_ip.ip_dst), 269 ipaddr_string(&dp->icmp_gwaddr)); 270 break; 271 272 case ICMP_ROUTERADVERT: 273 { 274 register const struct ih_rdiscovery *ihp; 275 register const struct id_rdiscovery *idp; 276 u_int lifetime, num, size; 277 278 (void)strcpy(buf, "router advertisement"); 279 cp = buf + strlen(buf); 280 281 ihp = (struct ih_rdiscovery *)&dp->icmp_void; 282 TCHECK(*ihp); 283 (void)strcpy(cp, " lifetime "); 284 cp = buf + strlen(buf); 285 lifetime = EXTRACT_16BITS(&ihp->ird_lifetime); 286 if (lifetime < 60) | 268 ipaddr_string(&dp->icmp_ip.ip_dst), 269 ipaddr_string(&dp->icmp_gwaddr)); 270 break; 271 272 case ICMP_ROUTERADVERT: 273 { 274 register const struct ih_rdiscovery *ihp; 275 register const struct id_rdiscovery *idp; 276 u_int lifetime, num, size; 277 278 (void)strcpy(buf, "router advertisement"); 279 cp = buf + strlen(buf); 280 281 ihp = (struct ih_rdiscovery *)&dp->icmp_void; 282 TCHECK(*ihp); 283 (void)strcpy(cp, " lifetime "); 284 cp = buf + strlen(buf); 285 lifetime = EXTRACT_16BITS(&ihp->ird_lifetime); 286 if (lifetime < 60) |
287 (void)sprintf(cp, "%u", lifetime); | 287 (void)snprintf(cp, sizeof(buf) - strlen(buf), "%u", lifetime); |
288 else if (lifetime < 60 * 60) | 288 else if (lifetime < 60 * 60) |
289 (void)sprintf(cp, "%u:%02u", | 289 (void)snprintf(cp, sizeof(buf) - strlen(buf), "%u:%02u", |
290 lifetime / 60, lifetime % 60); 291 else | 290 lifetime / 60, lifetime % 60); 291 else |
292 (void)sprintf(cp, "%u:%02u:%02u", | 292 (void)snprintf(cp, sizeof(buf) - strlen(buf), "%u:%02u:%02u", |
293 lifetime / 3600, 294 (lifetime % 3600) / 60, 295 lifetime % 60); 296 cp = buf + strlen(buf); 297 298 num = ihp->ird_addrnum; | 293 lifetime / 3600, 294 (lifetime % 3600) / 60, 295 lifetime % 60); 296 cp = buf + strlen(buf); 297 298 num = ihp->ird_addrnum; |
299 (void)sprintf(cp, " %d:", num); | 299 (void)snprintf(cp, sizeof(buf) - strlen(buf), " %d:", num); |
300 cp = buf + strlen(buf); 301 302 size = ihp->ird_addrsiz; 303 if (size != 2) { | 300 cp = buf + strlen(buf); 301 302 size = ihp->ird_addrsiz; 303 if (size != 2) { |
304 (void)sprintf(cp, " [size %d]", size); | 304 (void)snprintf(cp, sizeof(buf) - strlen(buf), " [size %d]", size); |
305 break; 306 } 307 idp = (struct id_rdiscovery *)&dp->icmp_data; 308 while (num-- > 0) { 309 TCHECK(*idp); | 305 break; 306 } 307 idp = (struct id_rdiscovery *)&dp->icmp_data; 308 while (num-- > 0) { 309 TCHECK(*idp); |
310 (void)sprintf(cp, " {%s %u}", | 310 (void)snprintf(cp, sizeof(buf) - strlen(buf), " {%s %u}", |
311 ipaddr_string(&idp->ird_addr), 312 EXTRACT_32BITS(&idp->ird_pref)); 313 cp = buf + strlen(buf); 314 } 315 } 316 break; 317 318 case ICMP_TIMXCEED: --- 4 unchanged lines hidden (view full) --- 323 str = "time exceeded in-transit"; 324 break; 325 326 case ICMP_TIMXCEED_REASS: 327 str = "ip reassembly time exceeded"; 328 break; 329 330 default: | 311 ipaddr_string(&idp->ird_addr), 312 EXTRACT_32BITS(&idp->ird_pref)); 313 cp = buf + strlen(buf); 314 } 315 } 316 break; 317 318 case ICMP_TIMXCEED: --- 4 unchanged lines hidden (view full) --- 323 str = "time exceeded in-transit"; 324 break; 325 326 case ICMP_TIMXCEED_REASS: 327 str = "ip reassembly time exceeded"; 328 break; 329 330 default: |
331 (void)sprintf(buf, "time exceeded-#%d", dp->icmp_code); | 331 (void)snprintf(buf, sizeof(buf), "time exceeded-#%d", dp->icmp_code); |
332 break; 333 } 334 break; 335 336 case ICMP_PARAMPROB: 337 if (dp->icmp_code) | 332 break; 333 } 334 break; 335 336 case ICMP_PARAMPROB: 337 if (dp->icmp_code) |
338 (void)sprintf(buf, "parameter problem - code %d", | 338 (void)snprintf(buf, sizeof(buf), "parameter problem - code %d", |
339 dp->icmp_code); 340 else { 341 TCHECK(dp->icmp_pptr); | 339 dp->icmp_code); 340 else { 341 TCHECK(dp->icmp_pptr); |
342 (void)sprintf(buf, "parameter problem - octet %d", | 342 (void)snprintf(buf, sizeof(buf), "parameter problem - octet %d", |
343 dp->icmp_pptr); 344 } 345 break; 346 347 case ICMP_MASKREPLY: 348 TCHECK(dp->icmp_mask); | 343 dp->icmp_pptr); 344 } 345 break; 346 347 case ICMP_MASKREPLY: 348 TCHECK(dp->icmp_mask); |
349 (void)sprintf(buf, "address mask is 0x%08x", | 349 (void)snprintf(buf, sizeof(buf), "address mask is 0x%08x", |
350 (u_int32_t)ntohl(dp->icmp_mask)); 351 break; 352 353 default: 354 str = tok2str(icmp2str, "type-#%d", dp->icmp_type); 355 break; 356 } 357 (void)printf("icmp: %s", str); --- 17 unchanged lines hidden --- | 350 (u_int32_t)ntohl(dp->icmp_mask)); 351 break; 352 353 default: 354 str = tok2str(icmp2str, "type-#%d", dp->icmp_type); 355 break; 356 } 357 (void)printf("icmp: %s", str); --- 17 unchanged lines hidden --- |