summaryrefslogtreecommitdiff
path: root/other/b-scan/src/dcd_icmp.c
blob: c627a5621d8532a116d9707a3eedf912e8da1370 (plain)
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
/* bscan - icmp decoder
 *
 * based on information from
 *   RFC792 - INTERNET CONTROL MESSAGE PROTOCOL
 *   RFC950 - Internet Standard Subnetting Procedure
 *   ??? "ICMP Usage in Scanning" (ICMP_Scanning_v2.5.pdf)
 */

#include <stdio.h>
#include <bscan/dcd_icmp.h>

static char *	icmp_echo_reply[] = {
	"ICMP ECHOREPLY",
	NULL
};

static char *	icmp_unreach[] = {
	"ICMP UNREACH network unreachable",
	"ICMP UNREACH host unreachable",
	"ICMP UNREACH protocol unreachable",
	"ICMP UNREACH port unreachable",
	"ICMP UNREACH fragmentation needed but don't-fragment bit set",
	"ICMP UNREACH source route failed",
	"ICMP UNREACH destination network unknown",
	"ICMP UNREACH destination host unknown",
	"ICMP UNREACH source host isolated",
	"ICMP UNREACH destination network administratively prohibited",
	"ICMP UNREACH destination host administratively prohibited",
	"ICMP UNREACH network unreachable for TOS",
	"ICMP UNREACH host unreachable for TOS",
	"ICMP UNREACH communication administratively prohibited by filtering",
	"ICMP UNREACH host precedence violation",
	"ICMP UNREACH precedence cutoff in effect",
	NULL
};

static char *	icmp_quench[] = {
	"ICMP QUENCH",
	NULL
};

static char *	icmp_redirect[] = {
	"ICMP REDIRECT Redirect datagrams for the Network",
	"ICMP REDIRECT Redirect datagrams for the Host",
	"ICMP REDIRECT Redirect datagrams for the Type of Service and Network",
	"ICMP REDIRECT Redirect datagrams for the Type of Service and Host",
	NULL
};

static char *	icmp_alternate[] = {
	"ICMP ALTERNATEHOSTADDRESS",
	NULL
};

static char *	icmp_echo[] = {
	"ICMP ECHO",
	NULL
};

static char *	icmp_routerad[] = {
	"ICMP ROUTERADVERTISEMENT",
	NULL
};

static char *	icmp_routersel[] = {
	"ICMP ROUTERSELECTION",
	NULL
};

static char *	icmp_timeexceed[] = {
	"ICMP TIMEEXCEED time to live exceeded in transit",
	"ICMP TIMEEXCEED fragment reassembly time exceeded",
	NULL
};

static char *	icmp_parprob[] = {
	"ICMP PARAMETER pointer indicates the error",
	"ICMP PARAMETER missing a required option",
	"ICMP PARAMETER bad length",
	NULL
};

static char *	icmp_timestamp[] = {
	"ICMP TIMESTAMP",
	NULL
};

static char *	icmp_timestamp_reply[] = {
	"ICMP TIMESTAMPREPLY",
	NULL
};

static char *	icmp_information[] = {
	"ICMP INFORMATION",
	NULL
};

static char *	icmp_information_reply[] = {
	"ICMP INFORMATIONREPLY",
	NULL
};

static char *	icmp_addressmask[] = {
	"ICMP ADDRESSMASK",
	NULL
};

static char *	icmp_addressmask_reply[] = {
	"ICMP ADDRESSMASKREPLY",
	NULL
};

static char *	icmp_ERR[] = {
	"ICMP invalid code",
	NULL
};

struct icmp_typeelem {
	int		count;
	char **		tab;
};

struct icmp_typeelem 	icmp_tab[] = {
	{  1, icmp_echo_reply },	/*  0  Echo Reply */
	{  0, icmp_ERR },		/*  1  UNUSED */
	{  0, icmp_ERR },		/*  2  UNUSED */
	{ 16, icmp_unreach },		/*  3  Destination Unreachable */
	{  1, icmp_quench },		/*  4  Source Quench */
	{  4, icmp_redirect },		/*  5  Redirect */
	{  1, icmp_alternate },		/*  6  Alternate Host Address */
	{  0, icmp_ERR },		/*  7  UNUSED */
	{  1, icmp_echo },		/*  8  Echo */
	{  1, icmp_routerad },		/*  9  Router Advertisement */
	{  1, icmp_routersel },		/* 10  Router Selection */
	{  2, icmp_timeexceed },	/* 11  Time Exceeded */
	{  3, icmp_parprob },		/* 12  Parameter Problem */
	{  1, icmp_timestamp },		/* 13  Timestamp */
	{  1, icmp_timestamp_reply },	/* 14  Timestamp Reply */
	{  1, icmp_information },	/* 15  Information Request */
	{  1, icmp_information_reply },	/* 16  Information Request */
	{  1, icmp_addressmask },	/* 17  RFC950: Address Mask Request */
	{  1, icmp_addressmask_reply },	/* 18  RFC950: Address Mask Reply */
	{  0, NULL },	/* EOList */ 
};

int	icmp_type_max = (sizeof (icmp_tab) / sizeof (struct icmp_typeelem)) - 1;

const char *
icmp_str (int type, int code)
{
	struct icmp_typeelem *	it;

	if (type < 0 || type >= icmp_type_max)
		return ("ICMP invalid type");

	it = &icmp_tab[type];
	if (it->count == 0)
		return (it->tab[0]);

	if (code < 0 || code >= it->count)
		return ("ICMP invalid code");

	return (it->tab[code]);
}