libsocket icon indicating copy to clipboard operation
libsocket copied to clipboard

Cannot connect to server when no DNS available

Open ducss2015 opened this issue 10 years ago • 2 comments

I encountered the following error on inet_stream_server side when I use inet_stream to connect to it with the server's IP address specified (VERBOSE set to 1)

Temporary failure in name resolution
/home/libsocket-2.4.1/C++/inetserverstream.cpp:169: inet_stream_server::accept() - could not accept new connection on stream server socket! (Success)

The reason is the getnameinfo fails when my system does not connect to the Internet. The /etc/resolv.conf on both client and server is nameserver 127.0.0.1

I suggest to handle the case like following. (The patch has not been designed to work when _TRADITIONAL_RDNS is set, though)

diff --git a/C/inet/libinetsocket.c b/C/inet/libinetsocket.c
index 3dbb253..5b0208d 100644
--- a/C/inet/libinetsocket.c
+++ b/C/inet/libinetsocket.c
@@ -774,10 +774,12 @@ int accept_inet_stream_socket(int sfd, char* src_host, size_t src_host_len, char
           errstr = gai_strerror(retval);
           debug_write(errstr);
 # endif
-           return -1;
+      /* It is not a fatal error when the DNS is unavailable */
+      if (errno != 0)
+        return -1;
        }
 # endif

ducss2015 avatar Jul 07 '15 05:07 ducss2015

wdyt about #26?

dermesser avatar Jul 10 '15 22:07 dermesser

although, thinking about it -- getnameinfo() probably doesn't set errno anyway, so we could take out that condition.

dermesser avatar Jul 10 '15 22:07 dermesser