[newlib-cygwin] Cygwin: gethostname: fix fetching hostname from non-winsock function

Corinna Vinschen corinna@sourceware.org
Thu Jan 24 13:05:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c6171b9fde818b058b710c5e146bdecd963b7e9e

commit c6171b9fde818b058b710c5e146bdecd963b7e9e
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Thu Jan 24 14:01:59 2019 +0100

    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 <corinna@vinschen.de>

Diff:
---
 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 cfd29d1..2af71f7 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 c847b91..5835952 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.



More information about the Cygwin-cvs mailing list