Overview
Features
Download
Documentation
Community
Add-Ons & Services

Default Network Interface

Please post support and help requests here.

Default Network Interface

Postby Cyber » 10 Dec 2012, 19:23

How can I find the default network interface?

I tried: const NetworkInterface& theDefaultInterface = NetworkInterface::forIndex(0);

The documentation says:

static NetworkInterface forIndex( int index);
Returns the NetworkInterface for the given interface index. If an index of 0 is specified, a NetworkInterface instance representing the default interface (empty name and wildcard address) is returned.
Throws an InterfaceNotFoundException if an interface with the given index does not exist (or IPv6 is not available).


But I always get the InterfaceNotFoundException and I saw that forIndex just does a looup in the map of network interfaces (no special handling of index 0 and there is no entry with an index of 0 in the map)
I'am working on an Windows 7 (64) Machine.
Cyber
 
Posts: 1
Joined: 04 Aug 2012, 11:20

Re: Default Network Interface

Postby alex » 12 Dec 2012, 04:52

The documentation is wrong (leftover from previous version) and there is no interface with index 0; you have to pass a valid index to get a NetworkInterface. If you need first interface, call NetworkInterface::map(); interfaces in the map will be ordered by indices, so you can just grab the first one. See also How to change the binding order of network adapters
alex
 
Posts: 1113
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron