Deleted Added
sdiff udiff text old ( 111729 ) new ( 127675 )
full compact
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 $
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)";
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>
36
37#include <netinet/in.h>
38
39#include <stdio.h>
40#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"
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 {
73 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
270icmp_print(const u_char *bp, u_int plen, const u_char *bp2)
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
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);
305 dport = ntohs(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",
450 (unsigned)ntohl(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 (unsigned)ntohs(dp->icmp_id),
458 (unsigned)ntohs(dp->icmp_seq));
459 break;
460
461 case ICMP_TSTAMPREPLY:
462 TCHECK(dp->icmp_ttime);
463 (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 break;
471
472 default:
473 str = tok2str(icmp2str, "type-#%d", dp->icmp_type);
474 break;
475 }
476 (void)printf("icmp: %s", str);
477 if (vflag) {
478 if (TTEST2(*bp, plen)) {
479 if (in_cksum((u_short*)dp, plen, 0))
480 printf(" (wrong icmp csum)");
481 }
482 }
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 }
490 return;
491trunc:
492 fputs("[|icmp]", stdout);
493}