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