1#include <netdb.h>
2#include <stdio.h>
3#include <sys/socket.h>
4
5static int
6do_test (void)
7{
8 int retval = 0;
9
10 struct sockaddr_in s;
11 s.sin_family = AF_INET;
12 s.sin_port = 80;
13 s.sin_addr.s_addr = INADDR_LOOPBACK;
14 int r = getnameinfo((struct sockaddr *) &s, sizeof (s), NULL, 0, NULL, 0,
15 NI_NUMERICHOST | NI_NUMERICSERV);
16 printf(format: "r = %d\n", r);
17 if (r != 0)
18 {
19 puts (s: "failed without NI_NAMEREQD");
20 retval = 1;
21 }
22
23 r = getnameinfo((struct sockaddr *) &s, sizeof (s), NULL, 0, NULL, 0,
24 NI_NUMERICHOST | NI_NUMERICSERV | NI_NAMEREQD);
25 printf(format: "r = %d\n", r);
26 if (r != EAI_NONAME)
27 {
28 puts (s: "did not fail with EAI_NONAME with NI_NAMEREQD set");
29 retval = 1;
30 }
31
32 return retval;
33}
34
35#define TEST_FUNCTION do_test ()
36#include "../test-skeleton.c"
37

source code of glibc/inet/tst-getni1.c