1

I tried to convert the destination address to IPv6 format as ::ffff:IPv4. And use a socket of AF_INET6 type. It gives error: Network Unreachable. But using the same technique I am able to communicate from IPV4 to IPV6

Thanks for your help in advance.

2 Answers 2

3

IPv4 and IPv6 are separate protocols. They don't talk to each other.

On some operating systems you can use an IPv6 socket and accept incoming IPv4 connections on it. But that is just a software thing to make code development easier for server code. I have never seen that work for client code. You'll have to create the right socket type for that.

Usually you resolve a hostname using DNS, you'll get multiple answers (IPv4 and IPv6), you iterate over them creating the required socket type and try to connect. If it works you use that socket, if not you do the next iteration which creates a new socket etc.

If you code that is sensitive to delays you might want to implement the happy eyeballs algorithm.

Sign up to request clarification or add additional context in comments.

2 Comments

They most certainly do talk to each other. There is a specific IPv6 address format for connecting to IPv4 addresses.
@EJP: IPv4 and IPv6 have different packet formats. They don't understand each other. There are systems that have both, there are NAT64 boxes that do NAT from IPv6 to IPv4, but there is no way an IPv4-only system can directly talk to an IPv6-only system. As I said there are IP stacks that can represent an IPv4 connection as an IPv6 socket with ::ffff:192.0.2.1 style addresses, but that is just software masquerading. It is still an IPv4 connection on the wire.
3

On most systems, PF_INET6 sockets are able to communicate with IPv4 addresses by using addresses in the ::FFFF:0:0/96 range. However, this is only done at the level of the sockets library: the actual on-the-wire data are plain IPv4 packets (as though you had used an PF_INET socket), there is no protocol conversion in the network.

The error you receive indicates that you have no IPv4 route to the requested destination. This probably indicates that your host doesn't have an IPv4 default route. There is no solution to that — without IPv4 connectivity, there is nothing you can do to reach an IPv4 address.

2 Comments

You have mentioned that: "There is no solution to that — without IPv4 connectivity, there is nothing you can do to reach an IPv4 address." So, it means that an IPv6 only machine and IPv4 only machine cannot contact with each other.
Yes, Virginia. Fortunately, obtaining IPv6 connectivity on your IPv4 machines is easy, do a search for Teredo (Miredo if running Linux or Mac OS X).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.