AF_INET6 sockets and IPv4 connections, etc.

Philip Prindeville philipp_subx at redfish-solutions.com
Tue Jan 11 20:46:23 UTC 2011


Hi.

I'm working on a patch to support QoS setting on an IPv4 connection, but I'm being out-clevered by the kernel.

The code is doing the following:

s = socket(AF_INET6, SOCK_STREAM);
...
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = ... // ::FFFF:<IPv4>  address

and then, as the man page says:

        IPv4 connections can be handled with the v6 API by using the v4-mapped-
        on-v6 address type; thus a program only needs to support this API  type
        to  support  both  protocols.   This  is  handled  transparently by the
        address handling functions in the C library.


so how can I tell in a couple of lines of code if the connection will result in IPv4?

The patch looked like:

+#if defined(SOL_IP)&&  defined(IP_TOS)
+                      if (d->d_addr.sa.sa_family == AF_INET&&  InetQoS != 0x00)
+                              (void) setsockopt(d->d_socket, SOL_IP,
+                                                IP_TOS, (char *)&InetQoS, sizeof(InetQoS));
+#endif


but it strikes me that this will not cover the above case.

Any ideas welcome.

Thanks,

-Philip





More information about the devel mailing list