From d5dda483cb7ae1526019eccdcdd55815b36e984f Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 31 Jul 2025 19:24:46 +0200 Subject: [PATCH] os: xtrans: replace _XSERVTransGetHostname() by xhostname() Now that we have the OS layer xhostname() wrapper, we don't need the _XSERVTransGetHostname() function anymore. Signed-off-by: Enrico Weigelt, metux IT consult --- os/Xtrans.c | 38 +++++--------------------------------- os/Xtrans.h | 5 ----- os/Xtransutil.c | 9 ++++++--- 3 files changed, 11 insertions(+), 41 deletions(-) diff --git a/os/Xtrans.c b/os/Xtrans.c index 5dd872954..135476de1 100644 --- a/os/Xtrans.c +++ b/os/Xtrans.c @@ -56,6 +56,7 @@ from The Open Group. #endif #include "os/ossock.h" +#include "os/xhostname.h" /* * The transport table contains a definition for every transport (protocol) @@ -201,7 +202,6 @@ _XSERVTransParseAddress (const char *address, char *mybuf, *tmpptr = NULL; const char *_protocol = NULL; const char *_host, *_port; - char hostnamebuf[256]; char *_host_buf; int _host_len; @@ -305,10 +305,12 @@ _XSERVTransParseAddress (const char *address, *mybuf ++= '\0'; _host_len = strlen(_host); + + struct xhostname hn; if (_host_len == 0) { - _XSERVTransGetHostname (hostnamebuf, sizeof (hostnamebuf)); - _host = hostnamebuf; + xhostname(&hn); + _host = hn.name; } #ifdef IPv6 /* hostname in IPv6 [numeric_addr]:0 form? */ @@ -1060,34 +1062,4 @@ static int _XSERVTransWriteV (XtransConnInfo ciptr, struct iovec *iov, int iovcn return total; } -/* - * _XSERVTransGetHostname - similar to gethostname but allows special processing. - */ -int _XSERVTransGetHostname (char *buf, int maxlen) -{ - buf[0] = '\0'; - (void) gethostname (buf, maxlen); - buf [maxlen - 1] = '\0'; - return strlen(buf); -} - -#else /* WIN32 */ - -#include - -/* - * _XSERVTransGetHostname - similar to gethostname but allows special processing. - */ -int _XSERVTransGetHostname (char *buf, int maxlen) -{ - struct utsname name; - uname (&name); - - int len = strlen (name.nodename); - if (len >= maxlen) len = maxlen - 1; - memcpy (buf, name.nodename, len); - buf[len] = '\0'; - return len; -} - #endif /* WIN32 */ diff --git a/os/Xtrans.h b/os/Xtrans.h index 696078d48..0ef4a6528 100644 --- a/os/Xtrans.h +++ b/os/Xtrans.h @@ -292,9 +292,4 @@ int _XSERVTransConvertAddress ( Xtransaddr ** /* addrp */ ); -int _XSERVTransGetHostname ( - char * /* buf */, - int /* maxlen */ -); - #endif /* _XTRANS_H_ */ diff --git a/os/Xtransutil.c b/os/Xtransutil.c index de11c01dd..839e18253 100644 --- a/os/Xtransutil.c +++ b/os/Xtransutil.c @@ -62,6 +62,8 @@ from The Open Group. #include #endif +#include "os/xhostname.h" + #if defined(IPv6) && !defined(AF_INET6) #error "Cannot build IPv6 support without AF_INET6" #endif @@ -189,8 +191,9 @@ int _XSERVTransConvertAddress(int *familyp, int *addrlenp, Xtransaddr **addrp) * host name for authentication. */ - char hostnamebuf[256]; - int len = _XSERVTransGetHostname (hostnamebuf, sizeof hostnamebuf); + struct xhostname hn; + xhostname(&hn); + int len = strlen(hn.name); if (len > 0) { if (*addrp && *addrlenp < (len + 1)) @@ -201,7 +204,7 @@ int _XSERVTransConvertAddress(int *familyp, int *addrlenp, Xtransaddr **addrp) if (!*addrp) *addrp = malloc (len + 1); if (*addrp) { - strcpy ((char *) *addrp, hostnamebuf); + strcpy ((char *) *addrp, hn.name); *addrlenp = len; } else { *addrlenp = 0;