From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: Patch for network-interface-{list,info} Date: 17 Nov 2003 13:23:32 +0100 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: <87ad6w2hm6.fsf@Dora.local.> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1069069422 8673 80.91.224.253 (17 Nov 2003 11:43:42 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 17 Nov 2003 11:43:42 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon Nov 17 12:43:39 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1ALhn9-0001H8-00 for ; Mon, 17 Nov 2003 12:43:39 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1ALhn8-0000Sq-00 for ; Mon, 17 Nov 2003 12:43:38 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1ALieH-0000pl-QU for emacs-devel@quimby.gnus.org; Mon, 17 Nov 2003 07:38:33 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1ALiYJ-0008MU-UW for emacs-devel@gnu.org; Mon, 17 Nov 2003 07:32:23 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1ALiXn-0008Ig-E4 for emacs-devel@gnu.org; Mon, 17 Nov 2003 07:32:22 -0500 Original-Received: from [212.88.64.25] (helo=mail-relay.sonofon.dk) by monty-python.gnu.org with smtp (Exim 4.24) id 1ALiXm-0008IG-5u for emacs-devel@gnu.org; Mon, 17 Nov 2003 07:31:50 -0500 Original-Received: (qmail 30741 invoked from network); 17 Nov 2003 11:23:41 -0000 Original-Received: from unknown (HELO kfs-l.imdomain.dk.cua.dk) (213.83.150.2) by 0 with SMTP; 17 Nov 2003 11:23:41 -0000 Original-To: Alex Plotnick In-Reply-To: <87ad6w2hm6.fsf@Dora.local.> Original-Lines: 78 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:17860 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:17860 [To RMS: We need papers from Alex to use his patches] Alex Plotnick 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 http://www.cua.dk