tst-getni1.c 801 B

123456789101112131415161718192021222324252627282930313233343536
  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_in s;
  9. s.sin_family = AF_INET;
  10. s.sin_port = 80;
  11. s.sin_addr.s_addr = INADDR_LOOPBACK;
  12. int r = getnameinfo((struct sockaddr *) &s, sizeof (s), NULL, 0, NULL, 0,
  13. NI_NUMERICHOST | NI_NUMERICSERV);
  14. printf("r = %d\n", r);
  15. if (r != 0)
  16. {
  17. puts ("failed without NI_NAMEREQD");
  18. retval = 1;
  19. }
  20. r = getnameinfo((struct sockaddr *) &s, sizeof (s), NULL, 0, NULL, 0,
  21. NI_NUMERICHOST | NI_NUMERICSERV | NI_NAMEREQD);
  22. printf("r = %d\n", r);
  23. if (r != EAI_NONAME)
  24. {
  25. puts ("did not fail with EAI_NONAME with NI_NAMEREQD set");
  26. retval = 1;
  27. }
  28. return retval;
  29. }
  30. #define TEST_FUNCTION do_test ()
  31. #include "../test-skeleton.c"