extern "C" int
cygwin_gethostname (char *name, size_t len)
{
- int res = -1;
-
__try
{
- if (gethostname (name, len))
- {
- DWORD local_len = len;
+ PFIXED_INFO info = NULL;
+ ULONG size = 0;
- if (!GetComputerNameExA (ComputerNameDnsHostname, name,
- &local_len))
- {
- if (GetLastError () == ERROR_MORE_DATA)
- set_errno (ENAMETOOLONG);
- else
- set_winsock_errno ();
- __leave;
- }
+ if (GetNetworkParams(info, &size) == ERROR_BUFFER_OVERFLOW
+ && (info = (PFIXED_INFO) alloca(size))
+ && GetNetworkParams(info, &size) == ERROR_SUCCESS)
+ {
+ strncpy(name, info->HostName, len);
+ debug_printf ("gethostname %s", name);
+ return 0;
}
- debug_printf ("name %s", name);
- res = 0;
+ __seterrno ();
}
- __except (EFAULT) {}
+ __except (EFAULT)
__endtry
- return res;
+ return -1;
}
extern "C" int
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 */
extern "C" struct hostent *
cygwin_gethostbyname (const char *name)
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. */
struct gaa_wa {