Re: How to know if a network adapter is connected
- From: "fred_d" <duchassin@xxxxxxxxx>
- Date: Fri, 10 Oct 2008 13:37:58 +0200
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.
.
- Follow-Ups:
- Re: How to know if a network adapter is connected
- From: Paul G. Tobey [eMVP]
- Re: How to know if a network adapter is connected
- From: fred_d
- Re: How to know if a network adapter is connected
- References:
- How to know if a network adapter is connected
- From: fred_d
- Re: How to know if a network adapter is connected
- From: Helge Kruse
- How to know if a network adapter is connected
- Prev by Date: Re: GetDriveType
- Next by Date: Re: How to know if a network adapter is connected
- Previous by thread: Re: How to know if a network adapter is connected
- Next by thread: Re: How to know if a network adapter is connected
- Index(es):
Relevant Pages
|
Loading