if.h 2.7 KB

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