1 #include <stdio.h>
2 #include <firestring.h>
3 #include "firedns.h"
4
main(int argc,char ** argv)5 int main(int argc, char **argv) {
6 char *result;
7 struct in_addr *binip;
8 struct in6_addr *binip6;
9 struct firedns_ip4list *ipiter;
10 struct firedns_ip6list *ip6iter;
11 char *local_result;
12
13 if (argc != 2) {
14 fprintf(stderr,"usage: %s <ip address>\n",argv[0]);
15 return 2;
16 }
17
18 binip6 = firedns_aton6(argv[1]);
19 if (binip6 == NULL) {
20 binip = firedns_aton4(argv[1]);
21 if (binip == NULL) {
22 fprintf(stderr,"invalid IP address.\n");
23 return 2;
24 }
25
26 /* IPv4 */
27 result = firedns_resolvename4(binip);
28
29 if (result == NULL)
30 return 1;
31
32 local_result = firestring_strdup(result);
33
34 ipiter = firedns_resolveip4list(result);
35 while (ipiter != NULL) {
36 if (memcmp(&ipiter->ip,binip,4) == 0)
37 goto good;
38 ipiter = ipiter->next;
39 }
40
41 free(local_result);
42 return 3;
43 } else {
44 /* IPv6 */
45 result = firedns_resolvename6(binip6);
46
47 if (result == NULL)
48 return 1;
49
50 local_result = firestring_strdup(result);
51
52 ip6iter = firedns_resolveip6list(result);
53 while (ip6iter != NULL) {
54 if (memcmp(&ip6iter->ip,binip6,16) == 0)
55 goto good;
56 ip6iter = ip6iter->next;
57 }
58
59 free(local_result);
60 return 3;
61 }
62
63 good:
64 printf("%s\n",local_result);
65 free(local_result);
66 return 0;
67 }
68