Hi all,
I am currently having an issue when creating a socket to connect to multiple tcp devices and udp devices using a specific adapter. Here's the scenario:
1. I have 1 pc with 2 network adapters eth0 and eth1.
2. I have 4 devices on eth0 through a network switch, 2 of the devices are using udp, and 2 devices are using tcp.
3. eth0 is setup to use the link local only through linux.
4. eth1 is DHCP on the network through linux.
The issue is, my 2 tcp devices that I am trying to communicate on eth0 (link-local) both require static IP address's (non link-local) on the link local network adapter...
So, I guess my question is, is there a way to create a socket linked to a specific network adapter (eth0) so that when I try to connect to the tcp devices the two adapters do not get confused...?
here's the code I am using to create the socket to connect to the tcp devices...
int length;
thissocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( thissocket < 0 )
return -2;
// Connect
tcpsocket->sin_family = AF_INET;
tcpsocket->sin_addr.s_addr = inet_addr( strAddress );
tcpsocket->sin_port = htons( DEST_PORT );
length = sizeof(struct sockaddr_in);
if ( connect( thissocket, (struct sockaddr *)tcpsocket, length ) < 0)
return -1;
return 0;
|
note: the ip address of the 2 tcp devices on the link local network are on the same gateway as the second network adapter set up for DHCP. I was under the assumption it would be ok to using a static IP with the link local configuration, but after testing, it failed to communicate with the devices...But in a way, it makes sense due to the difference in gateway address's.