public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Ethernet interface names with cygwin 1.7.5
@ 2010-08-09  9:03 laurent.metais
  2010-08-09  9:36 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: laurent.metais @ 2010-08-09  9:03 UTC (permalink / raw)
  To: cygwin

Hello !

I am using a very simple to find all ethernet on my PC with cygwin :

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>

int get_iface_list(struct ifconf *ifconf)
{
   int sock, rval;

   sock = socket(AF_INET,SOCK_STREAM,0);
   if(sock < 0)
   {
     perror("socket");
     return (-1);
   }

   if((rval = ioctl(sock, SIOCGIFCONF , (char*) ifconf  )) < 0 )
     perror("ioctl(SIOGIFCONF)");

   close(sock);

   return rval;
}

int main()
{
   static struct ifreq ifreqs[20];
   struct ifconf ifconf;
   int  nifaces, i;

   memset(&ifconf,0,sizeof(ifconf));
   ifconf.ifc_buf = (char*) (ifreqs);
   ifconf.ifc_len = sizeof(ifreqs);

   if(get_iface_list(&ifconf) < 0) exit(-1);

   nifaces =  ifconf.ifc_len/sizeof(struct ifreq);

   printf("Interfaces (count = %d):\n", nifaces);
   for(i = 0; i < nifaces; i++)
   {
     printf("\t%-10s\n", ifreqs[i].ifr_name);
   }
}

With cygwin 1.7.5 the result is :
$ ./a.exe
Interfaces (count = 5):
        {EE0A9E93-9A06-4CCB-B957-074C921D39FB}
        {46D151B0-33BB-4706-A450-B29F50F8095A}
        {B9BDEE37-C781-447B-B457-D4B17C576948}
        {A46ED7E6-A8A7-431E-BDE0-68DBEA2D334D}
        MS TCP Loopback interface

with release 1.5.25, the result was using the well-known names (lo0, eth0, 
eth1, etc...).

How can retrieve the standard names with release 1.7.5 ? Is it a new 
naming convention ?

Thanks for your help.

Best Regards,

Laurent Métais
Software Designer 

CP Technocenter 


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Ethernet interface names with cygwin 1.7.5
  2010-08-09  9:03 Ethernet interface names with cygwin 1.7.5 laurent.metais
@ 2010-08-09  9:36 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2010-08-09  9:36 UTC (permalink / raw)
  To: cygwin

On Aug  9 11:03, laurent.metais@cp.com wrote:
> I am using a very simple to find all ethernet on my PC with cygwin :
> [...]
> With cygwin 1.7.5 the result is :
> $ ./a.exe
> Interfaces (count = 5):
>         {EE0A9E93-9A06-4CCB-B957-074C921D39FB}
>         {46D151B0-33BB-4706-A450-B29F50F8095A}
>         {B9BDEE37-C781-447B-B457-D4B17C576948}
>         {A46ED7E6-A8A7-431E-BDE0-68DBEA2D334D}
>         MS TCP Loopback interface
> 
> with release 1.5.25, the result was using the well-known names (lo0, eth0, 
> eth1, etc...).
> 
> How can retrieve the standard names with release 1.7.5 ? Is it a new 
> naming convention ?

The problem with the well-known names is that they are not guaranteed to
be unique, because the order of the interfaces returned by the Windows
API can change arbitrarily.
Therefore Cygwin 1.7 starts to return the really unique Win32 interface
names, which are the above UUID-based names (plus the old "MS TCP Loopback"
name).

The uniqueness of the interface name is quite important in a couple of
circumstances, so, starting wit Windows XP, there's no way anymore to
retrieve the old well-known names since they are just not generated.

What's left is a Cygwin-specific extension, the SIOCGIFFRNDLYNAM ioctl,
which is documented in /usr/include/cygwin/if.h, see the comment
preceeding the definition of IFRF_FRIENDLYNAMESIZ.  This extension
returns the so-called "FriendlyName", which is the interface name as
shown in the Windows network properties.

Btw., Cygwin 1.7 also has the getifaddrs/freeifaddrs API to retrieve
the interface list (and the /proc/net/if_inet6 file).


Corinna

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

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-09  9:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-09  9:03 Ethernet interface names with cygwin 1.7.5 laurent.metais
2010-08-09  9:36 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).