00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __LIBNET_HEADERS_H
00033 #define __LIBNET_HEADERS_H
00034
00035
00036
00037
00038
00039 #define LIBNET_ARP_H 0x1c
00040 #define LIBNET_DNS_H 0xc
00041 #define LIBNET_ETH_H 0xe
00042 #define LIBNET_ICMP_H 0x4
00043 #define LIBNET_ICMP_ECHO_H 0x8
00044 #define LIBNET_ICMP_MASK_H 0xc
00045 #define LIBNET_ICMP_UNREACH_H 0x8
00046 #define LIBNET_ICMP_TIMXCEED_H 0x8
00047 #define LIBNET_ICMP_REDIRECT_H 0x8
00048 #define LIBNET_ICMP_TS_H 0x14
00049 #define LIBNET_IGMP_H 0x8
00050 #define LIBNET_IP_H 0x14
00051
00052 #define LIBNET_RIP_H 0x18
00053 #define LIBNET_TCP_H 0x14
00054 #define LIBNET_UDP_H 0x8
00055
00056
00057
00058
00059 #define ARP_H LIBNET_ARP_H
00060 #define DNS_H LIBNET_DNS_H
00061 #define ETH_H LIBNET_ETH_H
00062 #define ICMP_H LIBNET_ICMP_H
00063 #define ICMP_ECHO_H LIBNET_ICMP_ECHO_H
00064 #define ICMP_MASK_H LIBNET_ICMP_MASK_H
00065 #define ICMP_UNREACH_H LIBNET_ICMP_UNREACH_H
00066 #define ICMP_TIMXCEED_H LIBNET_ICMP_TIMXCEED_H
00067 #define ICMP_REDIRECT_H LIBNET_ICMP_REDIRECT_H
00068 #define ICMP_TS_H LIBNET_ICMP_TS_H
00069 #define IGMP_H LIBNET_IGMP_H
00070 #define IP_H LIBNET_IP_H
00071 #define RIP_H LIBNET_RIP_H
00072 #define TCP_H LIBNET_TCP_H
00073 #define UDP_H LIBNET_UDP_H
00074
00075
00076
00077
00078 struct libnet_ip_hdr
00079 {
00080 #if (LIBNET_LIL_ENDIAN)
00081 u_char ip_hl:4,
00082 ip_v:4;
00083 #endif
00084 #if (LIBNET_BIG_ENDIAN)
00085 u_char ip_v:4,
00086 ip_hl:4;
00087 #endif
00088 u_char ip_tos;
00089 u_short ip_len;
00090 u_short ip_id;
00091 u_short ip_off;
00092 #ifndef IP_RF
00093 #define IP_RF 0x8000
00094 #endif
00095 #ifndef IP_DF
00096 #define IP_DF 0x4000
00097 #endif
00098 #ifndef IP_MF
00099 #define IP_MF 0x2000
00100 #endif
00101 #ifndef IP_OFFMASK
00102 #define IP_OFFMASK 0x1fff
00103 #endif
00104 u_char ip_ttl;
00105 u_char ip_p;
00106 u_short ip_sum;
00107 struct in_addr ip_src, ip_dst;
00108 };
00109
00110 #ifndef IP_MAXPACKET
00111 #define IP_MAXPACKET 65535
00112 #endif
00113
00114
00115
00116
00117 struct libnet_tcp_hdr
00118 {
00119 u_short th_sport;
00120 u_short th_dport;
00121 u_long th_seq;
00122 u_long th_ack;
00123 #if (LIBNET_LIL_ENDIAN)
00124 u_char th_x2:4,
00125 th_off:4;
00126 #endif
00127 #if (LIBNET_BIG_ENDIAN)
00128 u_char th_off:4,
00129 th_x2:4;
00130 #endif
00131 u_char th_flags;
00132 #ifndef TH_FIN
00133 #define TH_FIN 0x01
00134 #endif
00135 #ifndef TH_SYN
00136 #define TH_SYN 0x02
00137 #endif
00138 #ifndef TH_RST
00139 #define TH_RST 0x04
00140 #endif
00141 #ifndef TH_PUSH
00142 #define TH_PUSH 0x08
00143 #endif
00144 #ifndef TH_ACK
00145 #define TH_ACK 0x10
00146 #endif
00147 #ifndef TH_URG
00148 #define TH_URG 0x20
00149 #endif
00150 u_short th_win;
00151 u_short th_sum;
00152 u_short th_urp;
00153 };
00154
00155
00156
00157
00158
00159 struct libnet_udp_hdr
00160 {
00161 u_short uh_sport;
00162 u_short uh_dport;
00163 u_short uh_ulen;
00164 u_short uh_sum;
00165 };
00166
00167
00168
00169
00170
00171 struct libnet_icmp_hdr
00172 {
00173 u_char icmp_type;
00174
00175
00176
00177 #ifndef ICMP_ECHOREPLY
00178 #define ICMP_ECHOREPLY 0
00179 #endif
00180 #ifndef ICMP_UNREACH
00181 #define ICMP_UNREACH 3
00182 #endif
00183 #ifndef ICMP_SOURCEQUENCH
00184 #define ICMP_SOURCEQUENCH 4
00185 #endif
00186 #ifndef ICMP_REDIRECT
00187 #define ICMP_REDIRECT 5
00188 #endif
00189 #ifndef ICMP_ECHO
00190 #define ICMP_ECHO 8
00191 #endif
00192 #ifndef ICMP_ROUTERADVERT
00193 #define ICMP_ROUTERADVERT 9
00194 #endif
00195 #ifndef ICMP_ROUTERSOLICIT
00196 #define ICMP_ROUTERSOLICIT 10
00197 #endif
00198 #ifndef ICMP_TIMXCEED
00199 #define ICMP_TIMXCEED 11
00200 #endif
00201 #ifndef ICMP_PARAMPROB
00202 #define ICMP_PARAMPROB 12
00203 #endif
00204 #ifndef ICMP_TSTAMP
00205 #define ICMP_TSTAMP 13
00206 #endif
00207 #ifndef ICMP_TSTAMPREPLY
00208 #define ICMP_TSTAMPREPLY 14
00209 #endif
00210 #ifndef ICMP_IREQ
00211 #define ICMP_IREQ 15
00212 #endif
00213 #ifndef ICMP_IREQREPLY
00214 #define ICMP_IREQREPLY 16
00215 #endif
00216 #ifndef ICMP_MASKREQ
00217 #define ICMP_MASKREQ 17
00218 #endif
00219 #ifndef ICMP_MASKREPLY
00220 #define ICMP_MASKREPLY 18
00221 #endif
00222 u_char icmp_code;
00223
00224
00225
00226 #ifndef ICMP_UNREACH_NET
00227 #define ICMP_UNREACH_NET 0
00228 #endif
00229 #ifndef ICMP_UNREACH_HOST
00230 #define ICMP_UNREACH_HOST 1
00231 #endif
00232 #ifndef ICMP_UNREACH_PROTOCOL
00233 #define ICMP_UNREACH_PROTOCOL 2
00234 #endif
00235 #ifndef ICMP_UNREACH_PORT
00236 #define ICMP_UNREACH_PORT 3
00237 #endif
00238 #ifndef ICMP_UNREACH_NEEDFRAG
00239 #define ICMP_UNREACH_NEEDFRAG 4
00240 #endif
00241 #ifndef ICMP_UNREACH_SRCFAIL
00242 #define ICMP_UNREACH_SRCFAIL 5
00243 #endif
00244 #ifndef ICMP_UNREACH_NET_UNKNOWN
00245 #define ICMP_UNREACH_NET_UNKNOWN 6
00246 #endif
00247 #ifndef ICMP_UNREACH_HOST_UNKNOWN
00248 #define ICMP_UNREACH_HOST_UNKNOWN 7
00249 #endif
00250 #ifndef ICMP_UNREACH_ISOLATED
00251 #define ICMP_UNREACH_ISOLATED 8
00252 #endif
00253 #ifndef ICMP_UNREACH_NET_PROHIB
00254 #define ICMP_UNREACH_NET_PROHIB 9
00255 #endif
00256 #ifndef ICMP_UNREACH_HOST_PROHIB
00257 #define ICMP_UNREACH_HOST_PROHIB 10
00258 #endif
00259 #ifndef ICMP_UNREACH_TOSNET
00260 #define ICMP_UNREACH_TOSNET 11
00261 #endif
00262 #ifndef ICMP_UNREACH_TOSHOST
00263 #define ICMP_UNREACH_TOSHOST 12
00264 #endif
00265 #ifndef ICMP_UNREACH_FILTER_PROHIB
00266 #define ICMP_UNREACH_FILTER_PROHIB 13
00267 #endif
00268 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
00269 #define ICMP_UNREACH_HOST_PRECEDENCE 14
00270 #endif
00271 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
00272 #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
00273 #endif
00274 #ifndef ICMP_REDIRECT_NET
00275 #define ICMP_REDIRECT_NET 0
00276 #endif
00277 #ifndef ICMP_REDIRECT_HOST
00278 #define ICMP_REDIRECT_HOST 1
00279 #endif
00280 #ifndef ICMP_REDIRECT_TOSNET
00281 #define ICMP_REDIRECT_TOSNET 2
00282 #endif
00283 #ifndef ICMP_REDIRECT_TOSHOST
00284 #define ICMP_REDIRECT_TOSHOST 3
00285 #endif
00286 #ifndef ICMP_TIMXCEED_INTRANS
00287 #define ICMP_TIMXCEED_INTRANS 0
00288 #endif
00289 #ifndef ICMP_TIMXCEED_REASS
00290 #define ICMP_TIMXCEED_REASS 1
00291 #endif
00292 #ifndef ICMP_PARAMPROB_OPTABSENT
00293 #define ICMP_PARAMPROB_OPTABSENT 1
00294 #endif
00295
00296 u_short icmp_sum;
00297
00298 union
00299 {
00300 struct
00301 {
00302 u_short id;
00303 u_short seq;
00304 }echo;
00305
00306 #undef icmp_id
00307 #undef icmp_seq
00308 #define icmp_id hun.echo.id
00309 #define icmp_seq hun.echo.seq
00310
00311 u_long gateway;
00312 struct
00313 {
00314 u_short pad;
00315 u_short mtu;
00316 }frag;
00317 }hun;
00318 union
00319 {
00320 struct
00321 {
00322 n_time its_otime;
00323 n_time its_rtime;
00324 n_time its_ttime;
00325 }ts;
00326 struct
00327 {
00328 struct ip idi_ip;
00329
00330 }ip;
00331 u_long mask;
00332 char data[1];
00333
00334 #undef icmp_mask
00335 #define icmp_mask dun.mask
00336 #undef icmp_data
00337 #define icmp_data dun.data
00338
00339 #undef icmp_otime
00340 #define icmp_otime dun.ts.its_otime
00341 #undef icmp_rtime
00342 #define icmp_rtime dun.ts.its_rtime
00343 #undef icmp_ttime
00344 #define icmp_ttime dun.ts.its_ttime
00345 }dun;
00346 };
00347
00348
00349
00350
00351
00352 struct libnet_igmp_hdr
00353 {
00354 u_char igmp_type;
00355 #ifndef IGMP_MEMBERSHIP_QUERY
00356 #define IGMP_MEMBERSHIP_QUERY 0x11
00357 #endif
00358 #ifndef IGMP_V1_MEMBERSHIP_REPORT
00359 #define IGMP_V1_MEMBERSHIP_REPORT 0x12
00360 #endif
00361 #ifndef IGMP_V2_MEMBERSHIP_REPORT
00362 #define IGMP_V2_MEMBERSHIP_REPORT 0x16
00363 #endif
00364 #ifndef IGMP_LEAVE_GROUP
00365 #define IGMP_LEAVE_GROUP 0x17
00366 #endif
00367 u_char igmp_code;
00368 u_short igmp_sum;
00369 struct in_addr igmp_group;
00370 };
00371
00372
00373
00374
00375
00376
00377 struct libnet_ethernet_hdr
00378 {
00379 #ifndef ETHER_ADDR_LEN
00380 #define ETHER_ADDR_LEN 6
00381 #endif
00382 u_char ether_dhost[ETHER_ADDR_LEN];
00383 u_char ether_shost[ETHER_ADDR_LEN];
00384 u_short ether_type;
00385 };
00386
00387 #define ETHERTYPE_PUP 0x0200
00388 #define ETHERTYPE_IP 0x0800
00389 #define ETHERTYPE_ARP 0x0806
00390 #define ETHERTYPE_REVARP 0x8035
00391 #define ETHERTYPE_VLAN 0x8100
00392 #define ETHERTYPE_LOOPBACK 0x9000
00393
00394 #if (!__GLIBC__)
00395 struct ether_addr
00396 {
00397 u_char ether_addr_octet[6];
00398 };
00399 #endif
00400
00401
00402
00403
00404
00405 struct libnet_arp_hdr
00406 {
00407 u_short ar_hrd;
00408 #define ARPHRD_ETHER 1
00409 u_short ar_pro;
00410 u_char ar_hln;
00411 u_char ar_pln;
00412 u_short ar_op;
00413 #define ARPOP_REQUEST 1
00414 #define ARPOP_REPLY 2
00415 #define ARPOP_REVREQUEST 3
00416 #define ARPOP_REVREPLY 4
00417 #define ARPOP_INVREQUEST 8
00418 #define ARPOP_INVREPLY 9
00419
00420
00421
00422
00423 u_char ar_sha[6];
00424 u_char ar_spa[4];
00425 u_char ar_tha[6];
00426 u_char ar_tpa[4];
00427 };
00428
00429
00430
00431
00432
00433 struct libnet_dns_hdr
00434 {
00435 u_short id;
00436 u_short flags;
00437 u_short num_q;
00438 u_short num_answ_rr;
00439 u_short num_auth_rr;
00440 u_short num_addi_rr;
00441 };
00442
00443
00444
00445
00446
00447 struct libnet_rip_hdr
00448 {
00449 u_char cmd;
00450 #define RIPCMD_REQUEST 1
00451 #define RIPCMD_RESPONSE 2
00452 #define RIPCMD_TRACEON 3
00453 #define RIPCMD_TRACEOFF 4
00454 #define RIPCMD_POLL 5
00455 #define RIPCMD_POLLENTRY 6
00456 #define RIPCMD_MAX 7
00457 u_char ver;
00458 #define RIPVER_0 0
00459 #define RIPVER_1 1
00460 #define RIPVER_2 2
00461 u_short rd;
00462 u_short af;
00463 u_short rt;
00464 u_long addr;
00465 u_long mask;
00466 u_long next_hop;
00467 u_long metric;
00468 };
00469
00470
00471 #if 0
00472 struct libnet_snmp_hdr
00473 {
00474
00475 };
00476 #endif
00477
00478
00479
00480
00481
00482 struct tcpoption
00483 {
00484 u_char tcpopt_list[MAX_IPOPTLEN];
00485 };
00486
00487
00488 #if (__linux__ || WIN32)
00489
00490
00491
00492 struct ipoption
00493 {
00494 struct in_addr ipopt_dst;
00495 char ipopt_list[MAX_IPOPTLEN];
00496 };
00497 #endif
00498
00499 #endif
00500
00501