If you listen for a general "tcp" connection instead of a "tcp4" connection, ipv4.Conn.SetTOS fails on IPv4 connections (but works with ipv6.Conn.SetTrafficClass on IPv6 connections).
and send an IPv4 request (e.g. curl "127.0.0.1:1024"), the IPv4 connections will not have the TOS set, and SetTOS returns "setsockopt: invalid argument".
IPv6 connections in this same scenario (switch to ipv6.NewConn(c).SetTrafficClass) will work.
In my app, I'm testing for the type of connection by checking TCPConn.RemoteAddr() for IPv6 vs. IPv4 and calling the appropriate NewConn wrapper. IPv6 connections have their TrafficClass set properly. IPv4 connections generate the above error.
The text was updated successfully, but these errors were encountered:
Thanks for the notice, will update examples in both golang.org/x/net/{ipv4,ipv6}.
Yup, as the doc describes like "... network connections that use the IPv4 transport", you need to test address family when you use a dual stack listener, even though that feature doesn't work on some platform such as OpenBSD, DragonFly BSD, Plan 9. Of course it's also fine to have multiple explicit address family listeners.
If you listen for a general "tcp" connection instead of a "tcp4" connection, ipv4.Conn.SetTOS fails on IPv4 connections (but works with ipv6.Conn.SetTrafficClass on IPv6 connections).
From the https://godoc.org/golang.org/x/net/ipv4 example, if you change net.Listen("tcp4", "0.0.0.0:1024") to net.Listen("tcp", ":1024"):
and send an IPv4 request (e.g. curl "127.0.0.1:1024"), the IPv4 connections will not have the TOS set, and SetTOS returns "setsockopt: invalid argument".
IPv6 connections in this same scenario (switch to ipv6.NewConn(c).SetTrafficClass) will work.
In my app, I'm testing for the type of connection by checking TCPConn.RemoteAddr() for IPv6 vs. IPv4 and calling the appropriate NewConn wrapper. IPv6 connections have their TrafficClass set properly. IPv4 connections generate the above error.
The text was updated successfully, but these errors were encountered: