GetIpNetTable alternative for IPv6 - c++

I am trying to discover devices connected within a local area network. I have been successful using the GetIpNetTable function. However, this only returns IPv4 devices and I need to detect devices using IPv6 as well (such as mobile phones connected to the network). Is there a way that this can be achieved?

You're looking for the GetIpNetTable2 function, which can return both the IPv4 ARP table and the IPv6 neighbor table or both, depending on which address family you pass to it. This function requires Windows Vista/2008 or later, and there is absolutely nothing you can do on XP or earlier (except upgrade).

Related

How to display names and IP addresses of devices connected to a network using 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.

Ip Address resolution using Mac Address programatically

I am writing a discovery program, written in C++ that will run on linux, to enable me to determine if certain devices are connected to the network. I have the Mac Address of the other devices and I need to resolve their Ip Addresses.
I have checked /proc/net/arp and the devices don't appear.
I tried pinging the broadcast address and this doesn't reach the target and therefore the ARP cache is not updated. However, if I ping the ip address directly it is (but this is not an option).
Also, the devices can be configured with either static ips or can get them via dhcp.
Is there any way that I can determine the ip addresses given the Mac addresses?
Some years ago I'd have suggested to use RARP but it is not supported by Linux kernel any more. Unless there is already a solution I would suggest you the following home-made solution:
-You can use Packet sockets to implement your own Layer 2 protocol: instead of using IP as payload of the Ethernet frame you can select your own protocol code (for example: instead of 0x0800 for IP use 0xABAB, always a number greater than 1536)
-In each node you implement a simple server that use packet socket to read the frames with that protocol code or you could use pcap, as you prefer.
-Whenever you need the IP address of another node you send an Ethernet frame to that MAC address. The server will read the new frame and respond with another frame conveying its own IP address.
-If you choose this solution please remember the payload has to be at least 46 Bytes long, so you may need to use padding. Also you can use the TLV (type length value) format for your own protocol.
Read this:
http://en.wikipedia.org/wiki/Ethernet_frame
http://man7.org/linux/man-pages/man7/packet.7.html
I hope this helps.

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

Detecting IP addresses of network cards and ethernet devices with Windows API

I am using the Microsoft code here to learn how to detect IP addresses of cards and devices:
http://msdn.microsoft.com/en-us/library/aa365949%28v=VS.85%29.aspx
I notice some strange behavior.
I have a system with two ethernet cards; one is connected to the internet and one is connected to an ethernet device. When I run the sample code, it will always give an IP address for the card that has the internet connection, but the other card will come up as 127.0.0.1 with a subnet mask of 255.0.0.0 unless I have the ethernet device plugged in and powered. But the card should have a default IP address whether its actually connected to anything, right? How can I modify this code to detect that?
There's a third IP address detected that appears to be just empty data. I tried this on another computer with a single network connection and it also detected a second, non-existent connection. Each time, this connection has an IP address of 127.0.0.1 and a subnet mask of 255.0.0.0. What does this represent?
Given the demo code, would this be easy to edit to be able to detect IP addresses of devices on the network that any card is connected to? I really just want to detect the IP address that a single ethernet device is set to. The device is directly connected to the card. The reason I want to do this is because the device and card obviously don't play nice when their subnets are different and I want to detect when this is the case.
Thanks!
R
That address of 127.0.0.1 is not the address of the other card. It is the address of the loopback adapter - a virtual IP address that can only send and receive data with itself. The other NIC (that isn't plugged into a network) is simply not in the address table.
You may just want to call GetAdapterAddresses and filter out all adapters with an IFType of IF_TYPE_SOFTWARE_LOOPBACK.
If you want to see use existing tools that provide the same thing, type either of the following from a command prompt:
route print
(This will dump the routing table)
ipconfig /all
(this will show you the state of ALL adapters including the loopback)
Dunno exactly, you should at least specify your configuration, is it DHCP or static IP, or something else?
It's the loopback interface
Some broadcasting may be required. ARP is the link-layer protocol, so it can be used without the IP address to broadcast a link to find the devices and then to detect their address. Don't know about windows precisely, but on Unix an arping command is present for this.

Get the ip addresses of an interface

Using the output of "ipconfig /all" i can get what I need but I want a more reliable technique to get ip of an interface (practically the interface has to be identified by it's name) in case of ipconfig was corrupted or was not available for any reason.
I'm not sure what you mean by "server and client", but if you're looking for an API that tells you the IP address(es) associated with the local machine's network interfaces, check out getifaddrs() (for Linux/MacOSX/POSIX) and GetAdaptersAddresses() (for Windows). If you want a usage example for those calls, have a look at the GetNetworkInterfaceInfos() function in this file.
(If you wanted to get the IP address of a client connected to the local machine, call getpeername() on the socket that is associated with that client's connection)
Since you mentioned ipconfig, I assume you want to do this on windows.
Windows has a set of IP Helper apis designed for retrieval and modify networking settings.
And here is a simple sample: http://msdn.microsoft.com/en-us/library/aa366298(VS.85).aspx