public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: net: unify gethostname/getdomainname
@ 2019-01-24 13:22 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2019-01-24 13:22 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 2166f7dc0d9ae212d9f663241501f6fd17b71e50
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Thu Jan 24 14:22:09 2019 +0100

    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>

Diff:
---
 winsup/cygwin/net.cc | 77 ++++++++++++++++++++++++----------------------------
 1 file changed, 36 insertions(+), 41 deletions(-)

diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 2af71f7..cd296d1 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -710,30 +710,24 @@ cygwin_getservbyport (int port, const char *proto)
 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
@@ -750,6 +744,30 @@ sethostname (const char *name, size_t len)
   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)
@@ -1406,29 +1424,6 @@ cygwin_send (int fd, const void *buf, size_t len, int flags)
   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 {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-01-24 13:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-24 13:22 [newlib-cygwin] Cygwin: net: unify gethostname/getdomainname Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).