• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _ADAPT_NET_ETHERNET_H
32 #define _ADAPT_NET_ETHERNET_H
33 
34 #include <stdint.h>
35 #include <sys/types.h>
36 #include <netinet/if_ether.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #define ETHERTYPE_PUP       0x0200
43 #define ETHERTYPE_SPRITE    0x0500
44 #define ETHERTYPE_IP        0x0800
45 #define ETHERTYPE_ARP       0x0806
46 #define ETHERTYPE_REVARP    0x8035
47 #define ETHERTYPE_AT        0x809B
48 #define ETHERTYPE_AARP      0x80F3
49 #define ETHERTYPE_VLAN      0x8100
50 #define ETHERTYPE_IPX       0x8137
51 #define ETHERTYPE_IPV6      0x86dd
52 
53 #define ETHER_ADDR_LEN      ETH_ALEN
54 #define ETHER_TYPE_LEN      ETH_TLEN
55 #define ETHER_CRC_LEN       4
56 #define ETHER_HDR_LEN       ETH_HLEN
57 #define ETHER_MIN_LEN       (ETH_ZLEN + ETHER_CRC_LEN)
58 #define ETHER_MAX_LEN       (ETH_FRAME_LEN + ETHER_CRC_LEN)
59 
60 #define ETHER_IS_VALID_LEN(foo)     ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
61 
62 #define ETHERTYPE_TRAIL     0x1000
63 #define ETHERTYPE_NTRAILER  16
64 
65 #define ETHERMTU            ETH_DATA_LEN
66 #define ETHERMIN            (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
67 
68 struct ether_addr {
69     uint8_t ether_addr_octet[ETH_ALEN];
70 };
71 
72 struct ether_header {
73     uint8_t  ether_dhost[ETH_ALEN];
74     uint8_t  ether_shost[ETH_ALEN];
75     uint16_t ether_type;
76 };
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif /* !_ADAPT_NET_ETHERNET_H */
83