openFrameworks
openFrameworks copied to clipboard
OFXUdpManager - No way to select network interface?
I have a customer with two network cards in his computer. Our software both sends and receives on a multicast address, and in both cases, I believe it is choosing the "wrong" interface.
When sending to Multicast, no data is being received on a remote computer. If the computers IP is specified, I get an EAFNOSUPPORT error.
Looking through the docs and the code, I can't find a way to specify which network interface to use for sending and receiving, both in unicast or multicast applications. Is this possible? If not, this would seem to be a critical feature!
Hi, there seems to be no such way in the current implementation, but as it relies on <sys/socket> you can modify this class to add support for different network interfaces.
in file ofxUDPManager.cpp
in the following functions change the line that ends with INADDR_ANY;
and pass to it the IP address of the interface you want to use so it looks like
bool ofxUDPManager::Bind(...) {
...
saServer.sin_addr.s_addr = inet_addr("142.250.73.196"); // or which ever ip address your interface has
}
bool ofxUDPManager::BindMcast(...){
mreq.imr_interface.s_addr = inet_addr("142.250.73.196");// or which ever ip address your interface has
}
This might be useful info https://unix.stackexchange.com/questions/648718/force-programs-bind-to-an-interface-not-ip-address https://www.ibm.com/docs/en/ztpf/1.1.0.15?topic=apis-bind-bind-local-name-socket https://ubuntuforums.org/archive/index.php/t-1074742.html
I have not tested any of this but it makes sense to me. I might be wrong though
Thanks! Would the process be the same in Connect() for sending data?
I dont think you need to change anything in Connect. But you should try. Sorry if I cant help more.
@MadlyFX also just to check are you using the ConnectMCast and BindMCast functions?
https://github.com/openframeworks/openFrameworks/blob/master/addons/ofxNetwork/src/ofxUDPManager.h#L129-L131
@ofTheo Yes, I am. I seem to be able to replicate my customers issue by following Roy's suggestions, but intentionally setting an incorrect s_addr IP (resulting in a EAFNOSUPPORT on my machine.) This would, to me, seem to confirm my suspicions.
It's very common for media servers to have multiple network interfaces, so an easy way to choose which one to use would be fantastic.
@MadlyFX if you end up finding a good solution, please send a PR - sounds like it would be a handy feature!
One other thing to consider is it could be something at the router/swtich level. I haven't used multicast a lot, but use broadcast addressing all the time and that working can be very dependent on the router or router settings.
I remember the legacy version of ofxArtnet used to have a function you could select your interface by your local IP The code is still out there in a branch called legacy https://github.com/hiroyuki/ofxArtnet/tree/legacy/libs/artnet/src