* net.cc (get_ipv4fromreg_ipcnt): Rearrange to fetch all registry
values at once using RtlQueryRegistryValues. (get_ipv4fromreg): Ditto.
This commit is contained in:
parent
e5c91e1627
commit
cbc26145e8
@ -1,3 +1,9 @@
|
|||||||
|
2011-04-19 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* net.cc (get_ipv4fromreg_ipcnt): Rearrange to fetch all registry
|
||||||
|
values at once using RtlQueryRegistryValues.
|
||||||
|
(get_ipv4fromreg): Ditto.
|
||||||
|
|
||||||
2011-04-19 Corinna Vinschen <corinna@vinschen.de>
|
2011-04-19 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* fhandler_registry.cc (fhandler_registry::fstat): Use RegQueryInfoKeyW.
|
* fhandler_registry.cc (fhandler_registry::fstat): Use RegQueryInfoKeyW.
|
||||||
|
@ -49,6 +49,7 @@ details. */
|
|||||||
#include "cygwin/in6.h"
|
#include "cygwin/in6.h"
|
||||||
#include "ifaddrs.h"
|
#include "ifaddrs.h"
|
||||||
#include "tls_pbuf.h"
|
#include "tls_pbuf.h"
|
||||||
|
#include "ntdll.h"
|
||||||
#define _CYGWIN_IN_H
|
#define _CYGWIN_IN_H
|
||||||
#include <resolv.h>
|
#include <resolv.h>
|
||||||
|
|
||||||
@ -1761,96 +1762,104 @@ get_flags (PIP_ADAPTER_ADDRESSES pap)
|
|||||||
static ULONG
|
static ULONG
|
||||||
get_ipv4fromreg_ipcnt (const char *name)
|
get_ipv4fromreg_ipcnt (const char *name)
|
||||||
{
|
{
|
||||||
HKEY key;
|
WCHAR regkey[256], *c;
|
||||||
LONG ret;
|
|
||||||
char regkey[256], *c;
|
|
||||||
ULONG ifs = 1;
|
|
||||||
DWORD dhcp, size;
|
|
||||||
|
|
||||||
c = stpcpy (regkey, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\"
|
c = wcpcpy (regkey, L"Tcpip\\Parameters\\Interfaces\\");
|
||||||
"Parameters\\Interfaces\\");
|
sys_mbstowcs (c, 220, name);
|
||||||
stpcpy (c, name);
|
if (!NT_SUCCESS (RtlCheckRegistryKey (RTL_REGISTRY_SERVICES, regkey)))
|
||||||
if ((ret = RegOpenKeyEx (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ,
|
|
||||||
&key)) != ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
if (ret != ERROR_FILE_NOT_FOUND)
|
|
||||||
debug_printf ("RegOpenKeyEx(%s), win32 error %ld", regkey, ret);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
ULONG ifs = 1;
|
||||||
|
DWORD dhcp = 0;
|
||||||
|
UNICODE_STRING uipa = { 0, 0, NULL };
|
||||||
|
RTL_QUERY_REGISTRY_TABLE tab[3] = {
|
||||||
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
|
||||||
|
L"EnableDHCP", &dhcp, REG_NONE, NULL, 0 },
|
||||||
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOEXPAND,
|
||||||
|
L"IPAddress", &uipa, REG_NONE, NULL, 0 },
|
||||||
|
{ NULL, 0, NULL, NULL, 0, NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
/* If DHCP is used, we have only one address. */
|
/* If DHCP is used, we have only one address. */
|
||||||
if ((ret = RegQueryValueEx (key, "EnableDHCP", NULL, NULL, (PBYTE) &dhcp,
|
if (NT_SUCCESS (RtlQueryRegistryValues (RTL_REGISTRY_SERVICES, regkey, tab,
|
||||||
(size = sizeof dhcp, &size))) == ERROR_SUCCESS
|
NULL, NULL))
|
||||||
&& dhcp == 0
|
&& uipa.Buffer)
|
||||||
&& (ret = RegQueryValueEx (key, "IPAddress", NULL, NULL, NULL,
|
|
||||||
&size)) == ERROR_SUCCESS)
|
|
||||||
{
|
{
|
||||||
char *ipa = (char *) alloca (size);
|
if (dhcp == 0)
|
||||||
RegQueryValueEx (key, "IPAddress", NULL, NULL, (PBYTE) ipa, &size);
|
for (ifs = 0, c = uipa.Buffer; *c; c += wcslen (c) + 1)
|
||||||
for (ifs = 0, c = ipa; *c; c += strlen (c) + 1)
|
|
||||||
ifs++;
|
ifs++;
|
||||||
|
RtlFreeUnicodeString (&uipa);
|
||||||
}
|
}
|
||||||
RegCloseKey (key);
|
|
||||||
return ifs;
|
return ifs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_ipv4fromreg (struct ifall *ifp, const char *name, DWORD idx)
|
get_ipv4fromreg (struct ifall *ifp, const char *name, DWORD idx)
|
||||||
{
|
{
|
||||||
HKEY key;
|
WCHAR regkey[256], *c;
|
||||||
LONG ret;
|
|
||||||
char regkey[256], *c;
|
|
||||||
DWORD ifs;
|
|
||||||
DWORD dhcp, size;
|
|
||||||
|
|
||||||
c = stpcpy (regkey, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\"
|
c = wcpcpy (regkey, L"Tcpip\\Parameters\\Interfaces\\");
|
||||||
"Parameters\\Interfaces\\");
|
sys_mbstowcs (c, 220, name);
|
||||||
stpcpy (c, name);
|
if (!NT_SUCCESS (RtlCheckRegistryKey (RTL_REGISTRY_SERVICES, regkey)))
|
||||||
if ((ret = RegOpenKeyEx (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ, &key))
|
|
||||||
!= ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
if (ret != ERROR_FILE_NOT_FOUND)
|
|
||||||
debug_printf ("RegOpenKeyEx(%s), win32 error %ld", regkey, ret);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ULONG ifs;
|
||||||
|
DWORD dhcp = 0;
|
||||||
|
UNICODE_STRING udipa = { 0, 0, NULL };
|
||||||
|
UNICODE_STRING udsub = { 0, 0, NULL };
|
||||||
|
UNICODE_STRING uipa = { 0, 0, NULL };
|
||||||
|
UNICODE_STRING usub = { 0, 0, NULL };
|
||||||
|
RTL_QUERY_REGISTRY_TABLE tab[6] = {
|
||||||
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
|
||||||
|
L"EnableDHCP", &dhcp, REG_NONE, NULL, 0 },
|
||||||
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOEXPAND,
|
||||||
|
L"DhcpIPAddress", &udipa, REG_NONE, NULL, 0 },
|
||||||
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOEXPAND,
|
||||||
|
L"DhcpSubnetMask", &udsub, REG_NONE, NULL, 0 },
|
||||||
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOEXPAND,
|
||||||
|
L"IPAddress", &uipa, REG_NONE, NULL, 0 },
|
||||||
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOEXPAND,
|
||||||
|
L"SubnetMask", &usub, REG_NONE, NULL, 0 },
|
||||||
|
{ NULL, 0, NULL, NULL, 0, NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
if (NT_SUCCESS (RtlQueryRegistryValues (RTL_REGISTRY_SERVICES, regkey, tab,
|
||||||
|
NULL, NULL)))
|
||||||
|
{
|
||||||
|
# define addr ((struct sockaddr_in *) &ifp->ifa_addr)
|
||||||
|
# define mask ((struct sockaddr_in *) &ifp->ifa_netmask)
|
||||||
|
# define brdc ((struct sockaddr_in *) &ifp->ifa_brddstaddr)
|
||||||
|
# define inet_uton(u, a) \
|
||||||
|
{ \
|
||||||
|
char t[64]; \
|
||||||
|
sys_wcstombs (t, 64, (u)); \
|
||||||
|
cygwin_inet_aton (t, (a)); \
|
||||||
}
|
}
|
||||||
/* If DHCP is used, we have only one address. */
|
/* If DHCP is used, we have only one address. */
|
||||||
if ((ret = RegQueryValueEx (key, "EnableDHCP", NULL, NULL, (PBYTE) &dhcp,
|
|
||||||
(size = sizeof dhcp, &size))) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
#define addr ((struct sockaddr_in *) &ifp->ifa_addr)
|
|
||||||
#define mask ((struct sockaddr_in *) &ifp->ifa_netmask)
|
|
||||||
#define brdc ((struct sockaddr_in *) &ifp->ifa_brddstaddr)
|
|
||||||
if (dhcp)
|
if (dhcp)
|
||||||
{
|
{
|
||||||
if ((ret = RegQueryValueEx (key, "DhcpIPAddress", NULL, NULL,
|
if (udipa.Buffer)
|
||||||
(PBYTE) regkey, (size = 256, &size)))
|
inet_uton (udipa.Buffer, &addr->sin_addr);
|
||||||
== ERROR_SUCCESS)
|
if (udsub.Buffer)
|
||||||
cygwin_inet_aton (regkey, &addr->sin_addr);
|
inet_uton (udsub.Buffer, &mask->sin_addr);
|
||||||
if ((ret = RegQueryValueEx (key, "DhcpSubnetMask", NULL, NULL,
|
|
||||||
(PBYTE) regkey, (size = 256, &size)))
|
|
||||||
== ERROR_SUCCESS)
|
|
||||||
cygwin_inet_aton (regkey, &mask->sin_addr);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((ret = RegQueryValueEx (key, "IPAddress", NULL, NULL, NULL,
|
if (uipa.Buffer)
|
||||||
&size)) == ERROR_SUCCESS)
|
|
||||||
{
|
{
|
||||||
char *ipa = (char *) alloca (size);
|
for (ifs = 0, c = uipa.Buffer; *c && ifs < idx;
|
||||||
RegQueryValueEx (key, "IPAddress", NULL, NULL, (PBYTE) ipa, &size);
|
c += wcslen (c) + 1)
|
||||||
for (ifs = 0, c = ipa; *c && ifs < idx; c += strlen (c) + 1)
|
|
||||||
ifs++;
|
ifs++;
|
||||||
if (*c)
|
if (*c)
|
||||||
cygwin_inet_aton (c, &addr->sin_addr);
|
inet_uton (c, &addr->sin_addr);
|
||||||
}
|
}
|
||||||
if ((ret = RegQueryValueEx (key, "SubnetMask", NULL, NULL, NULL,
|
if (usub.Buffer)
|
||||||
&size)) == ERROR_SUCCESS)
|
|
||||||
{
|
{
|
||||||
char *ipa = (char *) alloca (size);
|
for (ifs = 0, c = usub.Buffer; *c && ifs < idx;
|
||||||
RegQueryValueEx (key, "SubnetMask", NULL, NULL, (PBYTE) ipa, &size);
|
c += wcslen (c) + 1)
|
||||||
for (ifs = 0, c = ipa; *c && ifs < idx; c += strlen (c) + 1)
|
|
||||||
ifs++;
|
ifs++;
|
||||||
if (*c)
|
if (*c)
|
||||||
cygwin_inet_aton (c, &mask->sin_addr);
|
inet_uton (c, &mask->sin_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ifp->ifa_ifa.ifa_flags & IFF_BROADCAST)
|
if (ifp->ifa_ifa.ifa_flags & IFF_BROADCAST)
|
||||||
@ -1860,8 +1869,16 @@ get_ipv4fromreg (struct ifall *ifp, const char *name, DWORD idx)
|
|||||||
#undef addr
|
#undef addr
|
||||||
#undef mask
|
#undef mask
|
||||||
#undef brdc
|
#undef brdc
|
||||||
|
#undef inet_uton
|
||||||
|
if (udipa.Buffer)
|
||||||
|
RtlFreeUnicodeString (&udipa);
|
||||||
|
if (udsub.Buffer)
|
||||||
|
RtlFreeUnicodeString (&udsub);
|
||||||
|
if (uipa.Buffer)
|
||||||
|
RtlFreeUnicodeString (&uipa);
|
||||||
|
if (usub.Buffer)
|
||||||
|
RtlFreeUnicodeString (&usub);
|
||||||
}
|
}
|
||||||
RegCloseKey (key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user