[Bug 228068] tclass is not used when sending to IPv4 mapped address via IPv6 socket

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Tue May 8 13:41:00 UTC 2018


            Bug ID: 228068
           Summary: tclass is not used when sending to IPv4 mapped address
                    via IPv6 socket
           Product: Base System
           Version: 11.1-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs at FreeBSD.org
          Reporter: preynold.freebsd at gmail.com

When sending a udp packet from an IPv6 socket to an IPv4 mapped address, I
would expect the setting for IPV6_TCLASS to be used in the TOS IP header field.
It does not appear to be. A similar mapping for TTL should be present, though I
did not check for that.

Can be seen with a simple c program and wireshark:

#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int main() {

     int s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
     if (s < 0) {
         return -1;

     int value = (40 << 2) & 0xFC;
     int ret = setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &value, sizeof(value));
     if (ret < 0) {
         return -2;

     struct addrinfo hints;
     memset(&hints, 0, sizeof(hints));
     struct addrinfo *res = NULL;
     ret = getaddrinfo("::ffff:", "1234", &hints, &res);
     if (ret != 0) {
         return -3;

     const char *msg = "hello world";
     ssize_t n = sendto(s, msg, strlen(msg), 0, res->ai_addr, res->ai_addrlen);
     if (n < 0) {
         return -4;

     return 0;

You are receiving this mail because:
You are the assignee for the bug.

More information about the freebsd-bugs mailing list