* net.cc (gen_old_if_name): New function to generate short interface

names for old pre-1.7 applications.
	(get_ifs): Call gen_old_if_name for said old applications.
This commit is contained in:
Corinna Vinschen 2013-06-13 19:37:14 +00:00
parent f06d6d2886
commit ba763af559
2 changed files with 58 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2013-06-13 Corinna Vinschen <corinna@vinschen.de>
* net.cc (gen_old_if_name): New function to generate short interface
names for old pre-1.7 applications.
(get_ifs): Call gen_old_if_name for said old applications.
2013-06-13 Corinna Vinschen <corinna@vinschen.de>
* posix.sgml (fcntl, flock, lockf): Point to implementation notes.

View File

@ -1900,6 +1900,51 @@ get_hwaddr (struct ifall *ifp, PIP_ADAPTER_ADDRESSES pap)
ifp->ifa_hwaddr.sa_data[i] = pap->PhysicalAddress[i];
}
/*
* Generate short, unique interface name for usage with aged
* applications still using the old pre-1.7 ifreq structure.
*/
static void
gen_old_if_name (char *name, PIP_ADAPTER_ADDRESSES pap, DWORD idx)
{
/* Note: The returned name must be < 16 chars. */
const char *prefix;
switch (pap->IfType)
{
case IF_TYPE_ISO88025_TOKENRING:
prefix = "tok";
break;
case IF_TYPE_PPP:
prefix = "ppp";
break;
case IF_TYPE_SOFTWARE_LOOPBACK:
prefix = "lo";
break;
case IF_TYPE_ATM:
prefix = "atm";
break;
case IF_TYPE_IEEE80211:
prefix = "wlan";
break;
case IF_TYPE_SLIP:
case IF_TYPE_RS232:
case IF_TYPE_MODEM:
prefix = "slp";
break;
case IF_TYPE_TUNNEL:
prefix = "tun";
break;
default:
prefix = "eth";
break;
}
if (idx)
__small_sprintf (name, "%s%u:%u", prefix, pap->IfIndex, idx);
else
__small_sprintf (name, "%s%u", prefix, pap->IfIndex, idx);
}
/*
* Get network interfaces. Use IP Helper function GetAdaptersAddresses.
*/
@ -1941,7 +1986,10 @@ get_ifs (ULONG family)
/* Next in chain */
ifp->ifa_ifa.ifa_next = (struct ifaddrs *) &ifp[1].ifa_ifa;
/* Interface name */
if (idx)
if (CYGWIN_VERSION_CHECK_FOR_OLD_IFREQ)
gen_old_if_name (ifp->ifa_name, pap, idx);
else if (idx)
__small_sprintf (ifp->ifa_name, "%s:%u", pap->AdapterName, idx);
else
strcpy (ifp->ifa_name, pap->AdapterName);
@ -1985,7 +2033,9 @@ get_ifs (ULONG family)
/* Next in chain */
ifp->ifa_ifa.ifa_next = (struct ifaddrs *) &ifp[1].ifa_ifa;
/* Interface name */
if (sa->sa_family == AF_INET && idx)
if (CYGWIN_VERSION_CHECK_FOR_OLD_IFREQ)
gen_old_if_name (ifp->ifa_name, pap, idx);
else if (sa->sa_family == AF_INET && idx)
__small_sprintf (ifp->ifa_name, "%s:%u", pap->AdapterName, idx);
else
strcpy (ifp->ifa_name, pap->AdapterName);