1 /* Test by David L Stevens <dlstevens@us.ibm.com> [BZ #358] */
8 #include <sys/socket.h>
13 const char portstr
[] = "583";
14 int port
= atoi (portstr
);
15 struct addrinfo hints
, *aires
, *pai
;
19 memset (&hints
, 0, sizeof (hints
));
20 hints
.ai_family
= AF_INET
;
21 rv
= getaddrinfo (NULL
, portstr
, &hints
, &aires
);
24 struct sockaddr_in
*psin
= 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
)
36 ntohs (((struct sockaddr_in
*) pai
->ai_addr
)->sin_port
));
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
)
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
;
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");
66 printf ("FAIL getaddrinfo IPv4 socktype 0,513 TCP %d"
67 " UDP %d\n", got_tcp
, got_udp
);
71 printf ("FAIL getaddrinfo IPv4 socktype 0,513 returns %d "
72 "(\"%s\")\n", rv
, gai_strerror (rv
));
77 #define TEST_FUNCTION do_test ()
78 #include "../test-skeleton.c"