if.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef _NET_IF_H
  2. #define _NET_IF_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <features.h>
  7. #define IF_NAMESIZE 16
  8. struct if_nameindex
  9. {
  10. unsigned int if_index;
  11. char *if_name;
  12. };
  13. unsigned int if_nametoindex (const char *);
  14. char *if_indextoname (unsigned int, char *);
  15. struct if_nameindex *if_nameindex (void);
  16. void if_freenameindex (struct if_nameindex *);
  17. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  18. #include <sys/socket.h>
  19. #define IFF_UP 0x1
  20. #define IFF_BROADCAST 0x2
  21. #define IFF_DEBUG 0x4
  22. #define IFF_LOOPBACK 0x8
  23. #define IFF_POINTOPOINT 0x10
  24. #define IFF_NOTRAILERS 0x20
  25. #define IFF_RUNNING 0x40
  26. #define IFF_NOARP 0x80
  27. #define IFF_PROMISC 0x100
  28. #define IFF_ALLMULTI 0x200
  29. #define IFF_MASTER 0x400
  30. #define IFF_SLAVE 0x800
  31. #define IFF_MULTICAST 0x1000
  32. #define IFF_PORTSEL 0x2000
  33. #define IFF_AUTOMEDIA 0x4000
  34. #define IFF_DYNAMIC 0x8000
  35. #define IFF_LOWER_UP 0x10000
  36. #define IFF_DORMANT 0x20000
  37. #define IFF_ECHO 0x40000
  38. #define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST| \
  39. IFF_ECHO|IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)
  40. struct ifaddr {
  41. struct sockaddr ifa_addr;
  42. union {
  43. struct sockaddr ifu_broadaddr;
  44. struct sockaddr ifu_dstaddr;
  45. } ifa_ifu;
  46. struct iface *ifa_ifp;
  47. struct ifaddr *ifa_next;
  48. };
  49. #define ifa_broadaddr ifa_ifu.ifu_broadaddr
  50. #define ifa_dstaddr ifa_ifu.ifu_dstaddr
  51. struct ifmap {
  52. unsigned long int mem_start;
  53. unsigned long int mem_end;
  54. unsigned short int base_addr;
  55. unsigned char irq;
  56. unsigned char dma;
  57. unsigned char port;
  58. };
  59. #define IFHWADDRLEN 6
  60. #define IFNAMSIZ IF_NAMESIZE
  61. struct ifreq {
  62. union {
  63. char ifrn_name[IFNAMSIZ];
  64. } ifr_ifrn;
  65. union {
  66. struct sockaddr ifru_addr;
  67. struct sockaddr ifru_dstaddr;
  68. struct sockaddr ifru_broadaddr;
  69. struct sockaddr ifru_netmask;
  70. struct sockaddr ifru_hwaddr;
  71. short int ifru_flags;
  72. int ifru_ivalue;
  73. int ifru_mtu;
  74. struct ifmap ifru_map;
  75. char ifru_slave[IFNAMSIZ];
  76. char ifru_newname[IFNAMSIZ];
  77. void *ifru_data;
  78. } ifr_ifru;
  79. };
  80. #define ifr_name ifr_ifrn.ifrn_name
  81. #define ifr_hwaddr ifr_ifru.ifru_hwaddr
  82. #define ifr_addr ifr_ifru.ifru_addr
  83. #define ifr_dstaddr ifr_ifru.ifru_dstaddr
  84. #define ifr_broadaddr ifr_ifru.ifru_broadaddr
  85. #define ifr_netmask ifr_ifru.ifru_netmask
  86. #define ifr_flags ifr_ifru.ifru_flags
  87. #define ifr_metric ifr_ifru.ifru_ivalue
  88. #define ifr_mtu ifr_ifru.ifru_mtu
  89. #define ifr_map ifr_ifru.ifru_map
  90. #define ifr_slave ifr_ifru.ifru_slave
  91. #define ifr_data ifr_ifru.ifru_data
  92. #define ifr_ifindex ifr_ifru.ifru_ivalue
  93. #define ifr_bandwidth ifr_ifru.ifru_ivalue
  94. #define ifr_qlen ifr_ifru.ifru_ivalue
  95. #define ifr_newname ifr_ifru.ifru_newname
  96. #define _IOT_ifreq _IOT(_IOTS(char),IFNAMSIZ,_IOTS(char),16,0,0)
  97. #define _IOT_ifreq_short _IOT(_IOTS(char),IFNAMSIZ,_IOTS(short),1,0,0)
  98. #define _IOT_ifreq_int _IOT(_IOTS(char),IFNAMSIZ,_IOTS(int),1,0,0)
  99. struct ifconf {
  100. int ifc_len;
  101. union {
  102. void *ifcu_buf;
  103. struct ifreq *ifcu_req;
  104. } ifc_ifcu;
  105. };
  106. #define ifc_buf ifc_ifcu.ifcu_buf
  107. #define ifc_req ifc_ifcu.ifcu_req
  108. #define _IOT_ifconf _IOT(_IOTS(struct ifconf),1,0,0,0,0)
  109. #endif
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif