How to get the IPv4 address from IPv4-mapped IPv6 addresses?
For e.g I have an IP address ::FFFF:129.144.52.38
. from this, I need to extract 129.144.52.38
. Is there any API for this purpose?
I can identify IPv6 or IPv4 address family by using the following function
int getaddrfamily(const char *addr)
{
struct addrinfo hint, *info =0;
memset(&hint, 0, sizeof(hint));
hint.ai_family = AF_UNSPEC;
// Uncomment this to disable DNS lookup
//hint.ai_flags = AI_NUMERICHOST;
int ret = getaddrinfo(addr, 0, &hint, &info);
if (ret)
return -1;
int result = info->ai_family;
freeaddrinfo(info);
return result;
}
If I give a IPv4 mapped IPv6 address, then how it's possible to identify if it's a mapped adress? Is there any socket API to extract IPv4 from a mapped IPv6 address?