News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Network Device Discovery

Started by Biterider, June 15, 2024, 05:43:14 PM

Previous topic - Next topic

Biterider

Hi
I have a situation where I need some advice from a network expert. 
I have a client application written in ASM that communicates with 2 devices on the same network. The client application is running on a host that has multiple adapters with their respective IP addresses. The 2 devices are connected via a switch to the host on one of its NIC adapters.

One of the devices was delivered with a communication library where I only have to enter the set IP address of the device and it communicates without any problems. No network mask, no host IP, nothing. The other device communicates via TCP and requires sockets to be set up. For this I need the host IP, the device IP, the port number (service) etc.

Now I was wondering how the first device figures out which network adapter to use. My guess is that it uses a discovery strategy like "ARP-who has" or it pings all the adapters. 

Does anyone have any advice on how to do this correctly?

Biterider

sinsi

Quote from: Biterider on June 15, 2024, 05:43:14 PMNow I was wondering how the first device figures out which network adapter to use.
The OS should take care of that, through the gateway.
Do you have more info? OS?
Tá fuinneoga a haon déag níos fearr :biggrin:

Biterider

Hi Sinsi
Thanks for the quick response.
There is no gateway in this configuration and the operating system is the latest Win10 Enterprise.

Lets make a drawing
                                 ----------
                                |          |
                                | DEVICE 1 |
                                |          |
             A                   ----------
             |                        |Y
         ----------                   |
        |          |              --------
    B---|   HOST   | X           |        |
        |          |-------------| SWITCH |
    C---|  CLIENT  |             |        |
        |          |              --------
         ----------                   |
             |                        | Z
             D                   ----------
                                |          |
                                | DEVICE 2 |
                                |          |
                                 ----------

Here the host (My PC) has NICs A...D connected to different networks. NIC X is connected to a switch which is connected to the devices in a completely different network configuration. In my case 192.168.000.000/16. I configured the adapter and the devices and passed the information to the client application. It all works fine.

For Device 1 I only had to specify the destination address (Y), while for Device 2 I had to set up a socket communication that needed the host address (X), the destination address (Z) and the port for the incoming protocol. The library for Device 1 somehow figured out that the adapter with the address X was the right one to use.

If I can replicate the behaviour of the library, the user of the client software has one less configuration parameter to worry about.

Biterider

sinsi

OK, A-D we can ignore, how is the switch configured? I assume it's not a router.
How are Y and Z getting their IP addresses? DHCP?

edit:
QuoteThere is no gateway in this configuration
Surely there must be?
Tá fuinneoga a haon déag níos fearr :biggrin:

Biterider

Hi
A-D are important as the OS reports them as possible IPs to use (e.g. GetAddrInfo API).
The switch is a fixed unmanaged layer 3 switch, 16 ports.
There is no DHCP server running in this configuration. 
The IPs are set manually on the devices (Y & Z) and also on the host (X).

Biterider


fearless

Could be worth using wireshark to see if the communication library is sending out a network discovery. It may be configured to then assign the first device it finds in a range of ip addresses as the main device to use. 

Or maybe it only works with 1 device and has some license check/behavior to only work with x amount based on license.

Are both devices exactly the same or do they differ at all, maybe a newer model or revision for one changes the requirement to have to specify more details to connect perhaps.

Biterider

Hi fearless
The devices are from different vendors. One is a calibrator and the other is the target device beeing calibrated.
Wireshark is definitively a good way to understand what is going on.

Thanks.
Biterider



Biterider

Hi
While experimenting with "iphlpapi" I found a way to find the adapter address. 
The process uses GetIpNetTable and GetAdaptersAddresses

The first call to GetIpNetTable gives me access to a list of all the IPs known to my system. If I browse through this list and look for the IP I am interested in, I can read out the "Adapter Index".
If I now call GetAdaptersAddresses, I will get a list of all the adapters in my system. Each entry in this list contains a lot of information, such as the "Adapter Index" and the IPv4 address. 
Now looking for the matching "Adapter Index" I get the address I was looking for.

I'm sure there are other ways, but it's worth a try.

Biterider