Click here to Skip to main content
15,881,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application that needs to discover devices connected to a Windows PC. That PC may have multiple Ethernet adapters. This is done by sending a broadcast UDP/IP packet to which the device replies. Typically one adapter is connected to a WAN and the other a LAN. If Windows 'uses' the LAN as the primary adapter, or the WAN adapter is disabled, all goes well. If not, the reply doesn't make it back to the application (Wireshark verifies that the device receives and replies to the request). How can I force Windows to use the LAN adapter for broadcasting the discovery request and receive the reply?

What I have tried:

I've tried multiple web searches with no meaningful results.
Posted
Updated 12-Mar-19 5:57am
Comments
Rick York 11-Mar-19 16:57pm    
Using Wireshark with both adapters enabled, have you verified that the message goes out both of them? Are the addresses of the adapters in different subnets or the same one? This can make a HUGE difference.
[no name] 11-Mar-19 17:08pm    
Why can't you just Ping a range in order to "discover"?
11917640 Member 12-Mar-19 2:58am    
You need to bind UDP socket to the adapter IP address. Using GetIpAddrTable function you can enumerate all adapters and get their addresses.
cwparker 12-Mar-19 9:20am    
The two adapters are connected to two different physical networks. For example, one adapter has an IP of 192.168.1.207 and the other has an IP of 172.28.74.254 (both with a subnet mask of 255.255.254.0). Windows thinks the adapter connected to 172.28.74.254 is the primary adapter. If the device is connected to the 172.28.74.x WAN, the app finds it. If it is connected to the 192.168.1.x LAN, it does not find it unless the 172.28.74.254 adapter is disabled. The IP address of the device is unknown, but for this example, let's say it's 192.168.1.2. It really doesn't matter what it's IP is. The problem is that the app can't find it if it isn't connected to the 'primary' adapter. For this app, there's no problem in having the user specify which adapter to use. It is a problem to disable the 'primary' adapter so that the device can be discovered on the 'secondary' adapter.

Yes, I've tried a lot of things. Selecting the adapter's IP with bind() does not work. My guess is because I'm trying to send and receive broadcast packets.

Since the device's IP address is completely unknown (may not be 192.168.1.x, could be 172.172.172.172 for example), it isn't really possible to ping a range to discover it.

I know Wireshark somehow manages to allow you to select the adapter you're sniffing, so it must be possible. I just don't know how to do it.
Rick York 12-Mar-19 10:54am    
I am not sure if this will help but take a look at MSTCPIP.h and the functions GetAdaptersInfo() and SetAdaptersInfo(). They might help lead you to what you need. One possibility is to use those and programmatically disable an adapter so you can try the other one and find the machine.

First glance at the quote
How can I force Windows to use the LAN adapter for broadcasting the discovery request and receive the reply?


would constitute an exploitable security hole sizeof Texas. It is usually up to network admins to configure adapters and requires root/admin access to do so.

Other than that each adapter has its own IP address. So knowing that address you can connect to the adapter in question and as long as there some type of server is running behind that adapter you can query it for whatever that server provides. It sounds like you searching for the bridge adapter:
"https://en.wikipedia.org/wiki/Bridging_(networking)"
 
Share this answer
 
v3
Comments
cwparker 12-Mar-19 13:38pm    
The network adapter on the PC running the app each have a unique IP address associated with them. No security issue here. Just a PC with more than one Ethernet 'port'. This is true for almost all laptops that have a physical Ethernet port and WiFi. The problem is selecting which adapter (port) Windows uses for sending out the broadcast message used to discover the 'device' that is trying to be found.
steveb 12-Mar-19 14:18pm    
Are you connecting to that PC remotely from WAN or from LAN?
Sounds like you need a router.

The PC (with ONE physical adapter) goes to the router; the (wired and / or wireless) router in turn is connected to the WAN and the LAN.

To me that is more "typical" than what you're describing (2 NICs).
 
Share this answer
 
v2
Comments
cwparker 12-Mar-19 13:40pm    
see comment for Solution 2. Not a WAN vs. LAN issue. I just used that in my example. All the Ethernet adapters could be connected to separate physical LANs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900