host by connecting a UDP socket and checking the address
the socket is bound to.
*/
-static void net_find_local_address(
- void)
+static
+void net_find_local_address(struct mtr_ctl * ctl)
{
int udp_socket;
int addr_length;
error(EXIT_FAILURE, errno, "udp socket creation failed");
}
+#ifdef SO_MARK
+ /* On Linux, the packet mark can affect the selection of the source address */
+ if(ctl->mark) {
+ if(setsockopt(udp_socket, SOL_SOCKET, SO_MARK, &ctl->mark, sizeof(ctl->mark))) {
+ error(EXIT_FAILURE, errno, "failed to set the packet mark");
+ }
+ }
+#endif
+
/*
We need to set the port to a non-zero value for the connect
to succeed.
&sourcesockaddr_struct, ctl->af, ctl->InterfaceName);
inet_ntop(sourcesockaddr->sa_family, sourceaddress, localaddr, sizeof(localaddr));
} else {
- net_find_local_address();
+ net_find_local_address(ctl);
}
}