if.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* net/if.h -- declarations for inquiring about network interfaces
  2. Copyright (C) 1997,98,99,2000,2001 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _NET_IF_H
  17. #define _NET_IF_H 1
  18. #include <features.h>
  19. #ifdef __USE_MISC
  20. # include <sys/types.h>
  21. # include <sys/socket.h>
  22. #endif
  23. /* Length of interface name. */
  24. #define IF_NAMESIZE 16
  25. struct if_nameindex
  26. {
  27. unsigned int if_index; /* 1, 2, ... */
  28. char *if_name; /* null terminated name: "eth0", ... */
  29. };
  30. #ifdef __USE_MISC
  31. /* Standard interface flags. */
  32. enum
  33. {
  34. IFF_UP = 0x1, /* Interface is up. */
  35. # define IFF_UP IFF_UP
  36. IFF_BROADCAST = 0x2, /* Broadcast address valid. */
  37. # define IFF_BROADCAST IFF_BROADCAST
  38. IFF_DEBUG = 0x4, /* Turn on debugging. */
  39. # define IFF_DEBUG IFF_DEBUG
  40. IFF_LOOPBACK = 0x8, /* Is a loopback net. */
  41. # define IFF_LOOPBACK IFF_LOOPBACK
  42. IFF_POINTOPOINT = 0x10, /* Interface is point-to-point link. */
  43. # define IFF_POINTOPOINT IFF_POINTOPOINT
  44. IFF_NOTRAILERS = 0x20, /* Avoid use of trailers. */
  45. # define IFF_NOTRAILERS IFF_NOTRAILERS
  46. IFF_RUNNING = 0x40, /* Resources allocated. */
  47. # define IFF_RUNNING IFF_RUNNING
  48. IFF_NOARP = 0x80, /* No address resolution protocol. */
  49. # define IFF_NOARP IFF_NOARP
  50. IFF_PROMISC = 0x100, /* Receive all packets. */
  51. # define IFF_PROMISC IFF_PROMISC
  52. /* Not supported */
  53. IFF_ALLMULTI = 0x200, /* Receive all multicast packets. */
  54. # define IFF_ALLMULTI IFF_ALLMULTI
  55. IFF_MASTER = 0x400, /* Master of a load balancer. */
  56. # define IFF_MASTER IFF_MASTER
  57. IFF_SLAVE = 0x800, /* Slave of a load balancer. */
  58. # define IFF_SLAVE IFF_SLAVE
  59. IFF_MULTICAST = 0x1000, /* Supports multicast. */
  60. # define IFF_MULTICAST IFF_MULTICAST
  61. IFF_PORTSEL = 0x2000, /* Can set media type. */
  62. # define IFF_PORTSEL IFF_PORTSEL
  63. IFF_AUTOMEDIA = 0x4000 /* Auto media select active. */
  64. # define IFF_AUTOMEDIA IFF_AUTOMEDIA
  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. struct ifaddr
  71. {
  72. struct sockaddr ifa_addr; /* Address of interface. */
  73. union
  74. {
  75. struct sockaddr ifu_broadaddr;
  76. struct sockaddr ifu_dstaddr;
  77. } ifa_ifu;
  78. struct iface *ifa_ifp; /* Back-pointer to interface. */
  79. struct ifaddr *ifa_next; /* Next address for interface. */
  80. };
  81. # define ifa_broadaddr ifa_ifu.ifu_broadaddr /* broadcast address */
  82. # define ifa_dstaddr ifa_ifu.ifu_dstaddr /* other end of link */
  83. /* Device mapping structure. I'd just gone off and designed a
  84. beautiful scheme using only loadable modules with arguments for
  85. driver options and along come the PCMCIA people 8)
  86. Ah well. The get() side of this is good for WDSETUP, and it'll be
  87. handy for debugging things. The set side is fine for now and being
  88. very small might be worth keeping for clean configuration. */
  89. struct ifmap
  90. {
  91. unsigned long int mem_start;
  92. unsigned long int mem_end;
  93. unsigned short int base_addr;
  94. unsigned char irq;
  95. unsigned char dma;
  96. unsigned char port;
  97. /* 3 bytes spare */
  98. };
  99. /* Interface request structure used for socket ioctl's. All interface
  100. ioctl's must have parameter definitions which begin with ifr_name.
  101. The remainder may be interface specific. */
  102. struct ifreq
  103. {
  104. # define IFHWADDRLEN 6
  105. # define IFNAMSIZ IF_NAMESIZE
  106. union
  107. {
  108. char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0". */
  109. } ifr_ifrn;
  110. union
  111. {
  112. struct sockaddr ifru_addr;
  113. struct sockaddr ifru_dstaddr;
  114. struct sockaddr ifru_broadaddr;
  115. struct sockaddr ifru_netmask;
  116. struct sockaddr ifru_hwaddr;
  117. short int ifru_flags;
  118. int ifru_ivalue;
  119. int ifru_mtu;
  120. struct ifmap ifru_map;
  121. char ifru_slave[IFNAMSIZ]; /* Just fits the size */
  122. char ifru_newname[IFNAMSIZ];
  123. __caddr_t ifru_data;
  124. } ifr_ifru;
  125. };
  126. # define ifr_name ifr_ifrn.ifrn_name /* interface name */
  127. # define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
  128. # define ifr_addr ifr_ifru.ifru_addr /* address */
  129. # define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-p lnk */
  130. # define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
  131. # define ifr_netmask ifr_ifru.ifru_netmask /* interface net mask */
  132. # define ifr_flags ifr_ifru.ifru_flags /* flags */
  133. # define ifr_metric ifr_ifru.ifru_ivalue /* metric */
  134. # define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
  135. # define ifr_map ifr_ifru.ifru_map /* device map */
  136. # define ifr_slave ifr_ifru.ifru_slave /* slave device */
  137. # define ifr_data ifr_ifru.ifru_data /* for use by interface */
  138. # define ifr_ifindex ifr_ifru.ifru_ivalue /* interface index */
  139. # define ifr_bandwidth ifr_ifru.ifru_ivalue /* link bandwidth */
  140. # define ifr_qlen ifr_ifru.ifru_ivalue /* queue length */
  141. # define ifr_newname ifr_ifru.ifru_newname /* New name */
  142. # define _IOT_ifreq _IOT(_IOTS(char),IFNAMSIZ,_IOTS(char),16,0,0)
  143. # define _IOT_ifreq_short _IOT(_IOTS(char),IFNAMSIZ,_IOTS(short),1,0,0)
  144. # define _IOT_ifreq_int _IOT(_IOTS(char),IFNAMSIZ,_IOTS(int),1,0,0)
  145. /* Structure used in SIOCGIFCONF request. Used to retrieve interface
  146. configuration for machine (useful for programs which must know all
  147. networks accessible). */
  148. struct ifconf
  149. {
  150. int ifc_len; /* Size of buffer. */
  151. union
  152. {
  153. __caddr_t ifcu_buf;
  154. struct ifreq *ifcu_req;
  155. } ifc_ifcu;
  156. };
  157. # define ifc_buf ifc_ifcu.ifcu_buf /* Buffer address. */
  158. # define ifc_req ifc_ifcu.ifcu_req /* Array of structures. */
  159. # define _IOT_ifconf _IOT(_IOTS(struct ifconf),1,0,0,0,0) /* not right */
  160. #endif /* Misc. */
  161. __BEGIN_DECLS
  162. /* Convert an interface name to an index, and vice versa. */
  163. extern unsigned int if_nametoindex (__const char *__ifname) __THROW;
  164. extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW;
  165. /* Return a list of all interfaces and their indices. */
  166. extern struct if_nameindex *if_nameindex (void) __THROW;
  167. /* Free the data returned from if_nameindex. */
  168. extern void if_freenameindex (struct if_nameindex *__ptr) __THROW;
  169. __END_DECLS
  170. #endif /* net/if.h */