2
votes

I'm trying to synthesize an IPv6 address from an IPv4 address in Android (either in native code or in Java itself) as documented in RFC-7050 for use while behind NAT64.

When working in iOS this option was available through a call to getaddrinfo, however it seems that Android's implementation of getaddrinfo will only synthesize IPv6 for hostnames, and not IPv4 addresses.

On iOS, while behind NAT64, the following code would generate a synthesized IPv6 address inside the variable res's address list. However, on Android the same native code will generate an IPv4 address unless I pass a host name instead of an IPv4 address to getaddrinfo.

struct addrinfo *res;
getaddrinfo("x.x.x.x", "80", NULL, &res);

Edit

I do know that Android implements CLAT/464lat, however that doesn't cover all devices and networks. One prime example would be a NAT64 network behind an IPv4 only network.

Example: Internet -> IPv4 Only Network -> NAT64 Network -> Client

The client would have a local IPv6 address under RFC-4193 (I believe) but only be able to access the internet through it's NAT64 gateway, meaning that the NAT64 will have to translate addresses before sending them upstream.

So what I need is a way to generate the prefix for the synthesized IPv6 address

Ideally, we would need to synthesize an IPv6 address in order to reach the IPv4 endpoint.

1

1 Answers

2
votes

This might or might not be an answer for you:

You don't need to synthesize addresses on Android. It has 464xlat which simulates an IPv4 stack on a NAT64 network so your application can just use IPv4 and Android will take care of the mapping behind the scenes.

The difference between iOS and Android here is that Android implemented the IPv4 emulation in the stack. Apple decided that they want to keep the IP stack clean and provide the developer with the tools (like getaddrinfo) to do the mapping themselves. Different design decision.