* fhandler_socket.cc (fhandler_socket::ioctl): Don't fake results

for SIOCGIFFLAGS here.  Call get_ifconf instead.
	* net.cc (get_2k_ifconf): Clean up code to generate interface name.
	Handle SIOCGIFFLAGS here.
	(get_nt_ifconf): Fake SIOCGIFFLAGS here.
	(get_95_ifconf): Ditto.
	(get_ifconf): Don't fake loopback on systems with IP Helper Lib.
	Set MTU for loopback to a more "modern" value.
This commit is contained in:
Corinna Vinschen 2007-01-04 10:11:27 +00:00
parent 7bef7db5cc
commit bcdf742178
3 changed files with 121 additions and 123 deletions

View File

@ -1,3 +1,14 @@
2007-01-04 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::ioctl): Don't fake results
for SIOCGIFFLAGS here. Call get_ifconf instead.
* net.cc (get_2k_ifconf): Clean up code to generate interface name.
Handle SIOCGIFFLAGS here.
(get_nt_ifconf): Fake SIOCGIFFLAGS here.
(get_95_ifconf): Ditto.
(get_ifconf): Don't fake loopback on systems with IP Helper Lib.
Set MTU for loopback to a more "modern" value.
2007-01-04 Brian Ford <Brian.Ford@FlightSafety.com> 2007-01-04 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de> Corinna Vinschen <corinna@vinschen.de>

View File

