From c6171b9fde818b058b710c5e146bdecd963b7e9e Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 24 Jan 2019 14:01:59 +0100 Subject: [PATCH] Cygwin: gethostname: fix fetching hostname from non-winsock function If gethostname() fails we call GetComputerNameEx with ComputerNameDnsFullyQualified. This is wrong, gethostname should return the hostname only, not the FQDN. Fix this by calling GetComputerNameEx with ComputerNameDnsHostname. Signed-off-by: Corinna Vinschen --- winsup/cygwin/net.cc | 2 +- winsup/cygwin/release/2.12.0 | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index cfd29d191..2af71f7e5 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -718,7 +718,7 @@ cygwin_gethostname (char *name, size_t len) { DWORD local_len = len; - if (!GetComputerNameExA (ComputerNameDnsFullyQualified, name, + if (!GetComputerNameExA (ComputerNameDnsHostname, name, &local_len)) { if (GetLastError () == ERROR_MORE_DATA) diff --git a/winsup/cygwin/release/2.12.0 b/winsup/cygwin/release/2.12.0 index c847b91c0..5835952ee 100644 --- a/winsup/cygwin/release/2.12.0 +++ b/winsup/cygwin/release/2.12.0 @@ -79,3 +79,5 @@ Bug Fixes Addresses: https://cygwin.com/ml/cygwin/2018-12/msg00173.html - Fix thread names in GDB when cygthreads get reused. + +- Fix return value of gethostname in a border case.