[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Patch for network-interface-{list,info}

From: Kim F. Storm
Subject: Re: Patch for network-interface-{list,info}
Date: 17 Nov 2003 13:23:32 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

[To RMS:  We need papers from Alex to use his patches]

Alex Plotnick <address@hidden> writes:

> I noticed that the functions `network-interface-info' and
> `network-interface-list' did not work on Darwin 6.8 (Mac OS X 10.2.8).
> After some investigation, I determined that they probably would not work on
> some other BSDs as well.  The following patch addresses some of the issues.
> The use of ioctl(SIOCGIFCONF) to fetch the list of network interfaces is
> prone to some interesting problems.  In particular, the size of the
> returned structures (struct ifreq) is not constant on some systems (e.g.,
> Darwin), making the buffer resizing and list iteration somewhat tricky.  

Ah, yes, I'd forgotten all about the sa_len issue...  Thanks for
pointing that out.

>                                                                          My
> patch fixes these errors, and the SIOCGIFCONF now works properly under both
> GNU/Linux and Darwin.  However, it seems to be preferable to just use
> getifaddrs() when available, as it's a much cleaner interface.  To my mind,
> it's tempting to get rid of the SIOCGIFCONF code all together, but I've
> left it in for now.

It's definitely a cleaner interface, yes, and maybe it is as widely
available as SIOCGIFCONF these days...?

But in any case, since network-interface-list is a new addition in CVS
emacs, I think it would be alright for us to restrict its availability
to those systems which do support getifaddrs (in some form -- AFAIK,
there are variations in the amount of useful information returned by
getifaddrs on different systems [and I have seen bug reports about
traps in getifaddrs if there are many interfaces]).

If we settle on using only getifaddrs, I would suggest that we change
network-interface-list to return all the available information about
each interface (based on the information returned by getifaddrs),
similar to what network-interface-info return now, and just let
network-interface-info do something like

(defun network-interface-info (INTERFACE)
  (assoc-default INTERFACE (network-interface-list)))

> In the case of `network-interface-info', certain of the requested ioctl()s
> are non-existent on Darwin (and, again, presumably on some other BSDs); in
> particular, SIOCGIFNETMASK and SIOCGIFHWADDR.  I've got some code that
> uses getifaddrs() to fetch all of this info (instead of doing separate
> ioctl() calls), but have not included it in this patch.  If people think
> this is the correct way to go, I'll send it on.  (For those that care: the
> downside of this is the difference between the link-layer sockaddrs on BSD
> (struct sockaddr_dl) and Linux (struct sockaddr_ll).)

This is unclear to me.

How does getifaddrs return the hw address?  In ifaddr->ifa_data ?
Is that portable?  If not, maybe it could use SIOCGIFHWADDR as 
a fallback.

I haven't found any docs about the value of ifa_data on GNU/Linux.
Do you have ref. pointers for this?

> Comments, suggestions, bug-fixes, and test reports are all welcome.

If you want to modify network-interface-list and -info according to
the suggestions above, I would appreciate it.  

However, AFAICS, you have not signed papers for contributing to emacs,
and your changes are a little too big to be considered a tiny change.
Are you interested in signing papers for your changes?

Otherwise, I will work on this myself.  Thank you for your input.

Kim F. Storm <address@hidden> http://www.cua.dk

reply via email to

[Prev in Thread] Current Thread [Next in Thread]