Fix weight comparison in edge BFS
[tinc] / src / ethernet.h
1 #ifndef TINC_ETHERNET_H
2 #define TINC_ETHERNET_H
3
4 /*
5     ethernet.h -- missing Ethernet related definitions
6     Copyright (C) 2005 Ivo Timmermans
7                   2006 Guus Sliepen <guus@tinc-vpn.org>
8
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License along
20     with this program; if not, write to the Free Software Foundation, Inc.,
21     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24 #include "system.h"
25
26 #ifndef ETH_ALEN
27 #define ETH_ALEN 6
28 #endif
29
30 #ifndef ETH_HLEN
31 #define ETH_HLEN 14
32 #endif
33
34 #ifndef ETHER_TYPE_LEN
35 #define ETHER_TYPE_LEN 2
36 #endif
37
38
39 #ifndef ARPHRD_ETHER
40 #define ARPHRD_ETHER 1
41 #endif
42
43 #ifndef ETH_P_IP
44 #define ETH_P_IP 0x0800
45 #endif
46
47 #ifndef ETH_P_ARP
48 #define ETH_P_ARP 0x0806
49 #endif
50
51 #ifndef ETH_P_IPV6
52 #define ETH_P_IPV6 0x86DD
53 #endif
54
55 #ifndef ETH_P_8021Q
56 #define ETH_P_8021Q 0x8100
57 #endif
58
59 #ifndef ETH_P_MAX
60 #define ETH_P_MAX 0xFFFF
61 #endif
62
63 #ifndef HAVE_STRUCT_ETHER_HEADER
64 PACKED(struct ether_header {
65         uint8_t ether_dhost[ETH_ALEN];
66         uint8_t ether_shost[ETH_ALEN];
67         uint16_t ether_type;
68 });
69 #endif
70
71 STATIC_ASSERT(sizeof(struct ether_header) == 14, "ether_header has incorrect size");
72
73 #ifndef HAVE_STRUCT_ARPHDR
74 PACKED(struct arphdr {
75         uint16_t ar_hrd;
76         uint16_t ar_pro;
77         uint8_t ar_hln;
78         uint8_t ar_pln;
79         uint16_t ar_op;
80 });
81 #define ARPOP_REQUEST 1
82 #define ARPOP_REPLY 2
83 #define ARPOP_RREQUEST 3
84 #define ARPOP_RREPLY 4
85 #define ARPOP_InREQUEST 8
86 #define ARPOP_InREPLY 9
87 #define ARPOP_NAK 10
88 #endif
89
90 STATIC_ASSERT(sizeof(struct arphdr) == 8, "arphdr has incorrect size");
91
92 #ifndef HAVE_STRUCT_ETHER_ARP
93 PACKED(struct ether_arp {
94         struct  arphdr ea_hdr;
95         uint8_t arp_sha[ETH_ALEN];
96         uint8_t arp_spa[4];
97         uint8_t arp_tha[ETH_ALEN];
98         uint8_t arp_tpa[4];
99 });
100 #define arp_hrd ea_hdr.ar_hrd
101 #define arp_pro ea_hdr.ar_pro
102 #define arp_hln ea_hdr.ar_hln
103 #define arp_pln ea_hdr.ar_pln
104 #define arp_op ea_hdr.ar_op
105 #endif
106
107 STATIC_ASSERT(sizeof(struct ether_arp) == 28, "ether_arp has incorrect size");
108
109 #endif