Re: How to know if a network adapter is connected





it could occure that both network adapters are connected. What address
would you give in this case? So you should not ask for the adapter that is
connected, but for the adapter that received the packet. In the bind call
you passed a SOCKADDR_IN that is configured for INADDR_ANY.


Yes of course if the two adapters are connected i perefer use the USB
adapters .


You should create two sockets, detect the IP addresses of the adapters
with the IP Helper API and bind each socket to one adapter. Now you can
identify where the packet has entered your device and give an appropriate
answer.



Yes but i found this method quite difficult and not very readable. I've
tried to bind the socket one time i receive something but it dose't work.
The bind function always return SOCKET_ERROR.
I tried this :

if ((len=recv(sock, buf, 548, 0))>0)
{
VisuAdresseIPEthernet();//--> 135.150.5.65 in Chaine[0]
strcpy(&ChaineIP[0], Chaine[0]);
addr2.sin_family = AF_INET;
addr2.sin_addr.s_addr = inet_addr(&ChaineIP[0]);
addr2.sin_port = htons(67);

test = bind(sock, (LPSOCKADDR)&addr2, sizeof(addr2)); // test is always
SOCKET_ERROR

}



BTW: The IP Helper API reports only adapters that are connected. ;-)
So if i power on my application before having connected the network card ,
my dhcp thread will not work ! At this time i power on my instrument and i
create a trhaed after creating a sock with INADDR_ANY.


You didn't see any other solution ?

Thanks to help me.


.



Relevant Pages

  • Re: UDP question.
    ... bind socket1.network adapter1... ... bind socket2 network adapter2 ... But I get the result is also 75000 packet per second, ... I am not really sure, but I think the bind to an adapter under linux only chooses the source ip, not really the adapter used to send the packets. ...
    (Linux-Kernel)
  • Re: UDP question.
    ... >> My two adapters has two different IP address, and I bind one IP ... >> do you mean that I alloc two socket and bind different IP is not ... > sending a packet *to* 1.2.4.5, it will go out the first interface. ... not real bind the adapter? ...
    (Linux-Kernel)
  • Re: How to know if a network adapter is connected
    ... This is the only way I know to identify the network adapter, ... Yes i agree but if the adapter is not connected to the network, the bind() function return SOCKET_ERROR. ... So i need to bind every socket each time i call the recv ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: socket send help
    ... That's true for hardware firewalls ... merely hook socket calls", I still don't see failing a bind() to INADDR_ANY while allowing a bindto 127.0.0.1. ... If some physical network adapter should be unavailable while the loopback is allowed, fine; passing INADDR_ANY should work and bind to the loopback adapter. ... The time to bindto localhost is when we specifically do not want to be available on an external network adapter. ...
    (comp.lang.python)
  • Re: UDP question.
    ... >>> My two adapters has two different IP address, and I bind one IP ... >>> do you mean that I alloc two socket and bind different IP is not ... >> interface address it came from. ... why dont you try a different subnet for the other adapter & its dest. ...
    (Linux-Kernel)

Loading