-
Notifications
You must be signed in to change notification settings - Fork 4
/
ipv4mapped-ipv6.c
40 lines (33 loc) · 934 Bytes
/
ipv4mapped-ipv6.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
/*
* ipv4mapped-ipv6.c - Given an IPv4 address produce an IPv4-mapped IPv6
* address.
*
* Copyright (C) 2023 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 <arpa/inet.h>
#include "common.h"
#include "short_types.h"
int main(int argc, char *argv[])
{
struct in_addr addr;
u32 naddr;
if (argc < 2) {
printf("Usage: ipv4mapped-ipv6 <IPv4 addr>\n");
exit(EXIT_FAILURE);
}
inet_pton(AF_INET, argv[1], &addr);
naddr = htonl(addr.s_addr);
printf("IPv4-mapped IPv6 : ::ffff:%s%s%s\n",
TXT_FMT_BOLD, argv[1], TXT_FMT_END);
printf(" : ::ffff:%s%04x:%04x%s\n",
TXT_FMT_BOLD, (naddr >> 16) & 0x0000ffff, naddr & 0x0000ffff,
TXT_FMT_END);
exit(EXIT_SUCCESS);
}