-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathipv6-arpa.c
53 lines (45 loc) · 1.06 KB
/
ipv6-arpa.c
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* ipv6-arpa.c - Given an IPv6 address display it in ip6.arpa format.
*
* Copyright (C) 2015 Andrew Clayton <[email protected]>
*
* Licensed under the GNU General Public License Version 2 or
* the GNU Lesser General Public License Version 2.1
*
* See GPLv2 & LGPLv2.1 in the source tree.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
static void ipv6_arpa(const char *address)
{
struct in6_addr ip6b;
int i;
int len = 0;
char ips[INET6_ADDRSTRLEN];
inet_pton(AF_INET6, address, &ip6b);
for (i = 0; i < 15; i += 2) {
len += sprintf(ips + len,"%02x%02x", ip6b.s6_addr[i],
ip6b.s6_addr[i + 1]);
if (i < 14)
len += sprintf(ips + len, ":");
}
printf("Address : %s\n", ips);
printf("ip6.arpa :- \n ");
for (i = strlen(ips) - 1; i >= 0; i--) {
if (ips[i] == ':')
continue;
printf("%c.", ips[i]);
}
printf("ip6.arpa.\n");
}
int main(int argc, char *argv[])
{
if (argc < 2) {
printf("Usage: ipv6-arpa address\n");
exit(EXIT_FAILURE);
}
ipv6_arpa(argv[1]);
exit(EXIT_SUCCESS);
}