res_get_nsaddr.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* Name server address at specified index in res_state.
  2. Copyright (C) 2015-2026 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. <https://www.gnu.org/licenses/>. */
  15. #include <assert.h>
  16. #include <resolv.h>
  17. #include <resolv-internal.h>
  18. struct sockaddr *
  19. __res_get_nsaddr (res_state statp, unsigned int n)
  20. {
  21. assert (n < statp->nscount);
  22. if (statp->nsaddr_list[n].sin_family == 0
  23. && statp->_u._ext.nsaddrs[n] != NULL)
  24. /* statp->_u._ext.nsaddrs[n] holds an address that is larger than
  25. struct sockaddr, and user code did not update
  26. statp->nsaddr_list[n]. */
  27. return (struct sockaddr *) statp->_u._ext.nsaddrs[n];
  28. else
  29. /* User code updated statp->nsaddr_list[n], or statp->nsaddr_list[n]
  30. has the same content as statp->_u._ext.nsaddrs[n]. */
  31. return (struct sockaddr *) (void *) &statp->nsaddr_list[n];
  32. }
  33. libc_hidden_def (__res_get_nsaddr)