2 * $Id: libnet-headers.h,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
4 * libnet-headers.h - Network routine library headers header file
6 * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #ifndef __LIBNET_HEADERS_H
33 #define __LIBNET_HEADERS_H
36 #if __BYTE_ORDER == __LITTLE_ENDIAN
37 #undef LIBNET_LIL_ENDIAN
38 #define LIBNET_LIL_ENDIAN 1
39 #elif __BYTE_ORDER == __BIG_ENDIAN
40 #undef LIBNET_BIG_ENDIAN
41 #define LIBNET_BIG_ENDIAN 1
43 #error "unknown endian"
48 * Standard (IPv4) header sizes in bytes.
51 #define LIBNET_ARP_H 0x1c /* ARP header: 28 bytes */
52 #define LIBNET_DNS_H 0xc /* DNS header base: 12 bytes */
53 #define LIBNET_ETH_H 0xe /* Etherner header: 14 bytes */
54 #define LIBNET_ICMP_H 0x4 /* ICMP header base: 4 bytes */
55 #define LIBNET_ICMP_ECHO_H 0x8 /* ICMP_ECHO header: 8 bytes */
56 #define LIBNET_ICMP_MASK_H 0xc /* ICMP_MASK header: 12 bytes */
57 #define LIBNET_ICMP_UNREACH_H 0x8 /* ICMP_UNREACH header: 8 bytes */
58 #define LIBNET_ICMP_TIMXCEED_H 0x8 /* ICMP_TIMXCEED header: 8 bytes */
59 #define LIBNET_ICMP_REDIRECT_H 0x8 /* ICMP_REDIRECT header: 8 bytes */
60 #define LIBNET_ICMP_TS_H 0x14 /* ICMP_TIMESTAMP headr:20 bytes */
61 #define LIBNET_IGMP_H 0x8 /* IGMP header: 8 bytes */
62 #define LIBNET_IP_H 0x14 /* IP header: 20 bytes */
63 /* See libnet-ospf.h for OSPF related header sizes */
64 #define LIBNET_RIP_H 0x18 /* RIP header base: 24 bytes */
65 #define LIBNET_TCP_H 0x14 /* TCP header: 20 bytes */
66 #define LIBNET_UDP_H 0x8 /* UDP header: 8 bytes */
67 #define LIBNET_VRRP_H 0x8 /* VRRP header: 8 bytes */
70 * Concession to legacy naming scheme.
72 #define ARP_H LIBNET_ARP_H
73 #define DNS_H LIBNET_DNS_H
74 #define ETH_H LIBNET_ETH_H
75 #define ICMP_H LIBNET_ICMP_H
76 #define ICMP_ECHO_H LIBNET_ICMP_ECHO_H
77 #define ICMP_MASK_H LIBNET_ICMP_MASK_H
78 #define ICMP_UNREACH_H LIBNET_ICMP_UNREACH_H
79 #define ICMP_TIMXCEED_H LIBNET_ICMP_TIMXCEED_H
80 #define ICMP_REDIRECT_H LIBNET_ICMP_REDIRECT_H
81 #define ICMP_TS_H LIBNET_ICMP_TS_H
82 #define IGMP_H LIBNET_IGMP_H
83 #define IP_H LIBNET_IP_H
84 #define RIP_H LIBNET_RIP_H
85 #define TCP_H LIBNET_TCP_H
86 #define UDP_H LIBNET_UDP_H
89 * IPv4 packet header prototype.
93 #if (LIBNET_LIL_ENDIAN)
94 u_char ip_hl:4, /* header length */
97 #if (LIBNET_BIG_ENDIAN)
98 u_char ip_v:4, /* version */
99 ip_hl:4; /* header length */
101 u_char ip_tos; /* type of service */
102 u_short ip_len; /* total length */
103 u_short ip_id; /* identification */
106 #define IP_RF 0x8000 /* reserved fragment flag */
109 #define IP_DF 0x4000 /* dont fragment flag */
112 #define IP_MF 0x2000 /* more fragments flag */
115 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
117 u_char ip_ttl; /* time to live */
118 u_char ip_p; /* protocol */
119 u_short ip_sum; /* checksum */
120 struct in_addr ip_src, ip_dst; /* source and dest address */
124 * TCP packet header prototype.
126 struct libnet_tcp_hdr
128 u_short th_sport; /* source port */
129 u_short th_dport; /* destination port */
130 u_long th_seq; /* sequence number */
131 u_long th_ack; /* acknowledgement number */
132 #if (LIBNET_LIL_ENDIAN)
133 u_char th_x2:4, /* (unused) */
134 th_off:4; /* data offset */
136 #if (LIBNET_BIG_ENDIAN)
137 u_char th_off:4, /* data offset */
138 th_x2:4; /* (unused) */
140 u_char th_flags; /* control flags */
159 u_short th_win; /* window */
160 u_short th_sum; /* checksum */
161 u_short th_urp; /* urgent pointer */
166 * UDP packet header prototype.
168 struct libnet_udp_hdr
170 u_short uh_sport; /* soure port */
171 u_short uh_dport; /* destination port */
172 u_short uh_ulen; /* length */
173 u_short uh_sum; /* checksum */
178 * ICMP packet header prototype.
180 struct libnet_icmp_hdr
186 #ifndef ICMP_ECHOREPLY
187 #define ICMP_ECHOREPLY 0
190 #define ICMP_UNREACH 3
192 #ifndef ICMP_SOURCEQUENCH
193 #define ICMP_SOURCEQUENCH 4
195 #ifndef ICMP_REDIRECT
196 #define ICMP_REDIRECT 5
201 #ifndef ICMP_ROUTERADVERT
202 #define ICMP_ROUTERADVERT 9
204 #ifndef ICMP_ROUTERSOLICIT
205 #define ICMP_ROUTERSOLICIT 10
207 #ifndef ICMP_TIMXCEED
208 #define ICMP_TIMXCEED 11
210 #ifndef ICMP_PARAMPROB
211 #define ICMP_PARAMPROB 12
214 #define ICMP_TSTAMP 13
216 #ifndef ICMP_TSTAMPREPLY
217 #define ICMP_TSTAMPREPLY 14
222 #ifndef ICMP_IREQREPLY
223 #define ICMP_IREQREPLY 16
226 #define ICMP_MASKREQ 17
228 #ifndef ICMP_MASKREPLY
229 #define ICMP_MASKREPLY 18
235 #ifndef ICMP_UNREACH_NET
236 #define ICMP_UNREACH_NET 0
238 #ifndef ICMP_UNREACH_HOST
239 #define ICMP_UNREACH_HOST 1
241 #ifndef ICMP_UNREACH_PROTOCOL
242 #define ICMP_UNREACH_PROTOCOL 2
244 #ifndef ICMP_UNREACH_PORT
245 #define ICMP_UNREACH_PORT 3
247 #ifndef ICMP_UNREACH_NEEDFRAG
248 #define ICMP_UNREACH_NEEDFRAG 4
250 #ifndef ICMP_UNREACH_SRCFAIL
251 #define ICMP_UNREACH_SRCFAIL 5
253 #ifndef ICMP_UNREACH_NET_UNKNOWN
254 #define ICMP_UNREACH_NET_UNKNOWN 6
256 #ifndef ICMP_UNREACH_HOST_UNKNOWN
257 #define ICMP_UNREACH_HOST_UNKNOWN 7
259 #ifndef ICMP_UNREACH_ISOLATED
260 #define ICMP_UNREACH_ISOLATED 8
262 #ifndef ICMP_UNREACH_NET_PROHIB
263 #define ICMP_UNREACH_NET_PROHIB 9
265 #ifndef ICMP_UNREACH_HOST_PROHIB
266 #define ICMP_UNREACH_HOST_PROHIB 10
268 #ifndef ICMP_UNREACH_TOSNET
269 #define ICMP_UNREACH_TOSNET 11
271 #ifndef ICMP_UNREACH_TOSHOST
272 #define ICMP_UNREACH_TOSHOST 12
274 #ifndef ICMP_UNREACH_FILTER_PROHIB
275 #define ICMP_UNREACH_FILTER_PROHIB 13
277 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
278 #define ICMP_UNREACH_HOST_PRECEDENCE 14
280 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
281 #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
283 #ifndef ICMP_REDIRECT_NET
284 #define ICMP_REDIRECT_NET 0
286 #ifndef ICMP_REDIRECT_HOST
287 #define ICMP_REDIRECT_HOST 1
289 #ifndef ICMP_REDIRECT_TOSNET
290 #define ICMP_REDIRECT_TOSNET 2
292 #ifndef ICMP_REDIRECT_TOSHOST
293 #define ICMP_REDIRECT_TOSHOST 3
295 #ifndef ICMP_TIMXCEED_INTRANS
296 #define ICMP_TIMXCEED_INTRANS 0
298 #ifndef ICMP_TIMXCEED_REASS
299 #define ICMP_TIMXCEED_REASS 1
301 #ifndef ICMP_PARAMPROB_OPTABSENT
302 #define ICMP_PARAMPROB_OPTABSENT 1
317 #define icmp_id hun.echo.id
318 #define icmp_seq hun.echo.seq
338 /* options and then 64 bits of data */
344 #define icmp_mask dun.mask
346 #define icmp_data dun.data
349 #define icmp_otime dun.ts.its_otime
351 #define icmp_rtime dun.ts.its_rtime
353 #define icmp_ttime dun.ts.its_ttime
361 struct libnet_igmp_hdr
364 #ifndef IGMP_MEMBERSHIP_QUERY
365 #define IGMP_MEMBERSHIP_QUERY 0x11 /* membership query */
367 #ifndef IGMP_V1_MEMBERSHIP_REPORT
368 #define IGMP_V1_MEMBERSHIP_REPORT 0x12 /* Ver. 1 membership report */
370 #ifndef IGMP_V2_MEMBERSHIP_REPORT
371 #define IGMP_V2_MEMBERSHIP_REPORT 0x16 /* Ver. 2 membership report */
373 #ifndef IGMP_LEAVE_GROUP
374 #define IGMP_LEAVE_GROUP 0x17 /* Leave-group message */
378 struct in_addr igmp_group;
383 * Ethernet packet header prototype. Too many O/S's define this differently.
384 * Easy enough to solve that and define it here.
386 struct libnet_ethernet_hdr
388 #ifndef ETHER_ADDR_LEN
389 #define ETHER_ADDR_LEN 6
391 u_char ether_dhost[ETHER_ADDR_LEN]; /* destination ethernet address */
392 u_char ether_shost[ETHER_ADDR_LEN]; /* source ethernet address */
393 u_short ether_type; /* packet type ID */
396 #define ETHERTYPE_PUP 0x0200 /* PUP protocol */
397 #define ETHERTYPE_IP 0x0800 /* IP protocol */
398 #define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */
399 #define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */
400 #define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging */
401 #define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */
406 u_char ether_addr_octet[6];
411 * ARP packet header prototype. Too many O/S's define this differently.
412 * Easy enough to solve that and define it here.
414 struct libnet_arp_hdr
416 u_short ar_hrd; /* format of hardware address */
417 #define ARPHRD_ETHER 1 /* ethernet hardware format */
418 u_short ar_pro; /* format of protocol address */
419 u_char ar_hln; /* length of hardware address */
420 u_char ar_pln; /* length of protocol addres */
421 u_short ar_op; /* operation type */
422 #define ARPOP_REQUEST 1 /* req to resolve address */
423 #define ARPOP_REPLY 2 /* resp to previous request */
424 #define ARPOP_REVREQUEST 3 /* req protocol address given hardware */
425 #define ARPOP_REVREPLY 4 /* resp giving protocol address */
426 #define ARPOP_INVREQUEST 8 /* req to identify peer */
427 #define ARPOP_INVREPLY 9 /* resp identifying peer */
430 * These should implementation defined but I've hardcoded eth/IP.
432 u_char ar_sha[6]; /* sender hardware address */
433 u_char ar_spa[4]; /* sender protocol address */
434 u_char ar_tha[6]; /* target hardware address */
435 u_char ar_tpa[4]; /* target protocol address */
442 struct libnet_dns_hdr
444 u_short id; /* DNS packet ID */
445 u_short flags; /* DNS flags */
446 u_short num_q; /* Number of questions */
447 u_short num_answ_rr; /* Number of answer resource records */
448 u_short num_auth_rr; /* Number of authority resource records */
449 u_short num_addi_rr; /* Number of additional resource records */
454 * Base RIP (routing information protocol) header.
456 struct libnet_rip_hdr
458 u_char cmd; /* RIP command */
459 #define RIPCMD_REQUEST 1 /* want info */
460 #define RIPCMD_RESPONSE 2 /* responding to request */
461 #define RIPCMD_TRACEON 3 /* turn tracing on */
462 #define RIPCMD_TRACEOFF 4 /* turn it off */
463 #define RIPCMD_POLL 5 /* like request, but anyone answers */
464 #define RIPCMD_POLLENTRY 6 /* like poll, but for entire entry */
466 u_char ver; /* RIP version */
470 u_short rd; /* Zero (v1) or Routing Domain (v2) */
471 u_short af; /* Address family */
472 u_short rt; /* Zero (v1) or Route Tag (v2) */
473 u_long addr; /* IP address */
474 u_long mask; /* Zero (v1) or Subnet Mask (v2) */
475 u_long next_hop; /* Zero (v1) or Next hop IP address (v2) */
476 u_long metric; /* Metric */
480 * VRRP packet header prototype.
483 #define IPPROTO_VRRP 112
485 struct libnet_vrrp_hdr
487 #if (LIBNET_LIL_ENDIAN)
488 u_char vrrp_v:4, /* protocol version */
489 vrrp_t:4; /* packet type */
491 #if (LIBNET_BIG_ENDIAN)
492 u_char vrrp_t:4, /* packet type */
493 vrrp_v:4; /* protocol version */
495 #define LIBNET_VRRP_TYPE_ADVERT 0x1
496 u_char vrrp_vrouter_id; /* virtual router id */
497 u_char vrrp_priority; /* priority */
498 u_char vrrp_ip_count; /* number of IP addresses */
499 u_char vrrp_auth_type; /* authorization type */
500 #define LIBNET_VRRP_AUTH_NONE 0x1
501 #define LIBNET_VRRP_AUTH_PASSWD 0x2
502 #define LIBNET_VRRP_AUTH_IPAH 0x3
503 u_char vrrp_advert_int; /* advertisement interval */
504 u_short vrrp_sum; /* checksum */
508 struct libnet_snmp_hdr
510 /* ASN.1 BER support first */
516 * TCP options structure.
520 u_char tcpopt_list[MAX_IPOPTLEN];
526 * Linux has a radically different IP options structure from BSD.
530 struct in_addr ipopt_dst; /* first-hop dst if source routed */
531 char ipopt_list[MAX_IPOPTLEN]; /* options proper */
535 #endif /* __LIBNET_HEADERS_H */