Enumerating network interfaces

661 views
Skip to first unread message

Kenneth Porter

unread,
Aug 18, 2022, 4:13:31 AM8/18/22
to wxWidgets Users
I'm looking for a portable way to enumerate network interfaces and their
properties. Boost::ASIO lacks it. I see the wxSocket class but nothing
obvious for listing interfaces. I found a Python library written in C to do
it but the bindings are for Python and not generic for C/C++ clients or
other languages. Can anyone recommend a suitable library?

The Python library: <https://github.com/al45tair/netifaces>

Vadim Zeitlin

unread,
Aug 19, 2022, 9:54:30 AM8/19/22
to wxWidgets Users
On Thu, 18 Aug 2022 01:12:59 -0700 Kenneth Porter wrote:

KP> I'm looking for a portable way to enumerate network interfaces and their
KP> properties. Boost::ASIO lacks it. I see the wxSocket class but nothing
KP> obvious for listing interfaces.

No, there is definitely nothing for this in wx.

KP> Can anyone recommend a suitable library?

Sorry, I don't know of any. You could try searching for the names of the
functions used for implementing this using code search, if this doesn't
find any libraries doing this, you're probably out of luck.

KP> The Python library: <https://github.com/al45tair/netifaces>

This one does seem to contain everything you need but you'd have to
separate the useful stuff from all the Python chaff...

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Maarten Bent

unread,
Aug 19, 2022, 9:59:14 AM8/19/22
to wx-u...@googlegroups.com
Hi,

I think libpcap/npcap should be able to do this.

Maarten

Kenneth Porter

unread,
Aug 19, 2022, 2:45:44 PM8/19/22
to wx-u...@googlegroups.com
On 8/19/2022 6:59 AM, Maarten Bent wrote:
I think libpcap/npcap should be able to do this.

Maybe, although its primary focus is packet capture using a custom driver on Windows. Note also that it has a more restrictive license than wx.

https://npcap.com/


Igor Korot

unread,
Aug 19, 2022, 3:03:07 PM8/19/22
to wx-u...@googlegroups.com
Hi, Kenneth,
Did you see this:
https://stackoverflow.com/questions/18495619/how-to-get-all-network-interface-name-and-information-in-c

Thank you.

>
>
> --
> Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
> ---
> You received this message because you are subscribed to the Google Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/fd473eaa-de31-6c94-c43b-aa0eeac7541e%40sewingwitch.com.

Igor Korot

unread,
Aug 19, 2022, 3:20:45 PM8/19/22
to wx-u...@googlegroups.com
Hi,

On Fri, Aug 19, 2022 at 2:02 PM Igor Korot <ikor...@gmail.com> wrote:
>
> Hi, Kenneth,
>
> On Fri, Aug 19, 2022 at 1:45 PM Kenneth Porter <sh...@sewingwitch.com> wrote:
> >
> > On 8/19/2022 6:59 AM, Maarten Bent wrote:
> >
> > I think libpcap/npcap should be able to do this.
> >
> > Maybe, although its primary focus is packet capture using a custom driver on Windows. Note also that it has a more restrictive license than wx.
> >
> > https://npcap.com/
>
> Did you see this:
> https://stackoverflow.com/questions/18495619/how-to-get-all-network-interface-name-and-information-in-c

Or even this: https://stackoverflow.com/questions/19227781/linux-getting-all-network-interface-names

?

Thank yuo.

Nathan Hartman

unread,
Aug 21, 2022, 9:30:16 AM8/21/22
to wx-u...@googlegroups.com
On Windows you can get the list of network interfaces by a call to
WSAIoctl() with SIO_GET_INTERFACE_LIST on a temporary socket. (You
open the socket, do the ioctl, and then close the socket unless you
want to continue using it.) SIO_GET_INTERFACE_LIST is supported since
at least Windows XP.

See:
http://tangentsoft.net/wskfaq/examples/getifaces.html
https://social.technet.microsoft.com/Forums/windows/en-US/72e7387a-9f2c-4bf4-a004-c89ddde1c8aa/how-to-fix-the-global-broadcast-address-255255255255-behavior-on-windows
https://msdn.microsoft.com/en-us/library/windows/desktop/bb736550(v=vs.85).aspx

On Unix, including BSD, Linux, and macOS, you can do it with a call to
getifaddrs() ... freeifaddrs().

See:

https://man7.org/linux/man-pages/man3/getifaddrs.3.html
https://man.openbsd.org/getifaddrs
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getifaddrs.3.html

Cheers,
Nathan

Kenneth Porter

unread,
Aug 21, 2022, 12:27:08 PM8/21/22
to wx-u...@googlegroups.com
--On Sunday, August 21, 2022 10:30 AM -0400 Nathan Hartman
<hartman...@gmail.com> wrote:

> On Windows you can get the list of network interfaces by a call to
> WSAIoctl() with SIO_GET_INTERFACE_LIST on a temporary socket.

I found this API on Windows:

<https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersaddresses>

Reply all
Reply to author
Forward
0 new messages