tst-getni2.c 948 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <netdb.h>
  2. #include <stdio.h>
  3. #include <sys/socket.h>
  4. static int
  5. do_test (void)
  6. {
  7. int retval = 0;
  8. struct sockaddr_in6 s;
  9. s.sin6_family = AF_INET6;
  10. s.sin6_port = htons (80);
  11. s.sin6_flowinfo = 0;
  12. s.sin6_addr = (struct in6_addr) IN6ADDR_ANY_INIT;
  13. s.sin6_scope_id = 0;
  14. char buf[1000];
  15. buf[0] = '\0';
  16. int r = getnameinfo((struct sockaddr *) &s, sizeof (s), buf, sizeof (buf),
  17. NULL, 0, NI_NUMERICSERV);
  18. printf("r = %d, buf = \"%s\"\n", r, buf);
  19. if (r != 0)
  20. {
  21. puts ("failed without NI_NAMEREQD");
  22. retval = 1;
  23. }
  24. buf[0] = '\0';
  25. r = getnameinfo((struct sockaddr *) &s, sizeof (s), buf, sizeof (buf),
  26. NULL, 0, NI_NUMERICSERV | NI_NAMEREQD);
  27. printf("r = %d, buf = \"%s\"\n", r, buf);
  28. if (r != EAI_NONAME)
  29. {
  30. puts ("did not fail with EAI_NONAME with NI_NAMEREQD set");
  31. retval = 1;
  32. }
  33. return retval;
  34. }
  35. #define TEST_FUNCTION do_test ()
  36. #include "../test-skeleton.c"