i am getting the error ai_family not supported in call to getnameinfo.
1 #include <iostream>
2 #include <sys/types.h>
3 #include <unistd.h>
4 #include <sys/socket.h>
5 #include <netdb.h>
6 #include <arpa/inet.h>
7 #include <iomanip>
8 extern "C" {
9 #include "../../pg/include/errhnd.h"
10 }
11
12 using namespace std;
13
14
15 int main(int argc, char** argv)
16 {
17 if (argc != 2)
18 err_quit("Usage: %s <ip address>", argv[0]);
19
20 struct sockaddr_in sa;
21 if (inet_pton(AF_INET, argv[1], &sa) <= 0)
22 err_sys("inet_pton error");
23
24 char hostname[1000], servname[1000];
25
26 cout << hex << (unsigned int)sa.sin_addr.s_addr << endl;
27
28 sa.sin_port = htons(80);
29
30 int x;
31 if ((x=getnameinfo((struct sockaddr*)&(sa.sin_addr),
32 16, hostname, 1000, servname, 1000, NI_NAMEREQD)) != 0) {
33 err_ret("getnameinfo error");
34 cout << gai_strerror(x) << endl;
35 }
36
37 cout << hostname << " " << servname << endl;
38
39 return 0;
40 }