1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/* @(#) $Header: /home/ax25-cvs/ax25-apps/listen/icmpdump.c,v 1.2 2001/09/12 13:18:44 terry Exp $ */
/* ICMP header tracing
* Copyright 1991 Phil Karn, KA9Q
*/
#include <stdio.h>
#include "listen.h"
#define ICMP_DEST_UNREACH 3
#define ICMP_REDIRECT 5
#define ICMP_TIME_EXCEED 11
#define ICMP_PARAM_PROB 12
#define ICMP_ECHO 8
#define ICMP_ECHO_REPLY 0
#define ICMP_INFO_RQST 15
#define ICMP_INFO_REPLY 16
#define ICMP_TIMESTAMP 13
#define ICMP_TIME_REPLY 14
#define ICMP_QUENCH 4
#define ICMPLEN 8
/* Dump an ICMP header */
void icmp_dump(unsigned char *data, int length, int hexdump)
{
int type;
int code;
int pointer;
unsigned char *address;
int id, seq;
type = data[0];
code = data[1];
pointer = data[4];
address = data + 4;
id = get16(data + 4);
seq = get16(data + 6);
data += ICMPLEN;
length -= ICMPLEN;
lprintf(T_IPHDR, "ICMP: type ");
switch (type) {
case ICMP_DEST_UNREACH:
lprintf(T_ERROR, "Unreachable ");
lprintf(T_IPHDR, "code ");
switch (code) {
case 0:
lprintf(T_ERROR, "Network");
break;
case 1:
lprintf(T_ERROR, "Host");
break;
case 2:
lprintf(T_ERROR, "Protocol");
break;
case 3:
lprintf(T_ERROR, "Port");
break;
case 4:
lprintf(T_ERROR, "Fragmentation");
break;
case 5:
lprintf(T_ERROR, "Source route");
break;
case 6:
lprintf(T_ERROR, "Dest net unknown");
break;
case 7:
lprintf(T_ERROR, "Dest host unknown");
break;
case 8:
lprintf(T_ERROR, "Source host isolated");
break;
case 9:
lprintf(T_ERROR, "Net prohibited");
break;
case 10:
lprintf(T_ERROR, "Host prohibited");
break;
case 11:
lprintf(T_ERROR, "Net TOS");
break;
case 12:
lprintf(T_ERROR, "Host TOS");
break;
case 13:
lprintf(T_ERROR, "Administratively Prohibited");
break;
default:
lprintf(T_ERROR, "%d", code);
break;
}
lprintf(T_IPHDR, "\nReturned ");
ip_dump(data, length, hexdump);
break;
case ICMP_REDIRECT:
lprintf(T_ERROR, "Redirect ");
lprintf(T_IPHDR, "code ");
switch (code) {
case 0:
lprintf(T_ERROR, "Network");
break;
case 1:
lprintf(T_ERROR, "Host");
break;
case 2:
lprintf(T_ERROR, "TOS & Network");
break;
case 3:
lprintf(T_ERROR, "TOS & Host");
break;
default:
lprintf(T_ERROR, "%d", code);
break;
}
lprintf(T_IPHDR, " new gateway %d.%d.%d.%d",
address[0], address[1], address[2], address[3]);
lprintf(T_IPHDR, "\nReturned ");
ip_dump(data, length, hexdump);
break;
case ICMP_TIME_EXCEED:
lprintf(T_ERROR, "Time Exceeded code ");
lprintf(T_ERROR, "Time Exceeded ");
lprintf(T_IPHDR, "code ");
switch (code) {
case 0:
lprintf(T_ERROR, "Time-to-live");
break;
case 1:
lprintf(T_ERROR, "Fragment reassembly");
break;
default:
lprintf(T_ERROR, "%d", code);
break;
}
lprintf(T_IPHDR, "\nReturned ");
ip_dump(data, length, hexdump);
break;
case ICMP_PARAM_PROB:
lprintf(T_ERROR, "Parameter Problem pointer %d", pointer);
lprintf(T_IPHDR, "\nReturned ");
ip_dump(data, length, hexdump);
break;
case ICMP_QUENCH:
lprintf(T_ERROR, "Source Quench");
lprintf(T_IPHDR, "\nReturned ");
ip_dump(data, length, hexdump);
break;
case ICMP_ECHO:
lprintf(T_IPHDR, "Echo Request id %d seq %d\n", id, seq);
data_dump(data, length, hexdump);
break;
case ICMP_ECHO_REPLY:
lprintf(T_IPHDR, "Echo Reply id %d seq %d\n", id, seq);
data_dump(data, length, hexdump);
break;
case ICMP_INFO_RQST:
lprintf(T_IPHDR, "Information Request id %d seq %d\n", id,
seq);
data_dump(data, length, hexdump);
break;
case ICMP_INFO_REPLY:
lprintf(T_IPHDR, "Information Reply id %d seq %d\n", id,
seq);
data_dump(data, length, hexdump);
break;
case ICMP_TIMESTAMP:
lprintf(T_IPHDR, "Timestamp Request id %d seq %d\n", id,
seq);
data_dump(data, length, hexdump);
break;
case ICMP_TIME_REPLY:
lprintf(T_IPHDR, "Timestamp Reply id %d seq %d\n", id,
seq);
data_dump(data, length, hexdump);
break;
default:
lprintf(T_IPHDR, "%d\n", type);
data_dump(data, length, hexdump);
break;
}
}
|