if.h 3.0 KB

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