summaryrefslogtreecommitdiff
path: root/other/b-scan/tmp/src/dcd_icmp.c
diff options
context:
space:
mode:
authorRoot THC2026-02-24 12:42:47 +0000
committerRoot THC2026-02-24 12:42:47 +0000
commitc9cbeced5b3f2bdd7407e29c0811e65954132540 (patch)
treeaefc355416b561111819de159ccbd86c3004cf88 /other/b-scan/tmp/src/dcd_icmp.c
parent073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff)
initial
Diffstat (limited to 'other/b-scan/tmp/src/dcd_icmp.c')
-rw-r--r--other/b-scan/tmp/src/dcd_icmp.c166
1 files changed, 166 insertions, 0 deletions
diff --git a/other/b-scan/tmp/src/dcd_icmp.c b/other/b-scan/tmp/src/dcd_icmp.c
new file mode 100644
index 0000000..c627a56
--- /dev/null
+++ b/other/b-scan/tmp/src/dcd_icmp.c
@@ -0,0 +1,166 @@
1/* bscan - icmp decoder
2 *
3 * based on information from
4 * RFC792 - INTERNET CONTROL MESSAGE PROTOCOL
5 * RFC950 - Internet Standard Subnetting Procedure
6 * ??? "ICMP Usage in Scanning" (ICMP_Scanning_v2.5.pdf)
7 */
8
9#include <stdio.h>
10#include <bscan/dcd_icmp.h>
11
12static char * icmp_echo_reply[] = {
13 "ICMP ECHOREPLY",
14 NULL
15};
16
17static char * icmp_unreach[] = {
18 "ICMP UNREACH network unreachable",
19 "ICMP UNREACH host unreachable",
20 "ICMP UNREACH protocol unreachable",
21 "ICMP UNREACH port unreachable",
22 "ICMP UNREACH fragmentation needed but don't-fragment bit set",
23 "ICMP UNREACH source route failed",
24 "ICMP UNREACH destination network unknown",
25 "ICMP UNREACH destination host unknown",
26 "ICMP UNREACH source host isolated",
27 "ICMP UNREACH destination network administratively prohibited",
28 "ICMP UNREACH destination host administratively prohibited",
29 "ICMP UNREACH network unreachable for TOS",
30 "ICMP UNREACH host unreachable for TOS",
31 "ICMP UNREACH communication administratively prohibited by filtering",
32 "ICMP UNREACH host precedence violation",
33 "ICMP UNREACH precedence cutoff in effect",
34 NULL
35};
36
37static char * icmp_quench[] = {
38 "ICMP QUENCH",
39 NULL
40};
41
42static char * icmp_redirect[] = {
43 "ICMP REDIRECT Redirect datagrams for the Network",
44 "ICMP REDIRECT Redirect datagrams for the Host",
45 "ICMP REDIRECT Redirect datagrams for the Type of Service and Network",
46 "ICMP REDIRECT Redirect datagrams for the Type of Service and Host",
47 NULL
48};
49
50static char * icmp_alternate[] = {
51 "ICMP ALTERNATEHOSTADDRESS",
52 NULL
53};
54
55static char * icmp_echo[] = {
56 "ICMP ECHO",
57 NULL
58};
59
60static char * icmp_routerad[] = {
61 "ICMP ROUTERADVERTISEMENT",
62 NULL
63};
64
65static char * icmp_routersel[] = {
66 "ICMP ROUTERSELECTION",
67 NULL
68};
69
70static char * icmp_timeexceed[] = {
71 "ICMP TIMEEXCEED time to live exceeded in transit",
72 "ICMP TIMEEXCEED fragment reassembly time exceeded",
73 NULL
74};
75
76static char * icmp_parprob[] = {
77 "ICMP PARAMETER pointer indicates the error",
78 "ICMP PARAMETER missing a required option",
79 "ICMP PARAMETER bad length",
80 NULL
81};
82
83static char * icmp_timestamp[] = {
84 "ICMP TIMESTAMP",
85 NULL
86};
87
88static char * icmp_timestamp_reply[] = {
89 "ICMP TIMESTAMPREPLY",
90 NULL
91};
92
93static char * icmp_information[] = {
94 "ICMP INFORMATION",
95 NULL
96};
97
98static char * icmp_information_reply[] = {
99 "ICMP INFORMATIONREPLY",
100 NULL
101};
102
103static char * icmp_addressmask[] = {
104 "ICMP ADDRESSMASK",
105 NULL
106};
107
108static char * icmp_addressmask_reply[] = {
109 "ICMP ADDRESSMASKREPLY",
110 NULL
111};
112
113static char * icmp_ERR[] = {
114 "ICMP invalid code",
115 NULL
116};
117
118struct icmp_typeelem {
119 int count;
120 char ** tab;
121};
122
123struct icmp_typeelem icmp_tab[] = {
124 { 1, icmp_echo_reply }, /* 0 Echo Reply */
125 { 0, icmp_ERR }, /* 1 UNUSED */
126 { 0, icmp_ERR }, /* 2 UNUSED */
127 { 16, icmp_unreach }, /* 3 Destination Unreachable */
128 { 1, icmp_quench }, /* 4 Source Quench */
129 { 4, icmp_redirect }, /* 5 Redirect */
130 { 1, icmp_alternate }, /* 6 Alternate Host Address */
131 { 0, icmp_ERR }, /* 7 UNUSED */
132 { 1, icmp_echo }, /* 8 Echo */
133 { 1, icmp_routerad }, /* 9 Router Advertisement */
134 { 1, icmp_routersel }, /* 10 Router Selection */
135 { 2, icmp_timeexceed }, /* 11 Time Exceeded */
136 { 3, icmp_parprob }, /* 12 Parameter Problem */
137 { 1, icmp_timestamp }, /* 13 Timestamp */
138 { 1, icmp_timestamp_reply }, /* 14 Timestamp Reply */
139 { 1, icmp_information }, /* 15 Information Request */
140 { 1, icmp_information_reply }, /* 16 Information Request */
141 { 1, icmp_addressmask }, /* 17 RFC950: Address Mask Request */
142 { 1, icmp_addressmask_reply }, /* 18 RFC950: Address Mask Reply */
143 { 0, NULL }, /* EOList */
144};
145
146int icmp_type_max = (sizeof (icmp_tab) / sizeof (struct icmp_typeelem)) - 1;
147
148const char *
149icmp_str (int type, int code)
150{
151 struct icmp_typeelem * it;
152
153 if (type < 0 || type >= icmp_type_max)
154 return ("ICMP invalid type");
155
156 it = &icmp_tab[type];
157 if (it->count == 0)
158 return (it->tab[0]);
159
160 if (code < 0 || code >= it->count)
161 return ("ICMP invalid code");
162
163 return (it->tab[code]);
164}
165
166