+Sockets.IPAddress extend [
+ determineSourceAddress [
+ | sourceAddr res |
+ <category: '*Netlink'>
+ "Assuming that self is the destination address determine the
+ source address that will be used."
+ sourceAddr := ByteArray new: 4.
+ res := Netlink fromDestIPv4: address toLocal: sourceAddr.
+ res = 0
+ ifFalse: [^self error: 'Failed to determine source address'].
+ ^self class fromBytes: sourceAddr.
+ ]
+
+ fromDest: destAddress toLocal: localAddress [
+ <category: '*Netlink'>
+ "Given a destination IPv4 Address this function will
+ determine the local source address that would be used.
+ The addresses need to be a ByteArray with four entries."
+ <cCall: 'nl_route_source_ipv4' returning: #int args: #(#byteArray
#cObject)>
+ ]
+