Deleted Added
full compact
print-icmp.c (111729) print-icmp.c (127675)
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 111729 2003-03-02 08:25:48Z fenner $
21 * $FreeBSD: head/contrib/tcpdump/print-icmp.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-icmp.c,v 1.62.4.1 2002/06/01 23:51:13 guy Exp $ (LBL)";
25static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.73.2.3 2004/03/24 00:56:34 guy Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <sys/param.h>
34#include <sys/time.h>
35#include <sys/socket.h>
33#include <tcpdump-stdinc.h>
36
34
37#include <netinet/in.h>
38
39#include <stdio.h>
40#include <string.h>
35#include <stdio.h>
36#include <string.h>
41#include <netdb.h> /* for MAXHOSTNAMELEN on some platforms */
42
43#include "interface.h"
44#include "addrtoname.h"
45#include "extract.h" /* must come after interface.h */
46
47#include "ip.h"
48#include "udp.h"
37
38#include "interface.h"
39#include "addrtoname.h"
40#include "extract.h" /* must come after interface.h */
41
42#include "ip.h"
43#include "udp.h"
44#include "ipproto.h"
49
50/*
51 * Interface Control Message Protocol Definitions.
52 * Per RFC 792, September 1981.
53 */
54
55/*
56 * Structure of an icmp header.

--- 8 unchanged lines hidden (view full) ---

65 struct ih_idseq {
66 u_int16_t icd_id;
67 u_int16_t icd_seq;
68 } ih_idseq;
69 u_int32_t ih_void;
70
71 /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
72 struct ih_pmtu {
45
46/*
47 * Interface Control Message Protocol Definitions.
48 * Per RFC 792, September 1981.
49 */
50
51/*
52 * Structure of an icmp header.

--- 8 unchanged lines hidden (view full) ---

61 struct ih_idseq {
62 u_int16_t icd_id;
63 u_int16_t icd_seq;
64 } ih_idseq;
65 u_int32_t ih_void;
66
67 /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
68 struct ih_pmtu {
73 u_int16_t ipm_void;
69 u_int16_t ipm_void;
74 u_int16_t ipm_nextmtu;
75 } ih_pmtu;
76 } icmp_hun;
77#define icmp_pptr icmp_hun.ih_pptr
78#define icmp_gwaddr icmp_hun.ih_gwaddr
79#define icmp_id icmp_hun.ih_idseq.icd_id
80#define icmp_seq icmp_hun.ih_idseq.icd_seq
81#define icmp_void icmp_hun.ih_void

--- 180 unchanged lines hidden (view full) ---

262};
263
264struct id_rdiscovery {
265 u_int32_t ird_addr;
266 u_int32_t ird_pref;
267};
268
269void
70 u_int16_t ipm_nextmtu;
71 } ih_pmtu;
72 } icmp_hun;
73#define icmp_pptr icmp_hun.ih_pptr
74#define icmp_gwaddr icmp_hun.ih_gwaddr
75#define icmp_id icmp_hun.ih_idseq.icd_id
76#define icmp_seq icmp_hun.ih_idseq.icd_seq
77#define icmp_void icmp_hun.ih_void

--- 180 unchanged lines hidden (view full) ---

258};
259
260struct id_rdiscovery {
261 u_int32_t ird_addr;
262 u_int32_t ird_pref;
263};
264
265void
270icmp_print(const u_char *bp, u_int plen, const u_char *bp2)
266icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
271{
272 char *cp;
273 const struct icmp *dp;
274 const struct ip *ip;
275 const char *str, *fmt;
276 const struct ip *oip;
277 const struct udphdr *ouh;
278 u_int hlen, dport, mtu;
279 char buf[MAXHOSTNAMELEN + 100];
280
281 dp = (struct icmp *)bp;
282 ip = (struct ip *)bp2;
283 str = buf;
284
285 TCHECK(dp->icmp_code);
286 switch (dp->icmp_type) {
287
267{
268 char *cp;
269 const struct icmp *dp;
270 const struct ip *ip;
271 const char *str, *fmt;
272 const struct ip *oip;
273 const struct udphdr *ouh;
274 u_int hlen, dport, mtu;
275 char buf[MAXHOSTNAMELEN + 100];
276
277 dp = (struct icmp *)bp;
278 ip = (struct ip *)bp2;
279 str = buf;
280
281 TCHECK(dp->icmp_code);
282 switch (dp->icmp_type) {
283
284 case ICMP_ECHO:
285 case ICMP_ECHOREPLY:
286 TCHECK(dp->icmp_seq);
287 (void)snprintf(buf, sizeof(buf), "echo %s seq %u",
288 dp->icmp_type == ICMP_ECHO ?
289 "request" : "reply",
290 EXTRACT_16BITS(&dp->icmp_seq));
291 break;
292
288 case ICMP_UNREACH:
289 TCHECK(dp->icmp_ip.ip_dst);
290 switch (dp->icmp_code) {
291
292 case ICMP_UNREACH_PROTOCOL:
293 TCHECK(dp->icmp_ip.ip_p);
294 (void)snprintf(buf, sizeof(buf),
295 "%s protocol %d unreachable",
296 ipaddr_string(&dp->icmp_ip.ip_dst),
297 dp->icmp_ip.ip_p);
298 break;
299
300 case ICMP_UNREACH_PORT:
301 TCHECK(dp->icmp_ip.ip_p);
302 oip = &dp->icmp_ip;
303 hlen = IP_HL(oip) * 4;
304 ouh = (struct udphdr *)(((u_char *)oip) + hlen);
293 case ICMP_UNREACH:
294 TCHECK(dp->icmp_ip.ip_dst);
295 switch (dp->icmp_code) {
296
297 case ICMP_UNREACH_PROTOCOL:
298 TCHECK(dp->icmp_ip.ip_p);
299 (void)snprintf(buf, sizeof(buf),
300 "%s protocol %d unreachable",
301 ipaddr_string(&dp->icmp_ip.ip_dst),
302 dp->icmp_ip.ip_p);
303 break;
304
305 case ICMP_UNREACH_PORT:
306 TCHECK(dp->icmp_ip.ip_p);
307 oip = &dp->icmp_ip;
308 hlen = IP_HL(oip) * 4;
309 ouh = (struct udphdr *)(((u_char *)oip) + hlen);
305 dport = ntohs(ouh->uh_dport);
310 TCHECK(ouh->uh_dport);
311 dport = EXTRACT_16BITS(&ouh->uh_dport);
306 switch (oip->ip_p) {
307
308 case IPPROTO_TCP:
309 (void)snprintf(buf, sizeof(buf),
310 "%s tcp port %s unreachable",
311 ipaddr_string(&oip->ip_dst),
312 tcpport_string(dport));
313 break;

--- 128 unchanged lines hidden (view full) ---

442 (void)snprintf(buf, sizeof(buf),
443 "parameter problem - octet %d", dp->icmp_pptr);
444 }
445 break;
446
447 case ICMP_MASKREPLY:
448 TCHECK(dp->icmp_mask);
449 (void)snprintf(buf, sizeof(buf), "address mask is 0x%08x",
312 switch (oip->ip_p) {
313
314 case IPPROTO_TCP:
315 (void)snprintf(buf, sizeof(buf),
316 "%s tcp port %s unreachable",
317 ipaddr_string(&oip->ip_dst),
318 tcpport_string(dport));
319 break;

--- 128 unchanged lines hidden (view full) ---

448 (void)snprintf(buf, sizeof(buf),
449 "parameter problem - octet %d", dp->icmp_pptr);
450 }
451 break;
452
453 case ICMP_MASKREPLY:
454 TCHECK(dp->icmp_mask);
455 (void)snprintf(buf, sizeof(buf), "address mask is 0x%08x",
450 (unsigned)ntohl(dp->icmp_mask));
456 EXTRACT_32BITS(&dp->icmp_mask));
451 break;
452
453 case ICMP_TSTAMP:
454 TCHECK(dp->icmp_seq);
455 (void)snprintf(buf, sizeof(buf),
456 "time stamp query id %u seq %u",
457 break;
458
459 case ICMP_TSTAMP:
460 TCHECK(dp->icmp_seq);
461 (void)snprintf(buf, sizeof(buf),
462 "time stamp query id %u seq %u",
457 (unsigned)ntohs(dp->icmp_id),
458 (unsigned)ntohs(dp->icmp_seq));
463 EXTRACT_16BITS(&dp->icmp_id),
464 EXTRACT_16BITS(&dp->icmp_seq));
459 break;
460
461 case ICMP_TSTAMPREPLY:
462 TCHECK(dp->icmp_ttime);
463 (void)snprintf(buf, sizeof(buf),
465 break;
466
467 case ICMP_TSTAMPREPLY:
468 TCHECK(dp->icmp_ttime);
469 (void)snprintf(buf, sizeof(buf),
464 "time stamp reply id %u seq %u : org 0x%lx recv 0x%lx xmit 0x%lx",
465 (unsigned)ntohs(dp->icmp_id),
466 (unsigned)ntohs(dp->icmp_seq),
467 (unsigned long)ntohl(dp->icmp_otime),
468 (unsigned long)ntohl(dp->icmp_rtime),
469 (unsigned long)ntohl(dp->icmp_ttime));
470 "time stamp reply id %u seq %u : org 0x%x recv 0x%x xmit 0x%x",
471 EXTRACT_16BITS(&dp->icmp_id),
472 EXTRACT_16BITS(&dp->icmp_seq),
473 EXTRACT_32BITS(&dp->icmp_otime),
474 EXTRACT_32BITS(&dp->icmp_rtime),
475 EXTRACT_32BITS(&dp->icmp_ttime));
470 break;
471
472 default:
473 str = tok2str(icmp2str, "type-#%d", dp->icmp_type);
474 break;
475 }
476 break;
477
478 default:
479 str = tok2str(icmp2str, "type-#%d", dp->icmp_type);
480 break;
481 }
476 (void)printf("icmp: %s", str);
477 if (vflag) {
482 (void)printf("icmp %d: %s", plen, str);
483 if (vflag && !fragmented) { /* don't attempt checksumming if this is a frag */
484 u_int16_t sum, icmp_sum;
478 if (TTEST2(*bp, plen)) {
485 if (TTEST2(*bp, plen)) {
479 if (in_cksum((u_short*)dp, plen, 0))
480 printf(" (wrong icmp csum)");
486 sum = in_cksum((u_short*)dp, plen, 0);
487 if (sum != 0) {
488 icmp_sum = EXTRACT_16BITS(&dp->icmp_cksum);
489 (void)printf(" (wrong icmp cksum %x (->%x)!)",
490 icmp_sum,
491 in_cksum_shouldbe(icmp_sum, sum));
492 }
481 }
482 }
493 }
494 }
483 if (vflag > 1 && !ICMP_INFOTYPE(dp->icmp_type)) {
484 bp += 8;
485 (void)printf(" for ");
486 ip = (struct ip *)bp;
487 snaplen = snapend - bp;
488 ip_print(bp, ntohs(ip->ip_len));
489 }
495 if (vflag > 1 && !ICMP_INFOTYPE(dp->icmp_type)) {
496 bp += 8;
497 (void)printf(" for ");
498 ip = (struct ip *)bp;
499 snaplen = snapend - bp;
500 ip_print(bp, EXTRACT_16BITS(&ip->ip_len));
501 }
490 return;
491trunc:
492 fputs("[|icmp]", stdout);
493}
502 return;
503trunc:
504 fputs("[|icmp]", stdout);
505}