Could 'getifaddrs' be implemented in go?

347 views
Skip to first unread message

rivercheng

unread,
Feb 25, 2010, 11:29:49 PM2/25/10
to golang-nuts
In C, getifaddrs declared in <ifaddrs.h> can show addresses assigned
to all network interfaces in the computer. I think it is implemented
by using 'ioctl', which is not directly supported by Go due to the
type issue.

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

Giles Lean

unread,
Feb 26, 2010, 5:02:09 PM2/26/10
to golang-nuts

On Feb 26, 3:29 pm, rivercheng <riverch...@gmail.com> wrote:
> In C, getifaddrs declared in <ifaddrs.h> can show addresses assigned
> to all network interfaces in the computer.

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

Message has been deleted

Dave Cheney

unread,
Apr 18, 2013, 9:39:09 PM4/18/13
to yob...@gmail.com, golang-nuts
Does this type not do what you need ? http://tip.golang.org/pkg/net/#Interface

On Fri, Apr 19, 2013 at 7:57 AM, <yob...@gmail.com> wrote:
> Sorry to resurrect such an old topic!
>
> I found this thread very useful:
> http://developerweb.net/viewtopic.php?id=5085
>
> It looks like getifaddrs has gained lots of traction is the "best way to do
> it", and the code on that link supports windows as well.
>
> I'd love to implement this for Go if people think it's a good idea?
> Thoughts?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages