How to display names and IP addresses of devices connected to a network using C++ - c++

I am making a program where I have to use TCP/IP connection to transmit and receive data between devices. I would like to be able to detect the names and IP addresses of all devices that are using the network(The device running the program is also on the network). I am using C++ on windows, I looked through the Windows Native Wifi API but couldn't find anything. Is there an efficient way to get the names and IP addresses of all devices connected to the network?

There are a few competing techniques, such as Apple Bonjour. That's pretty much a clue that there is no single way that gives you all names of all devices - this is not standard IP-level functionality.

Related

C++ application: discover other IPs on LAN

I want to create a C++ application that can be used (in part) to communicate between users on a local area network using UDP. Each instance of the application will have a thread dedicated to listening for other instances of the application and broadcasting its presence to other instances.
Is there a reliable way to perform this type of broadcast/listening on the LAN using pure C++ and POSIX system calls? I know there's no generally reliable way to find all IPs on a LAN, but I assume this is only because other devices are not willing to respond to pings.
Don't re-invent the wheel. There are two existing technologies, that, when combined, solve your problem in a standardized, well-designed, proven manner:
RFC6762 mDNS (Multicast DNS) is a protocol that works almost exactly like DNS, except it works using IP multicast. Instead of sending your DNS request to a unicast address, you send your DNS request to a multicast group, and any member of that group can answer your request (so you may get multiple answers).
RFC6763 DNS-SD (DNS-based Service Discovery) is a way to encode Services as DNS entries, which allows you then to retrieve Services from DNS using specially encoded hostnames. (For example, looking up the hostname _ipp._tcp.example.com would return a list of all printers that support the Internet Printing Protocol over TCP within the domain example.com)
So, we have one protocol that allows us to ask DNS about Services, and we have one protocol that allows us to ask a group of hosts to answer DNS queries … when we put the two together, we get a way of asking hosts for services! The combination of those two protocols is sometimes called Zeroconf networking, and is already implemented in macOS, iOS, tvOS, and watchOS (where it is called Bonjour), Android, most Unices (via Avahi, a portable implementation of those two protocols), and many home devices such as TVs. E.g. Spotify Connect, ChromeCast, Philips Hue and many others are also based on it. It's how iTunes devices find each other on the local network, for example.
Unfortunately, support in Windows is still limited, at the moment it seems to only exist for Windows 10 apps implemented in ECMAScript. (However, nothing stops you from shipping your own implementation with your app, and AFAIK, both Avahi and Apple's mDNSResponder work on Windows.)
So, what you would basically do is to send an mDNS query to the mDNS multicast group and ask for _myprotocol._udp.local. Then, assuming that your application registers itself with the OS's mDNS service (i.e. Bonjour on macOS, Avahi on Unices, …), you would get back a list of all hosts on the local network that support your protocol.

C++ Multicasting while connected through Mobile Hotspot device

I'm new to network programming in C++ and I'm writing a very simple app that is suppose to do a multicast.
From my research I see one of the first things I need to do is find out if my router supports multicast forwarding and multicast routing protocols.
My point of confusion is, I am connected to the internet via a mobile hotspot device, and I don't exactly know how to find out if it supports multicasting.
Does anyone know how I can go about finding out if I can indeed send multicasts with this type of wireless connection?
Thanks
I found that on a linux box (that supports ifconfig) you can use the ifconfig command to see if multicast is supported. eth0 for example will show Multicast along with some other information.
For windows in the command line:
netsh interface ip show joins
should tell you

Windows WiFi network devices

I'm creating a WiFi program for Windows, I'm new to network programming.
I'm using the Native Wifi API to get information about a network but now I want information about the other devices that are connected to a network.
Does anybody know what I should learn to accomplish this? Do I need to use winsock?
You can do this via UPnP (assuming your AP supports UPnP, but most do).
You'd connect to the WLANConfiguration service of your UPnP access point, and read the TotalAssociations to get the number of associated devices, and the AssociatedDeviceMACAddress and/or AssociatedDeviceIPAddress variables to get the addresses of the associated devices. The latter might give you IPv4 or IPv6 addresses, or it might give you host names.
The TotalAssociations variable is "evented", which means you can have the access point tell you want the number of associated devices changes, and re-enumerate their addresses when that happens.
Microsoft also provides a UPnP API that may be helpful (though I've never used it personally, so I can't say much more about it).
References
UPnP Architecture specification
WLAN Configuration Service specification

Detect devices on local network for client-server connection in C++

I'm trying to implement an auto-connect feature for my Android application DroidPad, which is basically a TCP server running on an Android phone which the PC application connects to.
To make the process easier for the user, is there any way in (portable?) C++ to scan the IP addresses on the local subnet, possibly ones with a certain open port? I've tried using UDP broadcasting, but couldn't get it to work. I'm currently using the wxWidgets toolkit for GUI and libraries.
Any ideas?
I found a solution: wxServDisc. It uses mDNS (aka Zeroconf / Bonjour) to discover devices on a subnet, and is also based on wxWidgets.

USB proxy driver or equivalent solution?

Problem: Mediate USB traffic/data
I would like to accept inbound traffic on a specific USB port and replicate it exactly as outbound traffic on another specific USB port, in effect accomplishing a USB proxy. By extension, then, the connections need to be two-way. An additional requirement is that the port must be able to fake its identity (vendor ID, product ID, ...) as seen by an external device. Should the given solution also be able to dump/log the raw traffic, that would be fantastic, although not a requirement. Target platforms are Windows and/or Linux (any will do).
Before going on an epic journey and writing a custom driver, which is fairly likely to induce brain damage, I would like to ask if anyone has ever done anything similar, or could possibly conceive of the pieces needed to assemble this puzzle. :)
I don't think this is doable out of the box, without extra hardware.
What kind of device can you expect to connect to the "upstream" port of the proxy? Assuming there's a regular device (let's say a mouse, just as an example) on the "downstream" port, the device at upstream needs to be a USB host in order to handle the USB device in a meaningful way.
But you can't connect the USB port of your computer (which already is the host for all its USB root ports) directly to another computer, that's a total violation of USB's network topology. Both ports contain +5 V power rails, and if you connect those together, you're likely in for a shock. And/or a private fireworks display. Or a trip to your nearest motherboard and/or PSU retailer ...
Also, since USB is quite dynamic and so on, I don't think you can expect the bitstream from one port to be meaningful if repeated out another port, since address information etc might change.
There are 100% software USB analyzers, like http://www.usblyzer.com/, but I'm not so sure about proxies like what you describe.
At my work we have used this Beagle USB Analyzer. It sits between device and host and captures all traffic without interruption. It works in windows and linux and functions even with USB 2.0 highspeed ports.
http://www.totalphase.com/products/beagle_usb480/
Highly recommended.