The 'getifaddrs' function, however, is pretty useful and convenient
for system programming. Does anyone has plan to implement it in Go, or
it is already implemented somewhere?
Thanks
Sorta-kinda. This function is not yet standardised (that I know of,
at least) and the semantics are a little different between *BSD
systems and Linux. (And I have no idea what the Windows ports would
manage).
Quoting from the Linux manual page:
CONFORMING TO
Not in POSIX.1-2001. 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.
> The 'getifaddrs' function, however, is pretty useful and convenient
> for system programming. Does anyone has plan to implement it in Go, or
> it is already implemented somewhere?
I agree that knowing both available network interfaces and currently
assigned addresses is useful (I have some code which wants interfaces
right now, and can easily imagine wanting addresses).
My problem is what is a good interface to this sort of information for
go? Firstly, is it possible to unify the semantics on the current
platforms that go supports? If so, one or more interfaces in the os
package would seem sensible to me. (Off the top of my head:
something to get a list of interfaces, and something else to get a
list of addresses per interface, to allow for both link level
addresses and multiple aliases on single interfaces. Aliases on IPv4
interfaces aren't terribly uncommon, and aliases on IPV6 interfaces
are required.)
Most of my OS work has managed to avoid networking, so while I could
figure out answers to the questions I've posed above (at least for
those OSes for which I have source code!) perhaps someone else can
comment without having to undertake a research project first.
Bottom line summary: I agree the desirability of making the
information available; I'm not sure that getifaddrs() is a good
starting point.
Cheers,
Giles