Debian Codegraph @

share/libc/net/if.h

raw
1 /**************************************************************************/
2 /* */
3 /* This file is part of Frama-C. */
4 /* */
5 /* Copyright (C) 2007-2022 */
6 /* CEA (Commissariat à l'énergie atomique et aux énergies */
7 /* alternatives) */
8 /* */
9 /* you can redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation, version 2.1. */
12 /* */
13 /* It is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU Lesser General Public License for more details. */
17 /* */
18 /* See the GNU Lesser General Public License version 2.1 */
19 /* for more details (enclosed in the file licenses/LGPLv2.1). */
20 /* */
21 /**************************************************************************/
22
23 #ifndef FC_NET_IF
24 #define FC_NET_IF
25 #include "../features.h"
26 __PUSH_FC_STDLIB
27 __BEGIN_DECLS
28
29 #include "sys/socket.h"
30
31 struct if_nameidx {unsigned if_index; char *if_name;};
32 #define IF_NAMESIZE 16
33 extern unsigned if_nametoindex(const char * name);
34 extern char *if_indextoname(unsigned index, char *name);
35 extern struct if_nameindex *if_nameindex(void);
36 extern void if_freenameindex(struct if_nameindex *ni);
37 #define IFF_UP 0x1 /* interface is up */
38 #define IFF_BROADCAST 0x2 /* broadcast address valid */
39 #define IFF_DEBUG 0x4 /* turn on debugging */
40 #define IFF_LOOPBACK 0x8 /* is a loopback net */
41 #define IFF_POINTOPOINT 0x10 /* interface is has p-p link */
42 #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
43 #define IFF_RUNNING 0x40 /* interface RFC2863 OPER_UP */
44 #define IFF_NOARP 0x80 /* no ARP protocol */
45 #define IFF_PROMISC 0x100 /* receive all packets */
46 #define IFF_ALLMULTI 0x200 /* receive all multicast packets*/
47
48 #define IFF_MASTER 0x400 /* master of a load balancer */
49 #define IFF_SLAVE 0x800 /* slave of a load balancer */
50
51 #define IFF_MULTICAST 0x1000 /* Supports multicast */
52
53 #define IFF_PORTSEL 0x2000 /* can set media type */
54 #define IFF_AUTOMEDIA 0x4000 /* auto media select active */
55 #define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses*/
56
57 #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */
58 #define IFF_DORMANT 0x20000 /* driver signals dormant */
59
60 #define IFF_ECHO 0x40000 /* echo sent packets */
61
62 #define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_ECHO|\
63 IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)
64
65
66 /* The ifaddr structure contains information about one address of an
67 interface. They are maintained by the different address families,
68 are allocated and attached when an address is set, and are linked
69 together so all addresses for an interface can be located. */
70
71 struct ifaddr
72 {
73 struct sockaddr ifa_addr; /* Address of interface. */
74 union __fc_ifa_ifu
75 {
76 struct sockaddr ifu_broadaddr;
77 struct sockaddr ifu_dstaddr;
78 } ifa_ifu;
79 struct iface *ifa_ifp; /* Back-pointer to interface. */
80 struct ifaddr *ifa_next; /* Next address for interface. */
81 };
82
83 #if 0 /* NOTE: Conflicts with file ifaddrs.h */
84 # define ifa_broadaddr ifa_ifu.ifu_broadaddr /* broadcast address */
85 # define ifa_dstaddr ifa_ifu.ifu_dstaddr /* other end of link */
86 #endif
87
88 /* Device mapping structure. I'd just gone off and designed a
89 beautiful scheme using only loadable modules with arguments for
90 driver options and along come the PCMCIA people 8)
91
92 Ah well. The get() side of this is good for WDSETUP, and it'll be
93 handy for debugging things. The set side is fine for now and being
94 very small might be worth keeping for clean configuration. */
95
96 struct ifmap {
97 unsigned long int mem_start;
98 unsigned long int mem_end;
99 unsigned short int base_addr;
100 unsigned char irq;
101 unsigned char dma;
102 unsigned char port;
103 /* 3 bytes spare */
104 };
105
106
107 /* Interface request structure used for socket ioctl's. All interface
108 ioctl's must have parameter definitions which begin with ifr_name.
109 The remainder may be interface specific. */
110
111 struct ifreq {
112 # define IFHWADDRLEN 6
113 # define IFNAMSIZ IF_NAMESIZE
114 union __fc_ifr_ifrn {
115 char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0". */
116 } ifr_ifrn;
117
118 union __fc_ifr_ifru {
119 struct sockaddr ifru_addr;
120 struct sockaddr ifru_dstaddr;
121 struct sockaddr ifru_broadaddr;
122 struct sockaddr ifru_netmask;
123 struct sockaddr ifru_hwaddr;
124 short int ifru_flags;
125 int ifru_ivalue;
126 int ifru_mtu;
127 struct ifmap ifru_map;
128 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
129 char ifru_newname[IFNAMSIZ];
130 char * ifru_data;
131 } ifr_ifru;
132 };
133
134 # define ifr_name ifr_ifrn.ifrn_name /* interface name */
135 # define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
136 # define ifr_addr ifr_ifru.ifru_addr /* address */
137 # define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-p lnk */
138 # define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
139 # define ifr_netmask ifr_ifru.ifru_netmask /* interface net mask */
140 # define ifr_flags ifr_ifru.ifru_flags /* flags */
141 # define ifr_metric ifr_ifru.ifru_ivalue /* metric */
142 # define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
143 # define ifr_map ifr_ifru.ifru_map /* device map */
144 # define ifr_slave ifr_ifru.ifru_slave /* slave device */
145 # define ifr_data ifr_ifru.ifru_data /* for use by interface */
146 # define ifr_ifindex ifr_ifru.ifru_ivalue /* interface index */
147 # define ifr_bandwidth ifr_ifru.ifru_ivalue /* link bandwidth */
148 # define ifr_qlen ifr_ifru.ifru_ivalue /* queue length */
149 # define ifr_newname ifr_ifru.ifru_newname /* New name */
150 # define _IOT_ifreq _IOT(_IOTS(char),IFNAMSIZ,_IOTS(char),16,0,0)
151 # define _IOT_ifreq_short _IOT(_IOTS(char),IFNAMSIZ,_IOTS(short),1,0,0)
152 # define _IOT_ifreq_int _IOT(_IOTS(char),IFNAMSIZ,_IOTS(int),1,0,0)
153
154 struct ifconf
155 {
156 int ifc_len; /* Size of buffer. */
157 union __fc_ifc_ifcu
158 {
159 char *ifcu_buf;
160 struct ifreq *ifcu_req;
161 } ifc_ifcu;
162 };
163 # define ifc_buf ifc_ifcu.ifcu_buf /* Buffer address. */
164 # define ifc_req ifc_ifcu.ifcu_req /* Array of structures. */
165
166 __END_DECLS
167 __POP_FC_STDLIB
168
169 #endif