S390: Optimize utf8-utf16 module.
[glibc.git] / posix / tst-getaddrinfo2.c
blob13edca0a34f2981337d8b6a0d76ee03cced6f7c7
1 /* Test by David L Stevens <dlstevens@us.ibm.com> [BZ #358] */
2 #include <errno.h>
3 #include <netdb.h>
4 #include <unistd.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <sys/socket.h>
9 static int
10 do_test (void)
12 const char portstr[] = "583";
13 int port = atoi (portstr);
14 struct addrinfo hints, *aires, *pai;
15 int rv;
16 int res = 1;
18 memset (&hints, 0, sizeof (hints));
19 hints.ai_family = AF_INET;
20 rv = getaddrinfo (NULL, portstr, &hints, &aires);
21 if (rv == 0)
23 struct sockaddr_in *psin = 0;
24 int got_tcp, got_udp;
25 int err = 0;
27 got_tcp = got_udp = 0;
28 for (pai = aires; pai; pai = pai->ai_next)
30 printf ("ai_family=%d, ai_addrlen=%d, ai_socktype=%d",
31 (int) pai->ai_family, (int) pai->ai_addrlen,
32 (int) pai->ai_socktype);
33 if (pai->ai_family == AF_INET)
34 printf (", port=%d",
35 ntohs (((struct sockaddr_in *) pai->ai_addr)->sin_port));
36 puts ("");
38 err |= pai->ai_family != AF_INET;
39 err |= pai->ai_addrlen != sizeof (struct sockaddr_in);
40 err |= pai->ai_addr == 0;
41 if (pai->ai_family == AF_INET)
42 err |=
43 ntohs (((struct sockaddr_in *) pai->ai_addr)->sin_port) != port;
44 got_tcp |= pai->ai_socktype == SOCK_STREAM;
45 got_udp |= pai->ai_socktype == SOCK_DGRAM;
46 if (err)
47 break;
49 if (err)
51 printf ("FAIL getaddrinfo IPv4 socktype 0,513: "
52 "fam %d alen %d addr %p addr/fam %d "
53 "addr/port %d H[%d]\n",
54 pai->ai_family, pai->ai_addrlen, psin,
55 psin ? psin->sin_family : 0,
56 psin ? psin->sin_port : 0,
57 psin ? htons (psin->sin_port) : 0);
59 else if (got_tcp && got_udp)
61 printf ("SUCCESS getaddrinfo IPv4 socktype 0,513\n");
62 res = 0;
64 else
65 printf ("FAIL getaddrinfo IPv4 socktype 0,513 TCP %d"
66 " UDP %d\n", got_tcp, got_udp);
67 freeaddrinfo (aires);
69 else
70 printf ("FAIL getaddrinfo IPv4 socktype 0,513 returns %d "
71 "(\"%s\")\n", rv, gai_strerror (rv));
73 return res;
76 #define TEST_FUNCTION do_test ()
77 #include "../test-skeleton.c"