00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef DNET_ICMP_H
00013 #define DNET_ICMP_H
00014
00015 #define ICMP_HDR_LEN 4
00016 #define ICMP_LEN_MIN 8
00017
00018 #ifndef __GNUC__
00019 # define __attribute__(x)
00020 # pragma pack(1)
00021 #endif
00022
00023
00024
00025
00026 struct icmp_hdr {
00027 uint8_t icmp_type;
00028 uint8_t icmp_code;
00029 uint16_t icmp_cksum;
00030 };
00031
00032
00033
00034
00035
00036 #define ICMP_CODE_NONE 0
00037 #define ICMP_ECHOREPLY 0
00038 #define ICMP_UNREACH 3
00039 #define ICMP_UNREACH_NET 0
00040 #define ICMP_UNREACH_HOST 1
00041 #define ICMP_UNREACH_PROTO 2
00042 #define ICMP_UNREACH_PORT 3
00043 #define ICMP_UNREACH_NEEDFRAG 4
00044 #define ICMP_UNREACH_SRCFAIL 5
00045 #define ICMP_UNREACH_NET_UNKNOWN 6
00046 #define ICMP_UNREACH_HOST_UNKNOWN 7
00047 #define ICMP_UNREACH_ISOLATED 8
00048 #define ICMP_UNREACH_NET_PROHIB 9
00049 #define ICMP_UNREACH_HOST_PROHIB 10
00050 #define ICMP_UNREACH_TOSNET 11
00051 #define ICMP_UNREACH_TOSHOST 12
00052 #define ICMP_UNREACH_FILTER_PROHIB 13
00053 #define ICMP_UNREACH_HOST_PRECEDENCE 14
00054 #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
00055 #define ICMP_SRCQUENCH 4
00056 #define ICMP_REDIRECT 5
00057 #define ICMP_REDIRECT_NET 0
00058 #define ICMP_REDIRECT_HOST 1
00059 #define ICMP_REDIRECT_TOSNET 2
00060 #define ICMP_REDIRECT_TOSHOST 3
00061 #define ICMP_ALTHOSTADDR 6
00062 #define ICMP_ECHO 8
00063 #define ICMP_RTRADVERT 9
00064 #define ICMP_RTRADVERT_NORMAL 0
00065 #define ICMP_RTRADVERT_NOROUTE_COMMON 16
00066 #define ICMP_RTRSOLICIT 10
00067 #define ICMP_TIMEXCEED 11
00068 #define ICMP_TIMEXCEED_INTRANS 0
00069 #define ICMP_TIMEXCEED_REASS 1
00070 #define ICMP_PARAMPROB 12
00071 #define ICMP_PARAMPROB_ERRATPTR 0
00072 #define ICMP_PARAMPROB_OPTABSENT 1
00073 #define ICMP_PARAMPROB_LENGTH 2
00074 #define ICMP_TSTAMP 13
00075 #define ICMP_TSTAMPREPLY 14
00076 #define ICMP_INFO 15
00077 #define ICMP_INFOREPLY 16
00078 #define ICMP_MASK 17
00079 #define ICMP_MASKREPLY 18
00080 #define ICMP_TRACEROUTE 30
00081 #define ICMP_DATACONVERR 31
00082 #define ICMP_MOBILE_REDIRECT 32
00083 #define ICMP_IPV6_WHEREAREYOU 33
00084 #define ICMP_IPV6_IAMHERE 34
00085 #define ICMP_MOBILE_REG 35
00086 #define ICMP_MOBILE_REGREPLY 36
00087 #define ICMP_DNS 37
00088 #define ICMP_DNSREPLY 38
00089 #define ICMP_SKIP 39
00090 #define ICMP_PHOTURIS 40
00091 #define ICMP_PHOTURIS_UNKNOWN_INDEX 0
00092 #define ICMP_PHOTURIS_AUTH_FAILED 1
00093 #define ICMP_PHOTURIS_DECOMPRESS_FAILED 2
00094 #define ICMP_PHOTURIS_DECRYPT_FAILED 3
00095 #define ICMP_PHOTURIS_NEED_AUTHN 4
00096 #define ICMP_PHOTURIS_NEED_AUTHZ 5
00097 #define ICMP_TYPE_MAX 40
00098
00099 #define ICMP_INFOTYPE(type) \
00100 ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
00101 (type) == ICMP_RTRADVERT || (type) == ICMP_RTRSOLICIT || \
00102 (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
00103 (type) == ICMP_INFO || (type) == ICMP_INFOREPLY || \
00104 (type) == ICMP_MASK || (type) == ICMP_MASKREPLY)
00105
00106
00107
00108
00109 struct icmp_msg_echo {
00110 uint16_t icmp_id;
00111 uint16_t icmp_seq;
00112 uint8_t icmp_data __flexarr;
00113 };
00114
00115
00116
00117
00118 struct icmp_msg_needfrag {
00119 uint16_t icmp_void;
00120 uint16_t icmp_mtu;
00121 uint8_t icmp_ip __flexarr;
00122 };
00123
00124
00125
00126
00127
00128 struct icmp_msg_quote {
00129 uint32_t icmp_void;
00130 #define icmp_gwaddr icmp_void
00131 #define icmp_pptr icmp_void
00132 uint8_t icmp_ip __flexarr;
00133 };
00134
00135
00136
00137
00138 struct icmp_msg_rtradvert {
00139 uint8_t icmp_num_addrs;
00140 uint8_t icmp_wpa;
00141 uint16_t icmp_lifetime;
00142 struct icmp_msg_rtr_data {
00143 uint32_t icmp_void;
00144 #define icmp_gwaddr icmp_void
00145 uint32_t icmp_pref;
00146 } icmp_rtr __flexarr;
00147 };
00148 #define ICMP_RTR_PREF_NODEFAULT 0x80000000
00149
00150
00151
00152
00153 struct icmp_msg_tstamp {
00154 uint32_t icmp_id;
00155 uint32_t icmp_seq;
00156 uint32_t icmp_ts_orig;
00157 uint32_t icmp_ts_rx;
00158 uint32_t icmp_ts_tx;
00159 };
00160
00161
00162
00163
00164 struct icmp_msg_mask {
00165 uint32_t icmp_id;
00166 uint32_t icmp_seq;
00167 uint32_t icmp_mask;
00168 };
00169
00170
00171
00172
00173 struct icmp_msg_traceroute {
00174 uint16_t icmp_id;
00175 uint16_t icmp_void;
00176 uint16_t icmp_ohc;
00177 uint16_t icmp_rhc;
00178 uint32_t icmp_speed;
00179 uint32_t icmp_mtu;
00180 };
00181
00182
00183
00184
00185 struct icmp_msg_dnsreply {
00186 uint16_t icmp_id;
00187 uint16_t icmp_seq;
00188 uint32_t icmp_ttl;
00189 uint8_t icmp_names __flexarr;
00190 };
00191
00192
00193
00194
00195 struct icmp_msg_idseq {
00196 uint16_t icmp_id;
00197 uint16_t icmp_seq;
00198 };
00199
00200
00201
00202
00203 union icmp_msg {
00204 struct icmp_msg_echo echo;
00205 struct icmp_msg_quote unreach;
00206 struct icmp_msg_needfrag needfrag;
00207 struct icmp_msg_quote srcquench;
00208 struct icmp_msg_quote redirect;
00209 uint32_t rtrsolicit;
00210 struct icmp_msg_rtradvert rtradvert;
00211 struct icmp_msg_quote timexceed;
00212 struct icmp_msg_quote paramprob;
00213 struct icmp_msg_tstamp tstamp;
00214 struct icmp_msg_idseq info;
00215 struct icmp_msg_mask mask;
00216 struct icmp_msg_traceroute traceroute;
00217 struct icmp_msg_idseq dns;
00218 struct icmp_msg_dnsreply dnsreply;
00219 };
00220
00221 #ifndef __GNUC__
00222 # pragma pack()
00223 #endif
00224
00225 #define icmp_pack_hdr(hdr, type, code) do { \
00226 struct icmp_hdr *icmp_pack_p = (struct icmp_hdr *)(hdr); \
00227 icmp_pack_p->icmp_type = type; icmp_pack_p->icmp_code = code; \
00228 } while (0)
00229
00230 #define icmp_pack_hdr_echo(hdr, type, code, id, seq, data, len) do { \
00231 struct icmp_msg_echo *echo_pack_p = (struct icmp_msg_echo *) \
00232 ((uint8_t *)(hdr) + ICMP_HDR_LEN); \
00233 icmp_pack_hdr(hdr, type, code); \
00234 echo_pack_p->icmp_id = htons(id); \
00235 echo_pack_p->icmp_seq = htons(seq); \
00236 memmove(echo_pack_p->icmp_data, data, len); \
00237 } while (0)
00238
00239 #define icmp_pack_hdr_quote(hdr, type, code, word, pkt, len) do { \
00240 struct icmp_msg_quote *quote_pack_p = (struct icmp_msg_quote *) \
00241 ((uint8_t *)(hdr) + ICMP_HDR_LEN); \
00242 icmp_pack_hdr(hdr, type, code); \
00243 quote_pack_p->icmp_void = htonl(word); \
00244 memmove(quote_pack_p->icmp_ip, pkt, len); \
00245 } while (0)
00246
00247 #define icmp_pack_hdr_mask(hdr, type, code, id, seq, mask) do { \
00248 struct icmp_msg_mask *mask_pack_p = (struct icmp_msg_mask *) \
00249 ((uint8_t *)(hdr) + ICMP_HDR_LEN); \
00250 icmp_pack_hdr(hdr, type, code); \
00251 mask_pack_p->icmp_id = htons(id); \
00252 mask_pack_p->icmp_seq = htons(seq); \
00253 mask_pack_p->icmp_mask = htonl(mask); \
00254 } while (0)
00255
00256 #define icmp_pack_hdr_needfrag(hdr, type, code, mtu, pkt, len) do { \
00257 struct icmp_msg_needfrag *frag_pack_p = \
00258 (struct icmp_msg_needfrag *)((uint8_t *)(hdr) + ICMP_HDR_LEN); \
00259 icmp_pack_hdr(hdr, type, code); \
00260 frag_pack_p->icmp_void = 0; \
00261 frag_pack_p->icmp_mtu = htons(mtu); \
00262 memmove(frag_pack_p->icmp_ip, pkt, len); \
00263 } while (0)
00264
00265 #endif