diff options
Diffstat (limited to 'src/sock.c')
-rw-r--r-- | src/sock.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -385,11 +385,25 @@ int getsock_ip (int fd, char *ipaddr) return 0; } -int getmapped_ip (const char *ipv4mapped_conf, const char *ipaddr, char *ipaddr_mapped) +int getmapped_ipv4 (const char *ipv6mapped_conf, const char *ipaddr, char *ipaddr_mapped) +{ + struct in6_addr addr6; + struct in_addr addr; + + memset(&addr6, 0, sizeof(addr6)); + if ( inet_pton(AF_INET6, ipaddr, &addr6) < 0 ) + return -1; + + memcpy(&addr, addr6.s6_addr + 12, sizeof(&addr)); + return inet_ntop(AF_INET, &addr, ipaddr_mapped, IP_LENGTH) == NULL ? -1 : 0; +} + +int getmapped_ipv6 (const char *ipv4mapped_conf, const char *ipaddr, char *ipaddr_mapped) { memset(ipaddr_mapped, 0, IP_LENGTH); strncpy(ipaddr_mapped, ipv4mapped_conf, IP_LENGTH-1); strncat(ipaddr_mapped, ipaddr, IP_LENGTH-1-strlen(ipaddr_mapped)); + return 0; } |