vfs: check userland buffers before reading them.
[haiku.git] / headers / posix / net / if.h
blob80522f2bc814f57e12aed137e080a30d3a445d48
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
9 #include <net/route.h>
10 #include <sys/socket.h>
13 #define IF_NAMESIZE 32
15 /* BSD specific/proprietary part */
17 #define IFNAMSIZ IF_NAMESIZE
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;
27 struct ifreq_stats {
28 struct ifreq_stream_stats receive;
29 struct ifreq_stream_stats send;
30 uint32_t collisions;
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;
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;
63 struct sockaddr_storage ifra_mask;
64 uint32_t ifra_flags;
67 /* used with SIOCGIFMEDIA */
68 struct ifmediareq {
69 char ifm_name[IF_NAMESIZE];
70 int ifm_current;
71 int ifm_mask;
72 int ifm_status;
73 int ifm_active;
74 int ifm_count;
75 int* ifm_ulist;
79 /* interface flags */
80 #define IFF_UP 0x0001
81 #define IFF_BROADCAST 0x0002 /* valid broadcast address */
82 #define IFF_LOOPBACK 0x0008
83 #define IFF_POINTOPOINT 0x0010 /* point-to-point link */
84 #define IFF_NOARP 0x0040 /* no address resolution */
85 #define IFF_AUTOUP 0x0080 /* auto dial */
86 #define IFF_PROMISC 0x0100 /* receive all packets */
87 #define IFF_ALLMULTI 0x0200 /* receive all multicast packets */
88 #define IFF_SIMPLEX 0x0800 /* doesn't receive own transmissions */
89 #define IFF_LINK 0x1000 /* has link */
90 #define IFF_AUTO_CONFIGURED 0x2000
91 #define IFF_CONFIGURING 0x4000
92 #define IFF_MULTICAST 0x8000 /* supports multicast */
94 /* interface alias flags */
95 #define IFAF_AUTO_CONFIGURED 0x0001 /* has been automatically configured */
96 #define IFAF_CONFIGURING 0x0002 /* auto configuration in progress */
99 /* used with SIOCGIFCOUNT, and SIOCGIFCONF */
100 struct ifconf {
101 int ifc_len; /* size of buffer */
102 union {
103 void* ifc_buf;
104 struct ifreq* ifc_req;
105 int ifc_value;
109 /* Macro that returns the size of a single address within a SIOCGIFCONF buffer;
110 it looks like this because of compatibility with other platforms. */
111 #define _SIZEOF_ADDR_IFREQ(request) \
112 (IF_NAMESIZE + (request).ifr_addr.sa_len > (int)sizeof(struct ifreq) \
113 ? IF_NAMESIZE + (request).ifr_addr.sa_len : sizeof(struct ifreq))
116 /* POSIX definitions follow */
118 struct if_nameindex {
119 unsigned if_index; /* positive interface index */
120 char* if_name; /* interface name, ie. "loopback" */
124 #ifdef __cplusplus
125 extern "C" {
126 #endif
128 unsigned if_nametoindex(const char* name);
129 char* if_indextoname(unsigned interfaceIndex, char* nameBuffer);
130 struct if_nameindex* if_nameindex(void);
131 void if_freenameindex(struct if_nameindex* interfaceArray);
133 #ifdef __cplusplus
135 #endif
138 #endif /* _NET_IF_H */