if.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. struct ifaddr {
  36. struct sockaddr ifa_addr;
  37. union {
  38. struct sockaddr ifu_broadaddr;
  39. struct sockaddr ifu_dstaddr;
  40. } ifa_ifu;
  41. struct iface *ifa_ifp;
  42. struct ifaddr *ifa_next;
  43. };
  44. #define ifa_broadaddr ifa_ifu.ifu_broadaddr
  45. #define ifa_dstaddr ifa_ifu.ifu_dstaddr
  46. struct ifmap {
  47. unsigned long int mem_start;
  48. unsigned long int mem_end;
  49. unsigned short int base_addr;
  50. unsigned char irq;
  51. unsigned char dma;
  52. unsigned char port;
  53. };
  54. #define IFHWADDRLEN 6
  55. #define IFNAMSIZ IF_NAMESIZE
  56. struct ifreq {
  57. union {
  58. char ifrn_name[IFNAMSIZ];
  59. } ifr_ifrn;
  60. union {
  61. struct sockaddr ifru_addr;
  62. struct sockaddr ifru_dstaddr;
  63. struct sockaddr ifru_broadaddr;
  64. struct sockaddr ifru_netmask;
  65. struct sockaddr ifru_hwaddr;
  66. short int ifru_flags;
  67. int ifru_ivalue;
  68. int ifru_mtu;
  69. struct ifmap ifru_map;
  70. char ifru_slave[IFNAMSIZ];
  71. char ifru_newname[IFNAMSIZ];
  72. void *ifru_data;
  73. } ifr_ifru;
  74. };
  75. #define ifr_name ifr_ifrn.ifrn_name
  76. #define ifr_hwaddr ifr_ifru.ifru_hwaddr
  77. #define ifr_addr ifr_ifru.ifru_addr
  78. #define ifr_dstaddr ifr_ifru.ifru_dstaddr
  79. #define ifr_broadaddr ifr_ifru.ifru_broadaddr
  80. #define ifr_netmask ifr_ifru.ifru_netmask
  81. #define ifr_flags ifr_ifru.ifru_flags
  82. #define ifr_metric ifr_ifru.ifru_ivalue
  83. #define ifr_mtu ifr_ifru.ifru_mtu
  84. #define ifr_map ifr_ifru.ifru_map
  85. #define ifr_slave ifr_ifru.ifru_slave
  86. #define ifr_data ifr_ifru.ifru_data
  87. #define ifr_ifindex ifr_ifru.ifru_ivalue
  88. #define ifr_bandwidth ifr_ifru.ifru_ivalue
  89. #define ifr_qlen ifr_ifru.ifru_ivalue
  90. #define ifr_newname ifr_ifru.ifru_newname
  91. #define _IOT_ifreq _IOT(_IOTS(char),IFNAMSIZ,_IOTS(char),16,0,0)
  92. #define _IOT_ifreq_short _IOT(_IOTS(char),IFNAMSIZ,_IOTS(short),1,0,0)
  93. #define _IOT_ifreq_int _IOT(_IOTS(char),IFNAMSIZ,_IOTS(int),1,0,0)
  94. struct ifconf {
  95. int ifc_len;
  96. union {
  97. void *ifcu_buf;
  98. struct ifreq *ifcu_req;
  99. } ifc_ifcu;
  100. };
  101. #define ifc_buf ifc_ifcu.ifcu_buf
  102. #define ifc_req ifc_ifcu.ifcu_req
  103. #define _IOT_ifconf _IOT(_IOTS(struct ifconf),1,0,0,0,0)
  104. #endif
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #endif