On Thu, Oct 13, 2016 at 11:39:17PM +0200, Neels Hofmeyr wrote:
But how would I tell the IuPS to use a given local interface 1.2.3.5 to contact the SGSN's address?
Please note that on Linux, addresses are always addresses of the overall host / IP stack and not of a specific interface. The routing table is used to determine the local address that should be used for a given destination.
So for (almost?) all reasonably configured systems, it should simply work based on what the system administrator has set.
Would I bind() to a given local IP address and connect() to the remote one?
yes.
AFAIK it can be important to set a local IP address and port to send from.
I think in general this would mostly be a work-around for broken setups.
At least, when talking about TCP clients here. Binding UDP or TCP server sockets is of course a different story
Anyway, in osmo_sock_init, I see:
if ((flags & (OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT)) == (OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT)) { fprintf(stderr, "invalid: both bind and connect flags set:" " %s:%u\n", host, port); return -EINVAL; }
well, because we only pass one pair of host+port parameters into osmo_sock_init(), you cannot bind and connect to that same host:port, unless you insist to only talk to yourself.
Should we have another osmo_sock_init that can set up a socket like this code I found somewhere at sysmocom to define both ends of a connection?
I'm not sure if it should be a new function for both connect + bind at the same time, or we simply bind using osmo_sock_init() and then have another call for the connect?
In any case, this is one of the things I wouldn't bother unless somebody really indicates he needs it.