The problem
I have a computer that is supposed to connect to two machines (or rather sets of individual devices) via TCP. To make things tricky, these two machines share the same IP address range and also have partially identical addresses, only one is connected via one ethernet adapter and the other one via a second ethernet adapter.
Note: The address ranges were not defined by me, but by the manufacturers of these machines. I unfortunately have to live with them, as they are.
The program that should do that job is written in C/C++. The connections are outgoing from the program's point of view, so I can't just bind incoming connections and keep their id.
Possible solution
After some research (e.g. here: Problems with SO_BINDTODEVICE Linux socket option), I tried to bind the socket to a device using
setsockopt(socket, SOL_SOCKET, SO_BINDTODEVICE, "adapter name", strlen("adapter name");
As it turns out, this would only work, if the program was run with superuser privileges, which I would try to avoid. Otherwise, the function returns an error code, which translates to permission denied (I forgot the exact phrase).
Other solutions?
Is there any other way, how I could achieve that?