delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/06/12/10:26:57

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Fri, 12 Jun 2009 16:26:31 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: ioctl(sock, SIOCGIFHWADDR, &ifr) fails with 1.7
Message-ID: <20090612142631.GA14587@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <a9a39a210906120530j7892c00eu526489b97feff150 AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <a9a39a210906120530j7892c00eu526489b97feff150@mail.gmail.com>
User-Agent: Mutt/1.5.19 (2009-02-20)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Jun 12 14:30, Fr?d?ric Bron wrote:
> I used the following program to obtain mac address and ip of network
> adpaters. It works fine with 1.5 but not with 1.7.
> 
> Output with 1.5:
> sock=3
> trying eth0
> mac: 00.1f.3c.57.XX.XX, ip: XXX.XXX.XXX.XXX
> trying eth1
> mac: 00.1d.09.df.XX.XX, ip: XXX.XXX.XXX.XXX
> trying eth2
> mac: 08.00.27.00.XX.XX, ip: XXX.XXX.XXX.XXX
> trying eth3
> ...
> 
> Output with 1.7:
> sock=3
> trying eth0
> trying eth1
> trying eth2
> trying eth3
> ...
> 
> Any clue?

Yes.  Your example application is wrongly assuming that the interfaces
are called eth0, eth1, ...

The problem is that this approach to use our own naming convention
for the Windows interfaces wasn't feasible anymore, when you're trying
to support IPv6, multicast and all that stuff.  I really thought long
and hard about this but I couldn't find a satisfing renaming approach
*and* could guarantee that the device names were unique over the entire
runtime, over multiple processes.

Therefore, with Windows XP and later, our device name is the unique
Windows device name.  This is a GUID string as, for instance,
"{126B4C29-7A0E-41D1-81B4-C706C8F40128}". Yes, I know. this looks very
ugly, but it works.  I thought about using the interface name which you
see when you're in the "Network Connections" window, typically names
like "Local Area Connection".  This is the so-called "FriendlyName" of
an interface.  However, the name can be empty, and it is not unique.

To fix your application, call either

  struct ifconf ifc;
  ifc.ifc_len = sizeof (struct ifreq) * 32;
  ifc.ifc_buf = malloc (ifc.ifc_len);
  if (ioctl (fd, SIOCGIFCONF, &ifc))
    /* Resize ifc_buf and retry */
  else
    {
      struct ifreq *ifr = ifc.ifc_req;
      struct ifreq ifr2;
      for (int i = 0; i < ifc.ifc_len; i += sizeof (struct ifreq), ++ifr)
	if (!ioctl (fd, SIOCGIFADDR, &ifr2))
	  /* Print result for that interface */
    }

or, use the new getifaddrs() interface.  See
http://www.kernel.org/doc/man-pages/online/pages/man3/getifaddrs.3.html


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019