OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / include / libnet / libnet-headers.h
1 /*
2  *  $Id: libnet-headers.h,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
3  *
4  *  libnet-headers.h - Network routine library headers header file
5  *
6  *  Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
7  *  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
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.
17  *
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
28  * SUCH DAMAGE.
29  *
30  */
31
32 #ifndef __LIBNET_HEADERS_H
33 #define __LIBNET_HEADERS_H
34
35 #include <endian.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
42 #else
43 #error "unknown endian"
44 #endif
45
46
47 /* 
48  *  Standard (IPv4) header sizes in bytes.
49  */
50
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 */
68
69 /*
70  *  Concession to legacy naming scheme.
71  */
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
87
88 /*
89  *  IPv4 packet header prototype.
90  */
91 struct libnet_ip_hdr
92 {
93 #if (LIBNET_LIL_ENDIAN)
94     u_char ip_hl:4,         /* header length */
95             ip_v:4;         /* version */
96 #endif
97 #if (LIBNET_BIG_ENDIAN)
98     u_char ip_v:4,          /* version */
99             ip_hl:4;        /* header length */
100 #endif
101     u_char ip_tos;          /* type of service */
102     u_short ip_len;         /* total length */
103     u_short ip_id;          /* identification */
104     u_short ip_off;
105 #ifndef IP_RF
106 #define IP_RF 0x8000        /* reserved fragment flag */
107 #endif
108 #ifndef IP_DF
109 #define IP_DF 0x4000        /* dont fragment flag */
110 #endif
111 #ifndef IP_MF
112 #define IP_MF 0x2000        /* more fragments flag */
113 #endif 
114 #ifndef IP_OFFMASK
115 #define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
116 #endif
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 */
121 };
122
123 /*
124  *  TCP packet header prototype.
125  */
126 struct libnet_tcp_hdr
127 {
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 */
135 #endif
136 #if (LIBNET_BIG_ENDIAN)
137     u_char th_off:4,        /* data offset */
138            th_x2:4;         /* (unused) */
139 #endif
140     u_char  th_flags;       /* control flags */
141 #ifndef TH_FIN
142 #define TH_FIN    0x01
143 #endif
144 #ifndef TH_SYN
145 #define TH_SYN    0x02
146 #endif
147 #ifndef TH_RST
148 #define TH_RST    0x04
149 #endif
150 #ifndef TH_PUSH
151 #define TH_PUSH   0x08
152 #endif
153 #ifndef TH_ACK
154 #define TH_ACK    0x10
155 #endif
156 #ifndef TH_URG
157 #define TH_URG    0x20
158 #endif
159     u_short th_win;         /* window */
160     u_short th_sum;         /* checksum */
161     u_short th_urp;         /* urgent pointer */
162 };
163
164
165 /*
166  *  UDP packet header prototype.
167  */
168 struct libnet_udp_hdr
169 {
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 */
174 };
175
176
177 /*
178  *  ICMP packet header prototype.
179  */
180 struct libnet_icmp_hdr
181 {
182     u_char icmp_type;
183 /*
184  *  ICMP types.
185  */
186 #ifndef     ICMP_ECHOREPLY
187 #define     ICMP_ECHOREPLY                  0
188 #endif
189 #ifndef     ICMP_UNREACH
190 #define     ICMP_UNREACH                    3
191 #endif
192 #ifndef     ICMP_SOURCEQUENCH
193 #define     ICMP_SOURCEQUENCH               4
194 #endif
195 #ifndef     ICMP_REDIRECT
196 #define     ICMP_REDIRECT                   5
197 #endif
198 #ifndef     ICMP_ECHO
199 #define     ICMP_ECHO                       8
200 #endif
201 #ifndef     ICMP_ROUTERADVERT
202 #define     ICMP_ROUTERADVERT               9
203 #endif
204 #ifndef     ICMP_ROUTERSOLICIT
205 #define     ICMP_ROUTERSOLICIT              10
206 #endif
207 #ifndef     ICMP_TIMXCEED
208 #define     ICMP_TIMXCEED                   11
209 #endif
210 #ifndef     ICMP_PARAMPROB
211 #define     ICMP_PARAMPROB                  12
212 #endif
213 #ifndef     ICMP_TSTAMP
214 #define     ICMP_TSTAMP                     13
215 #endif
216 #ifndef     ICMP_TSTAMPREPLY
217 #define     ICMP_TSTAMPREPLY                14
218 #endif
219 #ifndef     ICMP_IREQ
220 #define     ICMP_IREQ                       15
221 #endif
222 #ifndef     ICMP_IREQREPLY
223 #define     ICMP_IREQREPLY                  16
224 #endif
225 #ifndef     ICMP_MASKREQ
226 #define     ICMP_MASKREQ                    17
227 #endif
228 #ifndef     ICMP_MASKREPLY
229 #define     ICMP_MASKREPLY                  18
230 #endif
231     u_char icmp_code;
232 /*
233  *  ICMP codes.
234  */
235 #ifndef     ICMP_UNREACH_NET
236 #define     ICMP_UNREACH_NET                0
237 #endif
238 #ifndef     ICMP_UNREACH_HOST
239 #define     ICMP_UNREACH_HOST               1
240 #endif
241 #ifndef     ICMP_UNREACH_PROTOCOL
242 #define     ICMP_UNREACH_PROTOCOL           2
243 #endif
244 #ifndef     ICMP_UNREACH_PORT
245 #define     ICMP_UNREACH_PORT               3
246 #endif
247 #ifndef     ICMP_UNREACH_NEEDFRAG
248 #define     ICMP_UNREACH_NEEDFRAG           4
249 #endif
250 #ifndef     ICMP_UNREACH_SRCFAIL
251 #define     ICMP_UNREACH_SRCFAIL            5
252 #endif
253 #ifndef     ICMP_UNREACH_NET_UNKNOWN
254 #define     ICMP_UNREACH_NET_UNKNOWN        6
255 #endif
256 #ifndef     ICMP_UNREACH_HOST_UNKNOWN
257 #define     ICMP_UNREACH_HOST_UNKNOWN       7
258 #endif
259 #ifndef     ICMP_UNREACH_ISOLATED
260 #define     ICMP_UNREACH_ISOLATED           8
261 #endif
262 #ifndef     ICMP_UNREACH_NET_PROHIB
263 #define     ICMP_UNREACH_NET_PROHIB         9
264 #endif
265 #ifndef     ICMP_UNREACH_HOST_PROHIB
266 #define     ICMP_UNREACH_HOST_PROHIB        10
267 #endif
268 #ifndef     ICMP_UNREACH_TOSNET
269 #define     ICMP_UNREACH_TOSNET             11
270 #endif
271 #ifndef     ICMP_UNREACH_TOSHOST
272 #define     ICMP_UNREACH_TOSHOST            12
273 #endif
274 #ifndef     ICMP_UNREACH_FILTER_PROHIB
275 #define     ICMP_UNREACH_FILTER_PROHIB      13
276 #endif
277 #ifndef     ICMP_UNREACH_HOST_PRECEDENCE
278 #define     ICMP_UNREACH_HOST_PRECEDENCE    14
279 #endif
280 #ifndef     ICMP_UNREACH_PRECEDENCE_CUTOFF
281 #define     ICMP_UNREACH_PRECEDENCE_CUTOFF  15
282 #endif
283 #ifndef     ICMP_REDIRECT_NET
284 #define     ICMP_REDIRECT_NET               0
285 #endif
286 #ifndef     ICMP_REDIRECT_HOST
287 #define     ICMP_REDIRECT_HOST              1
288 #endif
289 #ifndef     ICMP_REDIRECT_TOSNET
290 #define     ICMP_REDIRECT_TOSNET            2
291 #endif
292 #ifndef     ICMP_REDIRECT_TOSHOST
293 #define     ICMP_REDIRECT_TOSHOST           3
294 #endif
295 #ifndef     ICMP_TIMXCEED_INTRANS
296 #define     ICMP_TIMXCEED_INTRANS           0
297 #endif
298 #ifndef     ICMP_TIMXCEED_REASS
299 #define     ICMP_TIMXCEED_REASS             1
300 #endif
301 #ifndef     ICMP_PARAMPROB_OPTABSENT
302 #define     ICMP_PARAMPROB_OPTABSENT        1
303 #endif
304
305     u_short icmp_sum;
306
307     union
308     {
309         struct
310         {
311             u_short id;
312             u_short seq;
313         }echo;
314
315 #undef icmp_id
316 #undef icmp_seq
317 #define icmp_id     hun.echo.id
318 #define icmp_seq    hun.echo.seq
319  
320         u_long gateway;
321         struct
322         {
323             u_short pad;
324             u_short mtu;
325         }frag;
326     }hun;
327     union
328     {
329         struct
330         {
331             n_time its_otime;
332             n_time its_rtime;
333             n_time its_ttime;
334         }ts;
335         struct
336         {
337             struct ip idi_ip;
338             /* options and then 64 bits of data */
339         }ip;
340         u_long mask;
341         char data[1];
342
343 #undef icmp_mask
344 #define icmp_mask    dun.mask
345 #undef icmp_data
346 #define icmp_data    dun.data
347
348 #undef icmp_otime
349 #define icmp_otime   dun.ts.its_otime
350 #undef icmp_rtime
351 #define icmp_rtime   dun.ts.its_rtime
352 #undef icmp_ttime
353 #define icmp_ttime   dun.ts.its_ttime
354     }dun;
355 };
356
357
358 /*
359  *  IGMP header.
360  */
361 struct libnet_igmp_hdr
362 {
363     u_char igmp_type;
364 #ifndef IGMP_MEMBERSHIP_QUERY
365 #define IGMP_MEMBERSHIP_QUERY           0x11    /* membership query */
366 #endif
367 #ifndef IGMP_V1_MEMBERSHIP_REPORT
368 #define IGMP_V1_MEMBERSHIP_REPORT       0x12    /* Ver. 1 membership report */
369 #endif
370 #ifndef IGMP_V2_MEMBERSHIP_REPORT
371 #define IGMP_V2_MEMBERSHIP_REPORT       0x16    /* Ver. 2 membership report */
372 #endif
373 #ifndef IGMP_LEAVE_GROUP
374 #define IGMP_LEAVE_GROUP                0x17    /* Leave-group message */
375 #endif
376     u_char igmp_code;
377     u_short igmp_sum;
378     struct in_addr igmp_group;
379 };
380
381
382 /* 
383  *  Ethernet packet header prototype.  Too many O/S's define this differently.
384  *  Easy enough to solve that and define it here.
385  */
386 struct libnet_ethernet_hdr
387 {
388 #ifndef ETHER_ADDR_LEN
389 #define ETHER_ADDR_LEN 6
390 #endif
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 */
394 };
395
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 */
402
403 #if (!__GLIBC__)
404 struct ether_addr
405 {
406     u_char  ether_addr_octet[6];
407 };
408 #endif
409
410 /* 
411  *  ARP packet header prototype.  Too many O/S's define this differently.
412  *  Easy enough to solve that and define it here.
413  */
414 struct libnet_arp_hdr
415 {
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 */
428
429     /*
430      *  These should implementation defined but I've hardcoded eth/IP.
431      */
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 */
436 };
437
438
439 /*
440  *  Base DNS header.
441  */
442 struct libnet_dns_hdr
443 {
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 */
450 };
451
452
453 /*
454  *  Base RIP (routing information protocol) header.
455  */
456 struct libnet_rip_hdr
457 {
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 */
465 #define RIPCMD_MAX          7
466     u_char ver;             /* RIP version */
467 #define RIPVER_0            0
468 #define RIPVER_1            1
469 #define RIPVER_2            2
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 */
477 };
478
479 /*
480  *  VRRP packet header prototype.
481  */
482 #ifndef IPPROTO_VRRP
483 #define IPPROTO_VRRP 112
484 #endif
485 struct libnet_vrrp_hdr
486 {
487 #if (LIBNET_LIL_ENDIAN)
488     u_char vrrp_v:4,        /* protocol version */
489            vrrp_t:4;        /* packet type */
490 #endif
491 #if (LIBNET_BIG_ENDIAN)
492     u_char vrrp_t:4,        /* packet type */
493            vrrp_v:4;        /* protocol version */
494 #endif
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 */
505 };
506
507 #if 0
508 struct libnet_snmp_hdr
509 {
510     /* ASN.1 BER support first */
511 };
512 #endif
513
514
515 /*
516  *  TCP options structure.
517  */
518 struct tcpoption
519 {
520     u_char tcpopt_list[MAX_IPOPTLEN];
521 };
522
523
524 #if (__linux__)
525 /*
526  *  Linux has a radically different IP options structure from BSD.
527  */
528 struct ipoption
529 {
530     struct  in_addr ipopt_dst;          /* first-hop dst if source routed */
531     char ipopt_list[MAX_IPOPTLEN];      /* options proper */
532 };
533 #endif
534
535 #endif  /* __LIBNET_HEADERS_H */
536
537 /* EOF */