Ticket #8293: getaddrinfo.cpp

File getaddrinfo.cpp, 586 bytes (added by axeld, 7 years ago)

Test program to demonstrate the remaining problem.

Line 
1#include <netdb.h>
2
3#include <NetworkAddress.h>
4
5
6int
7main()
8{
9 const char* host = NULL;
10 const char* port = "80";
11 addrinfo hint = {0};
12 hint.ai_family = AF_UNSPEC;
13 hint.ai_socktype = SOCK_STREAM;
14
15 addrinfo* info;
16 int status = getaddrinfo(host, port, &hint, &info);
17 if (status != 0) {
18 fprintf(stderr, "getaddrinfo() failed: %s\n", gai_strerror(status));
19 return 1;
20 }
21
22 for (const addrinfo* next = info; next != NULL;
23 next = next->ai_next) {
24 BNetworkAddress address(*next->ai_addr);
25 printf("got: %s\n", address.ToString().String());
26 }
27
28 freeaddrinfo(info);
29 return 0;
30}