1 /* 2 * Copyright 2006-2012 Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _NET_IF_H 6 #define _NET_IF_H 7 8 9 #include <net/route.h> 10 #include <sys/socket.h> 11 12 13 #define IF_NAMESIZE 32 14 15 /* BSD specific/proprietary part */ 16 17 #define IFNAMSIZ IF_NAMESIZE 18 19 struct ifreq_stream_stats { 20 uint32_t packets; 21 uint32_t errors; 22 uint64_t bytes; 23 uint32_t multicast_packets; 24 uint32_t dropped; 25 }; 26 27 struct ifreq_stats { 28 struct ifreq_stream_stats receive; 29 struct ifreq_stream_stats send; 30 uint32_t collisions; 31 }; 32 33 struct ifreq { 34 char ifr_name[IF_NAMESIZE]; 35 union { 36 struct sockaddr ifr_addr; 37 struct sockaddr ifr_dstaddr; 38 struct sockaddr ifr_broadaddr; 39 struct sockaddr ifr_mask; 40 struct ifreq_stats ifr_stats; 41 struct route_entry ifr_route; 42 int ifr_flags; 43 int ifr_index; 44 int ifr_metric; 45 int ifr_mtu; 46 int ifr_media; 47 int ifr_type; 48 int ifr_reqcap; 49 int ifr_count; 50 uint8_t* ifr_data; 51 }; 52 }; 53 54 /* used with SIOC_IF_ALIAS_ADD, SIOC_IF_ALIAS_GET, SIOC_ALIAS_SET */ 55 struct ifaliasreq { 56 char ifra_name[IF_NAMESIZE]; 57 int ifra_index; 58 struct sockaddr_storage ifra_addr; 59 union { 60 struct sockaddr_storage ifra_broadaddr; 61 struct sockaddr_storage ifra_destination; 62 }; 63 struct sockaddr_storage ifra_mask; 64 uint32_t ifra_flags; 65 }; 66 67 68 /* interface flags */ 69 #define IFF_UP 0x0001 70 #define IFF_BROADCAST 0x0002 /* valid broadcast address */ 71 #define IFF_LOOPBACK 0x0008 72 #define IFF_POINTOPOINT 0x0010 /* point-to-point link */ 73 #define IFF_NOARP 0x0040 /* no address resolution */ 74 #define IFF_AUTOUP 0x0080 /* auto dial */ 75 #define IFF_PROMISC 0x0100 /* receive all packets */ 76 #define IFF_ALLMULTI 0x0200 /* receive all multicast packets */ 77 #define IFF_SIMPLEX 0x0800 /* doesn't receive own transmissions */ 78 #define IFF_LINK 0x1000 /* has link */ 79 #define IFF_AUTO_CONFIGURED 0x2000 80 #define IFF_CONFIGURING 0x4000 81 #define IFF_MULTICAST 0x8000 /* supports multicast */ 82 83 /* interface alias flags */ 84 #define IFAF_AUTO_CONFIGURED 0x0001 /* has been automatically configured */ 85 #define IFAF_CONFIGURING 0x0002 /* auto configuration in progress */ 86 87 88 /* used with SIOCGIFCOUNT, and SIOCGIFCONF */ 89 struct ifconf { 90 int ifc_len; /* size of buffer */ 91 union { 92 void* ifc_buf; 93 struct ifreq* ifc_req; 94 int ifc_value; 95 }; 96 }; 97 98 /* Macro that returns the size of a single address within a SIOCGIFCONF buffer; 99 it looks like this because of compatibility with other platforms. */ 100 #define _SIZEOF_ADDR_IFREQ(request) \ 101 (IF_NAMESIZE + (request).ifr_addr.sa_len > (int)sizeof(struct ifreq) \ 102 ? IF_NAMESIZE + (request).ifr_addr.sa_len : sizeof(struct ifreq)) 103 104 105 /* POSIX definitions follow */ 106 107 struct if_nameindex { 108 unsigned if_index; /* positive interface index */ 109 char* if_name; /* interface name, ie. "loopback" */ 110 }; 111 112 113 #ifdef __cplusplus 114 extern "C" { 115 #endif 116 117 unsigned if_nametoindex(const char* name); 118 char* if_indextoname(unsigned interfaceIndex, char* nameBuffer); 119 struct if_nameindex* if_nameindex(void); 120 void if_freenameindex(struct if_nameindex* interfaceArray); 121 122 #ifdef __cplusplus 123 } 124 #endif 125 126 127 #endif /* _NET_IF_H */ 128