blob: 218f74002fa8975daaf2e69aa33637c6a10cbffb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#include <stdio.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr,"usage: %s <IPADDRESS>\n", argv[0]);
return 1;
}
struct hostent *he;
struct in_addr ipv4addr;
struct in6_addr ipv6addr;
inet_pton(AF_INET, argv[1], &ipv4addr);
he = gethostbyaddr(&ipv4addr, sizeof ipv4addr, AF_INET);
if (he == NULL) return 2;
if (he->h_name == NULL) return 3;
printf("%s\n", he->h_name);
return 0;
}
|