From ba763af5599bf80e488b98a1cf973c2388eeeac9 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 13 Jun 2013 19:37:14 +0000 Subject: [PATCH] * 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. --- winsup/cygwin/ChangeLog | 6 +++++ winsup/cygwin/net.cc | 54 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 913084bd4..eaa0373ee 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2013-06-13 Corinna Vinschen + + * 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 * posix.sgml (fcntl, flock, lockf): Point to implementation notes. diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 0454d9b32..053c66718 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -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);