if.h 6.2 KB

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