X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 	tests=AWL,BAYES_00,J_CHICKENPOX_54,J_CHICKENPOX_66,RCVD_IN_NJABL_PROXY,SPF_PASS
X-Spam-Check-By: sourceware.org
Date: Thu, 18 Jun 2009 09:57:30 +0200
To: =?utf-8?Q?Fr=C3=A9d=C3=A9ric_Bron?= <frederic.bron@m4x.org>,
   cygwin  <cygwin@cygwin.com>
Subject: Re: ioctl(sock, SIOCGIFHWADDR, &ifr) fails with 1.7
From: "Matthias Andree" <matthias.andree@gmx.de>
Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8
MIME-Version: 1.0
References: <a9a39a210906120530j7892c00eu526489b97feff150@mail.gmail.com>  <20090612142631.GA14587@calimero.vinschen.de>  <a9a39a210906150222k5aa69cddg22118d889328c004@mail.gmail.com>
Content-Transfer-Encoding: 8bit
Message-ID: <op.uvpm14t31e62zd@merlin.emma.line.org>
In-Reply-To: <a9a39a210906150222k5aa69cddg22118d889328c004@mail.gmail.com>
User-Agent: Opera Mail/9.64 (Linux)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

Am 15.06.2009, 11:22 Uhr, schrieb Frédéric Bron <frederic.bron@m4x.org>:

>> 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 */
>>    }
>
> Thanks, this works half! No need of ifr2, ifr is enough.
> I saw the name change: 1.5 gives eth0, eth1, eth2, lo and 1.7 gives
> {821C54BE-...}...

Careful - this isn't portable to newer BSDs, as there ifc_len may exceed  
sizeof(struct ifreq).

getifaddrs() is probably the more portable solution here.

-- 
Matthias Andree

--
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/