@ -1,6 +1,6 @@
/* fhandler_socket.cc. See fhandler.h for a description of the fhandler classes. /* fhandler_socket.cc. See fhandler.h for a description of the fhandler classes.
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006 Red Hat, Inc. Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -1413,21 +1413,6 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
debug_printf ("error in get_ifconf"); debug_printf ("error in get_ifconf");
break; break;
case SIOCGIFFLAGS: case SIOCGIFFLAGS:
ifr = (struct ifreq *) p;
if (ifr == 0)
{
set_errno (EINVAL);
return -1;
}
ifr->ifr_flags = IFF_NOTRAILERS | IFF_UP | IFF_RUNNING;
if (!strncmp(ifr->ifr_name, "lo", 2)
|| ntohl (((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr)
== INADDR_LOOPBACK)
ifr->ifr_flags |= IFF_LOOPBACK;
else
ifr->ifr_flags |= IFF_BROADCAST;
res = 0;
break;
case SIOCGIFBRDADDR: case SIOCGIFBRDADDR:
case SIOCGIFNETMASK: case SIOCGIFNETMASK:
case SIOCGIFADDR: case SIOCGIFADDR:
@ -1463,6 +1448,9 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
{ {
switch (cmd) switch (cmd)
{ {
case SIOCGIFFLAGS:
ifr->ifr_flags = ifrp->ifr_flags;
break;
case SIOCGIFADDR: case SIOCGIFADDR:
ifr->ifr_addr = ifrp->ifr_addr; ifr->ifr_addr = ifrp->ifr_addr;
break; break;

View File

@ -1,7 +1,7 @@
/* net.cc: network-related routines. /* net.cc: network-related routines.
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006 Red Hat, Inc. 2005, 2006, 2007 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -1205,77 +1205,59 @@ get_2k_ifconf (struct ifconf *ifc, int what)
} }
/* Setup the interface name */ /* Setup the interface name */
switch (ifrow->dwType) if (ifrow->dwType == MIB_IF_TYPE_LOOPBACK)
strcpy (ifr->ifr_name, "lo");
else
{ {
case MIB_IF_TYPE_TOKENRING: const char *name = "";
if (ifEntry->enumerated == 0) switch (ifrow->dwType)
{ {
ifEntry->classId = tokId++; case MIB_IF_TYPE_TOKENRING:
__small_sprintf (ifr->ifr_name, "tok%u", name = "tok";
ifEntry->classId); if (ifEntry->enumerated == 0)
} ifEntry->classId = tokId++;
else break;
{ case MIB_IF_TYPE_ETHERNET:
__small_sprintf (ifr->ifr_name, "tok%u:%u", name = "eth";
ifEntry->classId, if (ifEntry->enumerated == 0)
ifEntry->enumerated - 1); ifEntry->classId = ethId++;
} break;
ifEntry->enumerated++; case MIB_IF_TYPE_PPP:
break; name = "ppp";
case MIB_IF_TYPE_ETHERNET: if (ifEntry->enumerated == 0)
if (ifEntry->enumerated == 0) ifEntry->classId = pppId++;
{ break;
ifEntry->classId = ethId++; case MIB_IF_TYPE_SLIP:
__small_sprintf (ifr->ifr_name, "eth%u", name = "slp";
ifEntry->classId); if (ifEntry->enumerated == 0)
} ifEntry->classId = slpId++;
else break;
{ default:
__small_sprintf (ifr->ifr_name, "eth%u:%u", continue;
ifEntry->classId, }
ifEntry->enumerated - 1); if (ifEntry->enumerated == 0)
} __small_sprintf (ifr->ifr_name, "%s%u", name, ifEntry->classId);
ifEntry->enumerated++; else
break; __small_sprintf (ifr->ifr_name, "%s%u:%u", name,
case MIB_IF_TYPE_PPP: ifEntry->classId, ifEntry->enumerated - 1);
if (ifEntry->enumerated == 0) ifEntry->enumerated++;
{
ifEntry->classId = pppId++;
__small_sprintf (ifr->ifr_name, "ppp%u",
ifEntry->classId);
}
else
{
__small_sprintf (ifr->ifr_name, "ppp%u:%u",
ifEntry->classId,
ifEntry->enumerated - 1);
}
ifEntry->enumerated++;
break;
case MIB_IF_TYPE_SLIP:
if (ifEntry->enumerated == 0)
{
ifEntry->classId = slpId++;
__small_sprintf (ifr->ifr_name, "slp%u",
ifEntry->classId);
}
else
{
__small_sprintf (ifr->ifr_name, "slp%u:%u",
ifEntry->classId,
ifEntry->enumerated - 1);
}
ifEntry->enumerated++;
break;
case MIB_IF_TYPE_LOOPBACK:
strcpy (ifr->ifr_name, "lo");
break;
default:
continue;
} }
/* setup sockaddr struct */
/* setup sockaddr struct */
switch (what) switch (what)
{ {
case SIOCGIFFLAGS:
if (ifrow->dwType == MIB_IF_TYPE_LOOPBACK)
ifr->ifr_flags = IFF_LOOPBACK;
else
ifr->ifr_flags = IFF_BROADCAST | IFF_MULTICAST;
if (ifrow->dwAdminStatus == MIB_IF_ADMIN_STATUS_UP)
{
ifr->ifr_flags |= IFF_UP;
if (ifrow->dwOperStatus >= MIB_IF_OPER_STATUS_CONNECTED)
ifr->ifr_flags |= IFF_RUNNING;
}
break;
case SIOCGIFCONF: case SIOCGIFCONF:
case SIOCGIFADDR: case SIOCGIFADDR:
sa = (struct sockaddr_in *) &ifr->ifr_addr; sa = (struct sockaddr_in *) &ifr->ifr_addr;
@ -1441,6 +1423,10 @@ get_nt_ifconf (struct ifconf *ifc, int what)
{ {
switch (what) switch (what)
{ {
case SIOCGIFFLAGS:
ifr->ifr_flags = IFF_UP | IFF_RUNNING
| IFF_BROADCAST;
break;
case SIOCGIFCONF: case SIOCGIFCONF:
case SIOCGIFADDR: case SIOCGIFADDR:
sa = (struct sockaddr_in *) &ifr->ifr_addr; sa = (struct sockaddr_in *) &ifr->ifr_addr;
@ -1481,6 +1467,10 @@ get_nt_ifconf (struct ifconf *ifc, int what)
{ {
switch (what) switch (what)
{ {
case SIOCGIFFLAGS:
ifr->ifr_flags = IFF_UP | IFF_RUNNING
| IFF_BROADCAST;
break;
case SIOCGIFCONF: case SIOCGIFCONF:
case SIOCGIFADDR: case SIOCGIFADDR:
sa = (struct sockaddr_in *) &ifr->ifr_addr; sa = (struct sockaddr_in *) &ifr->ifr_addr;
@ -1613,6 +1603,9 @@ get_95_ifconf (struct ifconf *ifc, int what)
switch (what) switch (what)
{ {
case SIOCGIFFLAGS:
ifr->ifr_flags = IFF_UP | IFF_RUNNING | IFF_BROADCAST;
break;
case SIOCGIFCONF: case SIOCGIFCONF:
case SIOCGIFADDR: case SIOCGIFADDR:
sa = (struct sockaddr_in *) &ifr->ifr_addr; sa = (struct sockaddr_in *) &ifr->ifr_addr;
@ -1712,46 +1705,52 @@ get_ifconf (struct ifconf *ifc, int what)
return -1; return -1;
} }
/* Set up interface lo0 first */ if (!wincap.has_ip_helper_lib ())
strcpy (ifr->ifr_name, "lo");
memset (&ifr->ifr_addr, '\0', sizeof (ifr->ifr_addr));
switch (what)
{ {
case SIOCGIFCONF: /* Set up interface lo0 first */
case SIOCGIFADDR: strcpy (ifr->ifr_name, "lo");
sa = (struct sockaddr_in *) &ifr->ifr_addr; memset (&ifr->ifr_addr, '\0', sizeof (ifr->ifr_addr));
sa->sin_addr.s_addr = htonl (INADDR_LOOPBACK); switch (what)
sa->sin_family = AF_INET; {
sa->sin_port = 0; case SIOCGIFFLAGS:
break; ifr->ifr_flags = IFF_UP | IFF_RUNNING | IFF_LOOPBACK;
case SIOCGIFBRDADDR: break;
lip = htonl (INADDR_LOOPBACK); case SIOCGIFCONF:
lnp = cygwin_inet_addr ("255.0.0.0"); case SIOCGIFADDR:
sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; sa = (struct sockaddr_in *) &ifr->ifr_addr;
sa->sin_addr.s_addr = lip & lnp | ~lnp; sa->sin_addr.s_addr = htonl (INADDR_LOOPBACK);
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFNETMASK: case SIOCGIFBRDADDR:
sa = (struct sockaddr_in *) &ifr->ifr_netmask; lip = htonl (INADDR_LOOPBACK);
sa->sin_addr.s_addr = cygwin_inet_addr ("255.0.0.0"); lnp = cygwin_inet_addr ("255.0.0.0");
sa->sin_family = AF_INET; sa = (struct sockaddr_in *) &ifr->ifr_broadaddr;
sa->sin_port = 0; sa->sin_addr.s_addr = lip & lnp | ~lnp;
break; sa->sin_family = AF_INET;
case SIOCGIFHWADDR: sa->sin_port = 0;
ifr->ifr_hwaddr.sa_family = AF_INET; break;
memset (ifr->ifr_hwaddr.sa_data, 0, IFHWADDRLEN); case SIOCGIFNETMASK:
break; sa = (struct sockaddr_in *) &ifr->ifr_netmask;
case SIOCGIFMETRIC: sa->sin_addr.s_addr = cygwin_inet_addr ("255.0.0.0");
ifr->ifr_metric = 1; sa->sin_family = AF_INET;
break; sa->sin_port = 0;
case SIOCGIFMTU: break;
/* This funny value is returned by `ifconfig lo' on Linux 2.2 kernel. */ case SIOCGIFHWADDR:
ifr->ifr_mtu = 3924; ifr->ifr_hwaddr.sa_family = AF_INET;
break; memset (ifr->ifr_hwaddr.sa_data, 0, IFHWADDRLEN);
default: break;
set_errno (EINVAL); case SIOCGIFMETRIC:
return -1; ifr->ifr_metric = 1;
break;
case SIOCGIFMTU:
/* Default value for loopback on Linux 2.6 kernel. */
ifr->ifr_mtu = 16436;
break;
default:
set_errno (EINVAL);
return -1;
}
} }
if (wincap.has_ip_helper_lib ()) if (wincap.has_ip_helper_lib ())