Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need to get the list of network interface names and the network addresses to which they are bound. Unfortunately there's no standard method for this, and the two recommended CPAN modules (IO::Interface and Net::Interface) are buggy and unmaintained. So I am currently parsing the output of `ifconfig -a` or `ip addr show`. This works for my test machines, but I'm planning on distributing the script, so need to maximize portability among unixes.

Using SIOCGIFCONF looks like an interesting alternative, but the only perl example I found is very non-portable: Re: How do I get the local internet IP address?. sys/ioctl.ph isn't present in any of my perlbrewed perls, and even after running h2ph, it fails with "unsupported architecture" for macOS. But I did confirm with the following C program that SIOCGIFCONF is relatively portable when implemented right: https://gist.github.com/OrangeTide/909204.

Is there an alternative I missed?

Replies are listed 'Best First'.
Re: Getting list of network interfaces
by Corion (Patriarch) on Mar 26, 2026 at 10:18 UTC
      IO::Interace::Simple is part of the IO::Interface distribution and uses it under the hood, so it's equally buggy. On my macbook it only finds the loopback and 6to4 tunnel interfaces.
Re: Getting list of network interfaces
by Marshall (Canon) on Mar 27, 2026 at 06:58 UTC
    On a POSIX system there is a C function, getifaddrs(). Windows has GetAdaptersAddresses() An inline C function would probably work well for your application.
      IO::Interface and Net::Interface both use getifaddrs, but it isn't part of the POSIX spec. From the linux manpage:
      This function first appeared in BSDi and is present on the BSD systems, but with slightly different semantics documented— returning one entry per interface, not per address. This means ifa_addr and other fields can actually be NULL if the interface has no address, and no link-level address is returned if the interface has an IP address assigned. Also, the way of choosing either ifa_broadaddr or ifa_dstaddr differs on various systems.

      getifaddrs() first appeared in glibc 2.3, but before glibc 2.3.3, the implementation supported only IPv4 addresses; IPv6 support was added in glibc 2.3.3. Support of address families other than IPv4 is available only on kernels that support netlink.

        yes, you are right, further investigation:

        The getifaddrs function is not part of the POSIX standard. It is a common extension used to retrieve a linked list of network interface addresses on the local system.

        POSIX Status and Portability
        Non-Standard: As of the latest POSIX versions (such as POSIX.1-2001 and 2008), getifaddrs remains an extension rather than a standardized interface. Origin: The function first appeared in BSDi and has since been adopted by most BSD-derived systems (FreeBSD, macOS, OpenBSD) and Linux (via glibc 2.3 and later).

        Implementation Differences: Because it is not standardized, behavior can vary across platforms. For example:
        BSD: Often returns one entry per interface.
        Linux: Typically returns one entry per address assigned to an interface (e.g., separate entries for IPv4 and IPv6).

        POSIX Alternative: For strictly POSIX-compliant code, developers often use the ioctl system call with the SIOCGIFCONF request to enumerate interfaces, though this method is more cumbersome and has limitations regarding IPv6 support.