4

I am trying to use winpcap for an application that is to be used on multiple servers in a production line. One thing that annoys me so far is the Windows 7 device naming convention, which is a long hex string and changes from server to server (i.e. \Device\NPF_{6F2E340D-FD43-4505-81C2-735716D02F15} (Linux makes this easier with just the eth0, eth1, ... convention). Since each server will be using 5 network adapters, I would like to keep from having to keep a configuration file with the device names or keep from changing the source code to accommodate the device name changes. In addition, the cat5 hook up will be going to different devices on separate networks and the port assignments should always stay the same per drawing.

So my question is, is there some easy way to manage these device names under windows, such as being able to easily rename them somehow in the registry? When I looked in the registry, the hex string is shown in many entries and also shows up in folder names, so I was not sure if that would become some hassle to change or not. Or perhaps, is there a way with winpcap to grab the friendly name of a device that one can set via the network connections page and get the hex device name result that way (similar to findalldev_ex()). Any other suggestions are also welcome.

PS: I know I can use bind() to bind to ip and ports or use winsock etc, but the application and hardware interfacing to other devices is complicated due to multiple network adapters needing to have the same IP address and that conflicts in windows, hence the winpcap option in promiscuous mode creating all raw messages.

  • Note that that is a GUID, not simply a string, and most programmers would treat it as a higher level Abstract Data Type, meaning they parse it, and expect it to consist of hex characters with dashes at specific positions, etc. That code will likely break if you were to change it to something like 'NIC1'. Second, these were not to be user readable names. the Windows analog for /dev/eth0 is "Local Area Connection X". Linux uses its own underlying non-user name, indicating the devices PCI bus address, for device mapping. have you ever had eth0 and eth1 just swap themselves on reboot? I have. – Frank Thomas Apr 17 '15 at 1:18
  • Currently I am able to extract and parse the GUID from the pcap_findalldevs_ex call and use it as a const char* for the device name. That is not a problem. As far as Linux changing the eth0 and eth1 by itself, I have not ran across this issue yet with multiple servers deployed in the field for a few years now. Thanks for making me aware of this potential issue. However, that eth0 convention made the Linux based deployment an ease, but now we are porting things into a Windows environment and that is where the GUID becomes more tricky. – Pita Apr 17 '15 at 1:31
4

How do I get a network connection's "Connection Name"?

On Windows getmac can be used to retrieve both the "Connection Name" (friendly name) and the "Transport Name" (GUID).

getmac /fo csv /v

Example output:

"Connection Name","Network Adapter","Physical Address","Transport Name"
"Local Area Connection","Realtek PCIe GBE Family Controller","F0-BF-97-62-95-5D","\Device\Tcpip_{45B9E87F-83FB-4829-A751-6B62656CC1A8}"
"Wireless Network Connection","Atheros AR9285 Wireless Network Adapter","CC-AF-78-B2-4C-09","\Device\Tcpip_{B108BB0B-CCDC-4ACA-9DFE-5A2F17BC138D}"
"Bluetooth Network Connection","Bluetooth Device (Personal Area Network)","CC-AF-78-B2-4C-0A","Media disconnected"

How do I rename a connection?

netsh can be used to rename a network connection.

netsh interface set interface name="Local Area Connection" newname="New Name"

How can I automate all of this?

You can use the above commands in a batch file when installing your product to automatically create a custom local configuration file.


Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • getmac - Display the Media Access Control (MAC) address and list of network protocols associated with each address for all network cards in each computer, either locally or across a network.
  • netsh - Configure Network Interfaces, Windows Firewall, Routing & remote access.
| improve this answer | |
  • I will look into these. Thank you for the tips! – Pita Apr 18 '15 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.