Cygwin: net: unify gethostname/getdomainname
Use info from same source (GetNetworkParams). Also move getdomainname near gethostname in source. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
c6171b9fde
commit
2166f7dc0d
|
@ -710,30 +710,24 @@ cygwin_getservbyport (int port, const char *proto)
|
||||||
extern "C" int
|
extern "C" int
|
||||||
cygwin_gethostname (char *name, size_t len)
|
cygwin_gethostname (char *name, size_t len)
|
||||||
{
|
{
|
||||||
int res = -1;
|
|
||||||
|
|
||||||
__try
|
__try
|
||||||
{
|
{
|
||||||
if (gethostname (name, len))
|
PFIXED_INFO info = NULL;
|
||||||
{
|
ULONG size = 0;
|
||||||
DWORD local_len = len;
|
|
||||||
|
|
||||||
if (!GetComputerNameExA (ComputerNameDnsHostname, name,
|
if (GetNetworkParams(info, &size) == ERROR_BUFFER_OVERFLOW
|
||||||
&local_len))
|
&& (info = (PFIXED_INFO) alloca(size))
|
||||||
{
|
&& GetNetworkParams(info, &size) == ERROR_SUCCESS)
|
||||||
if (GetLastError () == ERROR_MORE_DATA)
|
{
|
||||||
set_errno (ENAMETOOLONG);
|
strncpy(name, info->HostName, len);
|
||||||
else
|
debug_printf ("gethostname %s", name);
|
||||||
set_winsock_errno ();
|
return 0;
|
||||||
__leave;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
debug_printf ("name %s", name);
|
__seterrno ();
|
||||||
res = 0;
|
|
||||||
}
|
}
|
||||||
__except (EFAULT) {}
|
__except (EFAULT)
|
||||||
__endtry
|
__endtry
|
||||||
return res;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
|
@ -750,6 +744,30 @@ sethostname (const char *name, size_t len)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* getdomainname: 4.4BSD */
|
||||||
|
extern "C" int
|
||||||
|
getdomainname (char *domain, size_t len)
|
||||||
|
{
|
||||||
|
__try
|
||||||
|
{
|
||||||
|
PFIXED_INFO info = NULL;
|
||||||
|
ULONG size = 0;
|
||||||
|
|
||||||
|
if (GetNetworkParams(info, &size) == ERROR_BUFFER_OVERFLOW
|
||||||
|
&& (info = (PFIXED_INFO) alloca(size))
|
||||||
|
&& GetNetworkParams(info, &size) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
strncpy(domain, info->DomainName, len);
|
||||||
|
debug_printf ("gethostname %s", domain);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
__seterrno ();
|
||||||
|
}
|
||||||
|
__except (EFAULT)
|
||||||
|
__endtry
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* exported as gethostbyname: POSIX.1-2001 */
|
/* exported as gethostbyname: POSIX.1-2001 */
|
||||||
extern "C" struct hostent *
|
extern "C" struct hostent *
|
||||||
cygwin_gethostbyname (const char *name)
|
cygwin_gethostbyname (const char *name)
|
||||||
|
@ -1406,29 +1424,6 @@ cygwin_send (int fd, const void *buf, size_t len, int flags)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* getdomainname: 4.4BSD */
|
|
||||||
extern "C" int
|
|
||||||
getdomainname (char *domain, size_t len)
|
|
||||||
{
|
|
||||||
__try
|
|
||||||
{
|
|
||||||
PFIXED_INFO info = NULL;
|
|
||||||
ULONG size = 0;
|
|
||||||
|
|
||||||
if (GetNetworkParams(info, &size) == ERROR_BUFFER_OVERFLOW
|
|
||||||
&& (info = (PFIXED_INFO) alloca(size))
|
|
||||||
&& GetNetworkParams(info, &size) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
strncpy(domain, info->DomainName, len);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
__seterrno ();
|
|
||||||
}
|
|
||||||
__except (EFAULT)
|
|
||||||
__endtry
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fill out an ifconf struct. */
|
/* Fill out an ifconf struct. */
|
||||||
|
|
||||||
struct gaa_wa {
|
struct gaa_wa {
|
||||||
|
|
Loading…
Reference in New Issue