microblaze: Avoid clobbering register parameters in syscall
[glibc.git] / posix / tst-getaddrinfo2.c
blobd8be4a8e8f27b36c9e4d085d6700ac1bc7aa81f7
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 <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <sys/socket.h>
10 static int
11 do_test (void)
13 const char portstr[] = "583";
14 int port = atoi (portstr);
15 struct addrinfo hints, *aires, *pai;
16 int rv;
17 int res = 1;
19 memset (&hints, 0, sizeof (hints));
20 hints.ai_family = AF_INET;
21 rv = getaddrinfo (NULL, portstr, &hints, &aires);
22 if (rv == 0)
24 struct sockaddr_in *psin = 0;
25 int got_tcp, got_udp;
26 int err = 0;
28 got_tcp = got_udp = 0;
29 for (pai = aires; pai; pai = pai->ai_next)
31 printf ("ai_family=%d, ai_addrlen=%d, ai_socktype=%d",
32 (int) pai->ai_family, (int) pai->ai_addrlen,
33 (int) pai->ai_socktype);
34 if (pai->ai_family == AF_INET)
35 printf (", port=%d",
36 ntohs (((struct sockaddr_in *) pai->ai_addr)->sin_port));
37 puts ("");
39 err |= pai->ai_family != AF_INET;
40 err |= pai->ai_addrlen != sizeof (struct sockaddr_in);
41 err |= pai->ai_addr == 0;
42 if (pai->ai_family == AF_INET)
43 err |=
44 ntohs (((struct sockaddr_in *) pai->ai_addr)->sin_port) != port;
45 got_tcp |= pai->ai_socktype == SOCK_STREAM;
46 got_udp |= pai->ai_socktype == SOCK_DGRAM;
47 if (err)
48 break;
50 if (err)
52 printf ("FAIL getaddrinfo IPv4 socktype 0,513: "
53 "fam %d alen %d addr %p addr/fam %d "
54 "addr/port %d H[%d]\n",
55 pai->ai_family, pai->ai_addrlen, psin,
56 psin ? psin->sin_family : 0,
57 psin ? psin->sin_port : 0,
58 psin ? htons (psin->sin_port) : 0);
60 else if (got_tcp && got_udp)
62 printf ("SUCCESS getaddrinfo IPv4 socktype 0,513\n");
63 res = 0;
65 else
66 printf ("FAIL getaddrinfo IPv4 socktype 0,513 TCP %d"
67 " UDP %d\n", got_tcp, got_udp);
68 freeaddrinfo (aires);
70 else
71 printf ("FAIL getaddrinfo IPv4 socktype 0,513 returns %d "
72 "(\"%s\")\n", rv, gai_strerror (rv));
74 return res;
77 #define TEST_FUNCTION do_test ()
78 #include "../test-skeleton.c"