public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7704] libcody: Do not use a dummy port number in getaddrinfo().
@ 2022-03-18 15:23 Iain D Sandoe
0 siblings, 0 replies; only message in thread
From: Iain D Sandoe @ 2022-03-18 15:23 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:99fcd602a82e28e1d6a843e5cbe011b570dc81fa
commit r12-7704-g99fcd602a82e28e1d6a843e5cbe011b570dc81fa
Author: Iain Sandoe <iain@sandoe.co.uk>
Date: Sun Mar 13 16:29:45 2022 +0000
libcody: Do not use a dummy port number in getaddrinfo().
the getaddrinfo() requires either a non-null name for the server or
a port service / number. In the code that opens a connection we have
been calling this with a dummy port number of "0". Unfortunately this
triggers a bug in some BSD versions and OSes importing that code.
In this part of the code we do not really need a port number, since it
is not reasonable to open a connection to an unspecified host.
Setting hints info field to 0, and the servname parm to nullptr works
around the BSD bug in this case.
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
libcody/ChangeLog:
* netclient.cc (OpenInet6): Do not provide a dummy port number
in the getaddrinfo() call.
Diff:
---
libcody/netclient.cc | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/libcody/netclient.cc b/libcody/netclient.cc
index 7f81dd91810..558808be485 100644
--- a/libcody/netclient.cc
+++ b/libcody/netclient.cc
@@ -93,7 +93,7 @@ int OpenInet6 (char const **e, char const *name, int port)
}
addrinfo hints;
- hints.ai_flags = AI_NUMERICSERV;
+ hints.ai_flags = 0;
hints.ai_family = AF_INET6;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
@@ -102,9 +102,7 @@ int OpenInet6 (char const **e, char const *name, int port)
hints.ai_canonname = nullptr;
hints.ai_next = nullptr;
- /* getaddrinfo requires a port number, but is quite happy to accept
- invalid ones. So don't rely on it. */
- if (int err = getaddrinfo (name, "0", &hints, &addrs))
+ if (int err = getaddrinfo (name, nullptr, &hints, &addrs))
{
errstr = gai_strerror (err);
// What's the best errno to set?
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-03-18 15:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-18 15:23 [gcc r12-7704] libcody: Do not use a dummy port number in getaddrinfo() Iain D Sandoe
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).