Overview
Features
Download
Documentation
Community
Add-Ons & Services

Revamping NetworkInterface class

General discussion regarding the development of POCO for contributors.

Revamping NetworkInterface class

Postby philipp » 17 Dec 2011, 22:11

I'm looking at the NetworkInterface class and a few things stand out.

It's missing the attributes MTU, Running, Broadcast, Multicast, Loopback, PointToPoint. I've a patch for this which I will post, and it's trivial enough.

The second observation is that the index() function is misleading. It doesn't return the OS's index as known by SIOCGIFINDEX, for instance. It's overloaded instead to indicate the presence of IPv4 and/or IPv6 addresses. Frankly, I'd rather have it just return the index, and have a different mechanism for testing for IPv4 and IPv6 state.

On the subject of IPv4 and IPv6 state, an interface can have multiple addresses (including having both IPv6 and IPv4, or multiple instances of each).

Why not have a list of address/netmask/broadcast address triples for IPv4 and IPv6, and have functions like supportsIPv4() just test for a non-empty list of IPv4 addresses?
philipp
 
Posts: 16
Joined: 08 Dec 2011, 03:59

Re: Revamping NetworkInterface class

Postby philipp » 22 Dec 2011, 02:00

Revamping the layout of addresses to preserve the association of address-to-physical-interface mappings (i.e. so that one can distinguish an interface having multiple aliases correctly) requires more thought as it's potentially destabilizing.

Perhaps a new subclass like NetworkInterfaceV2 would be in order.

In any case, these changes should mesh with the current layout of addresses. They are adding support for retrieving the:

* MTU;
* (snmp)index (i.e. what's known as ifindex in Unix);
* destination address on point-to-point interfaces;

and detecting the following attributes:

* being point-to-point (e.g. IPSec, DSL or PPP);
* supporting multicast (useful for UPnP, etc);
* supporting broadcast;
* is loopback;
* is point-to-point;
* is up;
* is running;

I'm posting the changes here:

ftp://ftp.redfish-solutions.com/pub/poc ... face.patch

reviews appreciated.
philipp
 
Posts: 16
Joined: 08 Dec 2011, 03:59

Re: Revamping NetworkInterface class

Postby guenter » 23 Dec 2011, 18:04

Thanks for the patch. Looks good mostly. What's missing is some basic Windows support. At least isUp() should also work on Windows. Not sure how much of the other new functions can be implemented on Windows.
Also, the whole interface index issue needs to be revisited. When I implemented the class I was under the impression that the interface index was an IPv6 specific thing. Apparently, it's also used for IPv4 interfaces and what got me confused was that if_nametoindex() etc. are part of the IPv6 socket extensions. Therefore, we should have just one index() member function which returns the correct index for both IPv4 and IPv6 interfaces (or addresses) and do the test for IPv4/6 (supportsIPv4/6()) some other way.
guenter
 
Posts: 1106
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Revamping NetworkInterface class

Postby philipp » 23 Dec 2011, 21:08

Yes, I tried to figure out where the _WIN32 constructor code was for NetworkInterfaceImpl() but couldn't find it... in any case I don't have a Win32 development environment to test on.

Between GetAdaptersInfo() and GetInterfaceInfo() you should be able to get most of the attributes. Maybe GetIpInterfaceEntry() as well.
philipp
 
Posts: 16
Joined: 08 Dec 2011, 03:59

Re: Revamping NetworkInterface class

Postby philipp » 15 Feb 2012, 03:05

Ok, figured out the WIN32 code, including the fact that it was using the deprecated GetAdaptersInfo() interface except when POCO_HAVE_IPv6 was turned on.

Sent in a patch for this issue.

Also noticed that there's no way to get at the MAC layer information about the interface.

There are places where I need access to the MAC address information... as this is one way to determine what instance of machine the process is running on (since IP addresses aren't unique with RFC-1918 addressing).

Having a single NetworkInterface instance per actual H/W NIC, but having an associated list of addresses with it (i.e. zero or more IPv4 and IPv6 addresses, and 1 MAC address) would be useful... but that's not how it's structured right now.
philipp
 
Posts: 16
Joined: 08 Dec 2011, 03:59

Re: Revamping NetworkInterface class

Postby philipp » 18 Feb 2012, 00:28

I've made changes to IPAddress and NetworkInterface. Here are the patches:

ftp://ftp.redfish-solutions.com/pub/poc ... ress.patch
ftp://ftp.redfish-solutions.com/pub/poc ... face.patch

and a sample program called "interfaces" that exercises the NetworkInterface code (it works a bit like "ifconfig" on unix):

ftp://ftp.redfish-solutions.com/pub/poc ... aces.patch

if anyone wants to review them for inclusion upstream.

By the way, BSD, Mac OS and Linux all use the build/config/* files to pull their values... The Windows builds do not. So, questions:

(1) How do I turn -DPOCO_HAVE_IPv6 on for the compiler?
(2) Has anyone tried building (for instance) /D_WINVER=0x501 as a library build, and then linking and running on Vista or Win7?
(3) How important is XP (unpatched) compatibility? A lot changed in XP-SP1, and if someone is still running XP without patching, is it worth supporting them?

-Philip
philipp
 
Posts: 16
Joined: 08 Dec 2011, 03:59


Return to Contributors

Who is online

Users browsing this forum: No registered users and 1 guest