Your problem is the challenge inet_pton. When AF_INETa family of addresses is passed, the pointer dstmust be a pointer to struct in_addr, not struct sockaddr_in.
Change line 21 to:
if (inet_pton(AF_INET, argv[1], &sa.sin_addr) <= 0)
Insert a line in line 23:
sa.sin_family = AF_INET;
Change the lines from 31-32 to:
if ((x=getnameinfo((struct sockaddr*)&sa, sizeof sa,
hostname, sizeof hostname, servname, sizeof servname, NI_NAMEREQD)) != 0) {
then it should work.
source
share