1 /* 2 * Copyright (c) 2021-2021 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_IF_H 32 #define _ADAPT_IF_H 33 34 #include <sys/features.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #define IF_NAMESIZE 16 41 42 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 43 44 #include <sys/socket.h> 45 46 #define IFF_UP 0x1 47 #define IFF_BROADCAST 0x2 48 #define IFF_DEBUG 0x4 49 #define IFF_LOOPBACK 0x8 50 #define IFF_POINTOPOINT 0x10 51 #define IFF_NOTRAILERS 0x20 52 #define IFF_RUNNING 0x40 53 #define IFF_NOARP 0x80 54 #define IFF_PROMISC 0x100 55 #define IFF_ALLMULTI 0x200 56 #define IFF_MASTER 0x400 57 #define IFF_SLAVE 0x800 58 #define IFF_MULTICAST 0x1000 59 #define IFF_PORTSEL 0x2000 60 #define IFF_AUTOMEDIA 0x4000 61 #define IFF_DYNAMIC 0x8000 62 #define IFF_LOWER_UP 0x10000 63 #define IFF_DORMANT 0x20000 64 #define IFF_ECHO 0x40000 65 #define IFF_VOLATILE (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_BROADCAST | \ 66 IFF_ECHO | IFF_MASTER | IFF_SLAVE | IFF_RUNNING| \ 67 IFF_LOWER_UP | IFF_DORMANT) 68 69 struct ifaddr { 70 struct sockaddr ifa_addr; 71 union { 72 struct sockaddr ifu_broadaddr; 73 struct sockaddr ifu_dstaddr; 74 } ifa_ifu; 75 struct iface *ifa_ifp; 76 struct ifaddr *ifa_next; 77 }; 78 79 #define ifa_broadaddr ifa_ifu.ifu_broadaddr 80 #define ifa_dstaddr ifa_ifu.ifu_dstaddr 81 82 struct ifmap { 83 unsigned long int mem_start; 84 unsigned long int mem_end; 85 unsigned short int base_addr; 86 unsigned char irq; 87 unsigned char dma; 88 unsigned char port; 89 }; 90 91 #define IFHWADDRLEN 6 92 #define IFNAMSIZ IF_NAMESIZE 93 94 struct ifreq { 95 union { 96 char ifrn_name[IFNAMSIZ]; 97 } ifr_ifrn; 98 union { 99 struct sockaddr ifru_addr; 100 struct sockaddr ifru_dstaddr; 101 struct sockaddr ifru_broadaddr; 102 struct sockaddr ifru_netmask; 103 struct sockaddr ifru_hwaddr; 104 short int ifru_flags; 105 int ifru_ivalue; 106 int ifru_mtu; 107 struct ifmap ifru_map; 108 char ifru_slave[IFNAMSIZ]; 109 char ifru_newname[IFNAMSIZ]; 110 char *ifru_data; 111 } ifr_ifru; 112 }; 113 114 #define ifr_name ifr_ifrn.ifrn_name 115 #define ifr_hwaddr ifr_ifru.ifru_hwaddr 116 #define ifr_addr ifr_ifru.ifru_addr 117 #define ifr_dstaddr ifr_ifru.ifru_dstaddr 118 #define ifr_broadaddr ifr_ifru.ifru_broadaddr 119 #define ifr_netmask ifr_ifru.ifru_netmask 120 #define ifr_flags ifr_ifru.ifru_flags 121 #define ifr_metric ifr_ifru.ifru_ivalue 122 #define ifr_mtu ifr_ifru.ifru_mtu 123 #define ifr_map ifr_ifru.ifru_map 124 #define ifr_slave ifr_ifru.ifru_slave 125 #define ifr_data ifr_ifru.ifru_data 126 #define ifr_ifindex ifr_ifru.ifru_ivalue 127 #define ifr_bandwidth ifr_ifru.ifru_ivalue 128 #define ifr_qlen ifr_ifru.ifru_ivalue 129 #define ifr_newname ifr_ifru.ifru_newname 130 131 struct ifconf { 132 int ifc_len; 133 union { 134 char *ifcu_buf; 135 struct ifreq *ifcu_req; 136 } ifc_ifcu; 137 }; 138 139 #define ifc_buf ifc_ifcu.ifcu_buf 140 #define ifc_req ifc_ifcu.ifcu_req 141 #endif 142 143 struct if_nameindex { 144 unsigned int if_index; 145 char *if_name; 146 }; 147 148 unsigned int if_nametoindex(const char *name); 149 char *if_indextoname(unsigned int index, char *name); 150 struct if_nameindex *if_nameindex(void); 151 void if_freenameindex(struct if_nameindex *ifNameIndex); 152 153 #ifdef __cplusplus 154 } 155 #endif 156 157 #endif /* !_ADAPT_IF_H */ 158