nss_test_gai_hv2_canonname.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* NSS service provider that only provides gethostbyname2_r.
  2. Copyright The GNU Toolchain Authors.
  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 <nss.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "nss/tst-nss-gai-hv2-canonname.h"
  19. /* Catch misnamed and functions. */
  20. #pragma GCC diagnostic error "-Wmissing-prototypes"
  21. NSS_DECLARE_MODULE_FUNCTIONS (test_gai_hv2_canonname)
  22. extern enum nss_status _nss_files_gethostbyname2_r (const char *, int,
  23. struct hostent *, char *,
  24. size_t, int *, int *);
  25. enum nss_status
  26. _nss_test_gai_hv2_canonname_gethostbyname2_r (const char *name, int af,
  27. struct hostent *result,
  28. char *buffer, size_t buflen,
  29. int *errnop, int *herrnop)
  30. {
  31. return _nss_files_gethostbyname2_r (name, af, result, buffer, buflen, errnop,
  32. herrnop);
  33. }
  34. enum nss_status
  35. _nss_test_gai_hv2_canonname_getcanonname_r (const char *name, char *buffer,
  36. size_t buflen, char **result,
  37. int *errnop, int *h_errnop)
  38. {
  39. /* We expect QUERYNAME, which is a small enough string that it shouldn't fail
  40. the test. */
  41. if (memcmp (QUERYNAME, name, sizeof (QUERYNAME))
  42. || buflen < sizeof (QUERYNAME))
  43. abort ();
  44. strncpy (buffer, name, buflen);
  45. *result = buffer;
  46. return NSS_STATUS_SUCCESS;
  47. }