I think that currently the source IP address is not set correctly on Linux. When having several network interfaces, in my experience, setting the source IP address has no effect and packets are sent with another source IP address, not the one specified.
My change seems to fix this problem. I tested it with some live machines with multiple network interfaces. I think my changed version is also consistent with the documentation of Linux's IP implementation.
If IP_PKTINFO is passed to sendmsg(2)
and ipi_spec_dst is not zero, then it is used as the local
source address for the routing table lookup and for
setting up IP source route options. When ipi_ifindex is
not zero, the primary local address of the interface
specified by the index overwrites ipi_spec_dst for the
routing table lookup.
I guess for IPv6 this isn't a problem as in6_pktinfo has only one IP address inside of it.
I think that currently the source IP address is not set correctly on Linux. When having several network interfaces, in my experience, setting the source IP address has no effect and packets are sent with another source IP address, not the one specified.
My change seems to fix this problem. I tested it with some live machines with multiple network interfaces. I think my changed version is also consistent with the documentation of Linux's IP implementation.
I guess for IPv6 this isn't a problem as
in6_pktinfo
has only one IP address inside of it.