check_pf.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Determine protocol families for which interfaces exist. Generic version.
  2. Copyright (C) 2003, 2006 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. #include <features.h>
  17. #include "ifaddrs.h"
  18. #include <netdb.h>
  19. void
  20. attribute_hidden
  21. __check_pf (bool *seen_ipv4, bool *seen_ipv6)
  22. {
  23. *seen_ipv4 = false;
  24. *seen_ipv6 = false;
  25. #if defined __UCLIBC_SUPPORT_AI_ADDRCONFIG__
  26. {
  27. /* Get the interface list via getifaddrs. */
  28. struct ifaddrs *ifa = NULL;
  29. struct ifaddrs *runp;
  30. if (getifaddrs (&ifa) != 0)
  31. {
  32. /* We cannot determine what interfaces are available. Be
  33. optimistic. */
  34. #if defined __UCLIBC_HAS_IPV4__
  35. *seen_ipv4 = true;
  36. #endif /* __UCLIBC_HAS_IPV4__ */
  37. #if defined __UCLIBC_HAS_IPV6__
  38. *seen_ipv6 = true;
  39. #endif /* __UCLIBC_HAS_IPV6__ */
  40. return;
  41. }
  42. for (runp = ifa; runp != NULL; runp = runp->ifa_next)
  43. #if defined __UCLIBC_HAS_IPV4__
  44. if (runp->ifa_addr->sa_family == PF_INET)
  45. *seen_ipv4 = true;
  46. #endif /* __UCLIBC_HAS_IPV4__ */
  47. #if defined __UCLIBC_HAS_IPV4__ && defined __UCLIBC_HAS_IPV6__
  48. else /* can't be both at once */
  49. #endif /* __UCLIBC_HAS_IPV4__ && defined __UCLIBC_HAS_IPV6__ */
  50. #if defined __UCLIBC_HAS_IPV6__
  51. if (runp->ifa_addr->sa_family == PF_INET6)
  52. *seen_ipv6 = true;
  53. #endif /* __UCLIBC_HAS_IPV6__ */
  54. (void) freeifaddrs (ifa);
  55. }
  56. #else
  57. /* AI_ADDRCONFIG is disabled, assume both ipv4 and ipv6 available. */
  58. #if defined __UCLIBC_HAS_IPV4__
  59. *seen_ipv4 = true;
  60. #endif /* __UCLIBC_HAS_IPV4__ */
  61. #if defined __UCLIBC_HAS_IPV6__
  62. *seen_ipv6 = true;
  63. #endif /* __UCLIBC_HAS_IPV6__ */
  64. #endif /* __UCLIBC_SUPPORT_AI_ADDRCONFIG__ */
  65. }