check_pf.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Determine protocol families for which interfaces exist. Generic version.
  2. Copyright (C) 2003-2019 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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <ifaddrs.h>
  16. #include <netdb.h>
  17. #include <stdint.h>
  18. void
  19. attribute_hidden
  20. __check_pf (bool *seen_ipv4, bool *seen_ipv6,
  21. struct in6addrinfo **in6ai, size_t *in6ailen)
  22. {
  23. /* By default we have no way to determine information about
  24. deprecated and temporary addresses. */
  25. *in6ai = NULL;
  26. *in6ailen = 0;
  27. /* Get the interface list via getifaddrs. */
  28. struct ifaddrs *ifa = NULL;
  29. if (__getifaddrs (&ifa) != 0)
  30. {
  31. /* We cannot determine what interfaces are available. Be
  32. pessimistic. */
  33. *seen_ipv4 = true;
  34. *seen_ipv6 = true;
  35. return;
  36. }
  37. *seen_ipv4 = false;
  38. *seen_ipv6 = false;
  39. struct ifaddrs *runp;
  40. for (runp = ifa; runp != NULL; runp = runp->ifa_next)
  41. if (runp->ifa_addr->sa_family == PF_INET)
  42. *seen_ipv4 = true;
  43. else if (runp->ifa_addr->sa_family == PF_INET6)
  44. *seen_ipv6 = true;
  45. (void) __freeifaddrs (ifa);
  46. }
  47. void
  48. __free_in6ai (struct in6addrinfo *in6ai)
  49. {
  50. /* Nothing to do. */
  51. }
  52. #if IS_IN (nscd)
  53. uint32_t
  54. __bump_nl_timestamp (void)
  55. {
  56. return 0;
  57. }
  58. #endif