Cygwin: drop macro and code for CYGWIN_VERSION_CHECK_FOR_OLD_IFREQ

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2022-08-03 15:57:30 +02:00
parent 57c3ca8d51
commit fee7b24beb
3 changed files with 21 additions and 122 deletions

View File

@ -100,36 +100,12 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
set_errno (EINVAL); set_errno (EINVAL);
return -1; return -1;
} }
if (CYGWIN_VERSION_CHECK_FOR_OLD_IFREQ) ifc.ifc_len = ifcp->ifc_len;
{ ifc.ifc_buf = ifcp->ifc_buf;
ifc.ifc_len = ifcp->ifc_len / sizeof (struct __old_ifreq)
* sizeof (struct ifreq);
ifc.ifc_buf = (caddr_t) alloca (ifc.ifc_len);
}
else
{
ifc.ifc_len = ifcp->ifc_len;
ifc.ifc_buf = ifcp->ifc_buf;
}
res = get_ifconf (&ifc, cmd); res = get_ifconf (&ifc, cmd);
if (res) if (res)
debug_printf ("error in get_ifconf"); debug_printf ("error in get_ifconf");
if (CYGWIN_VERSION_CHECK_FOR_OLD_IFREQ) ifcp->ifc_len = ifc.ifc_len;
{
struct __old_ifreq *ifr = (struct __old_ifreq *) ifcp->ifc_buf;
for (ifrp = ifc.ifc_req;
(caddr_t) ifrp < ifc.ifc_buf + ifc.ifc_len;
++ifrp, ++ifr)
{
memcpy (&ifr->ifr_ifrn, &ifrp->ifr_ifrn, sizeof ifr->ifr_ifrn);
ifr->ifr_name[__OLD_IFNAMSIZ - 1] = '\0';
memcpy (&ifr->ifr_ifru, &ifrp->ifr_ifru, sizeof ifr->ifr_ifru);
}
ifcp->ifc_len = ifc.ifc_len / sizeof (struct ifreq)
* sizeof (struct __old_ifreq);
}
else
ifcp->ifc_len = ifc.ifc_len;
break; break;
case OLD_SIOCGIFFLAGS: case OLD_SIOCGIFFLAGS:
case OLD_SIOCGIFADDR: case OLD_SIOCGIFADDR:
@ -159,12 +135,6 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
return -1; return -1;
} }
if (cmd > SIOCGIFINDEX && CYGWIN_VERSION_CHECK_FOR_OLD_IFREQ)
{
debug_printf ("cmd not supported on this platform");
set_errno (EINVAL);
return -1;
}
ifc.ifc_len = 64 * sizeof (struct ifreq); ifc.ifc_len = 64 * sizeof (struct ifreq);
ifc.ifc_buf = (caddr_t) alloca (ifc.ifc_len); ifc.ifc_buf = (caddr_t) alloca (ifc.ifc_len);
if (cmd == SIOCGIFFRNDLYNAM) if (cmd == SIOCGIFFRNDLYNAM)
@ -182,45 +152,26 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
break; break;
} }
if (CYGWIN_VERSION_CHECK_FOR_OLD_IFREQ) struct ifreq *ifr = (struct ifreq *) p;
debug_printf (" name: %s", ifr->ifr_name);
for (ifrp = ifc.ifc_req;
(caddr_t) ifrp < ifc.ifc_buf + ifc.ifc_len;
++ifrp)
{ {
struct __old_ifreq *ifr = (struct __old_ifreq *) p; debug_printf ("testname: %s", ifrp->ifr_name);
debug_printf (" name: %s", ifr->ifr_name); if (! strcmp (ifrp->ifr_name, ifr->ifr_name))
for (ifrp = ifc.ifc_req;
(caddr_t) ifrp < ifc.ifc_buf + ifc.ifc_len;
++ifrp)
{ {
debug_printf ("testname: %s", ifrp->ifr_name); if (cmd == SIOCGIFFRNDLYNAM)
if (! strcmp (ifrp->ifr_name, ifr->ifr_name)) /* The application has to care for the space. */
{ memcpy (ifr->ifr_frndlyname, ifrp->ifr_frndlyname,
memcpy (&ifr->ifr_ifru, &ifrp->ifr_ifru, sizeof (struct ifreq_frndlyname));
sizeof ifr->ifr_ifru); else
break; memcpy (&ifr->ifr_ifru, &ifrp->ifr_ifru,
} sizeof ifr->ifr_ifru);
} break;
}
else
{
struct ifreq *ifr = (struct ifreq *) p;
debug_printf (" name: %s", ifr->ifr_name);
for (ifrp = ifc.ifc_req;
(caddr_t) ifrp < ifc.ifc_buf + ifc.ifc_len;
++ifrp)
{
debug_printf ("testname: %s", ifrp->ifr_name);
if (! strcmp (ifrp->ifr_name, ifr->ifr_name))
{
if (cmd == SIOCGIFFRNDLYNAM)
/* The application has to care for the space. */
memcpy (ifr->ifr_frndlyname, ifrp->ifr_frndlyname,
sizeof (struct ifreq_frndlyname));
else
memcpy (&ifr->ifr_ifru, &ifrp->ifr_ifru,
sizeof ifr->ifr_ifru);
break;
}
} }
} }
if ((caddr_t) ifrp >= ifc.ifc_buf + ifc.ifc_len) if ((caddr_t) ifrp >= ifc.ifc_buf + ifc.ifc_len)
{ {
set_errno (EINVAL); set_errno (EINVAL);

View File

@ -34,9 +34,6 @@ details. */
#define CYGWIN_VERSION_USER_API_VERSION_COMBINED \ #define CYGWIN_VERSION_USER_API_VERSION_COMBINED \
CYGWIN_VERSION_PER_PROCESS_API_VERSION_COMBINED (user_data) CYGWIN_VERSION_PER_PROCESS_API_VERSION_COMBINED (user_data)
#define CYGWIN_VERSION_CHECK_FOR_OLD_IFREQ \
(CYGWIN_VERSION_USER_API_VERSION_COMBINED <= 161)
#define CYGWIN_VERSION_CHECK_FOR_OLD_CTYPE \ #define CYGWIN_VERSION_CHECK_FOR_OLD_CTYPE \
(CYGWIN_VERSION_USER_API_VERSION_COMBINED <= 209) (CYGWIN_VERSION_USER_API_VERSION_COMBINED <= 209)

View File

@ -1673,51 +1673,6 @@ get_hwaddr (struct ifall *ifp, PIP_ADAPTER_ADDRESSES pap)
ifp->ifa_hwdata.ifa_hwaddr.sa_data[i] = pap->PhysicalAddress[i]; ifp->ifa_hwdata.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. * Get network interfaces. Use IP Helper function GetAdaptersAddresses.
*/ */
@ -1760,9 +1715,7 @@ get_ifs (ULONG family)
ifp->ifa_ifa.ifa_next = (struct ifaddrs *) &ifp[1].ifa_ifa; ifp->ifa_ifa.ifa_next = (struct ifaddrs *) &ifp[1].ifa_ifa;
/* Interface name */ /* Interface name */
if (CYGWIN_VERSION_CHECK_FOR_OLD_IFREQ) if (idx)
gen_old_if_name (ifp->ifa_name, pap, idx);
else if (idx)
__small_sprintf (ifp->ifa_name, "%s:%u", pap->AdapterName, idx); __small_sprintf (ifp->ifa_name, "%s:%u", pap->AdapterName, idx);
else else
strcpy (ifp->ifa_name, pap->AdapterName); strcpy (ifp->ifa_name, pap->AdapterName);
@ -1808,9 +1761,7 @@ get_ifs (ULONG family)
/* Next in chain */ /* Next in chain */
ifp->ifa_ifa.ifa_next = (struct ifaddrs *) &ifp[1].ifa_ifa; ifp->ifa_ifa.ifa_next = (struct ifaddrs *) &ifp[1].ifa_ifa;
/* Interface name */ /* Interface name */
if (CYGWIN_VERSION_CHECK_FOR_OLD_IFREQ) if (sa->sa_family == AF_INET && idx)
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); __small_sprintf (ifp->ifa_name, "%s:%u", pap->AdapterName, idx);
else else
strcpy (ifp->ifa_name, pap->AdapterName); strcpy (ifp->ifa_name, pap->AdapterName);