ifaddrs.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* ifaddrs.h -- declarations for getting network interface addresses
  2. Copyright (C) 2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _IFADDRS_H
  17. #define _IFADDRS_H 1
  18. #include <features.h>
  19. #include <sys/socket.h>
  20. #include <stdbool.h>
  21. #include <stdint.h>
  22. __BEGIN_DECLS
  23. /* The `getifaddrs' function generates a linked list of these structures.
  24. Each element of the list describes one network interface. */
  25. struct ifaddrs
  26. {
  27. struct ifaddrs *ifa_next; /* Pointer to the next structure. */
  28. char *ifa_name; /* Name of this network interface. */
  29. unsigned int ifa_flags; /* Flags as from SIOCGIFFLAGS ioctl. */
  30. struct sockaddr *ifa_addr; /* Network address of this interface. */
  31. struct sockaddr *ifa_netmask; /* Netmask of this interface. */
  32. union
  33. {
  34. /* At most one of the following two is valid. If the IFF_BROADCAST
  35. bit is set in `ifa_flags', then `ifa_broadaddr' is valid. If the
  36. IFF_POINTOPOINT bit is set, then `ifa_dstaddr' is valid.
  37. It is never the case that both these bits are set at once. */
  38. struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */
  39. struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */
  40. } ifa_ifu;
  41. /* These very same macros are defined by <net/if.h> for `struct ifaddr'.
  42. So if they are defined already, the existing definitions will be fine. */
  43. # ifndef ifa_broadaddr
  44. # define ifa_broadaddr ifa_ifu.ifu_broadaddr
  45. # endif
  46. # ifndef ifa_dstaddr
  47. # define ifa_dstaddr ifa_ifu.ifu_dstaddr
  48. # endif
  49. void *ifa_data; /* Address-specific data (may be unused). */
  50. };
  51. /* Create a linked list of `struct ifaddrs' structures, one for each
  52. network interface on the host machine. If successful, store the
  53. list in *IFAP and return 0. On errors, return -1 and set `errno'.
  54. The storage returned in *IFAP is allocated dynamically and can
  55. only be properly freed by passing it to `freeifaddrs'. */
  56. extern int getifaddrs (struct ifaddrs **__ifap) __THROW;
  57. /* Reclaim the storage allocated by a previous `getifaddrs' call. */
  58. extern void freeifaddrs (struct ifaddrs *__ifa) __THROW;
  59. __END_DECLS
  60. #endif /* ifaddrs.h */