From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14071 invoked by alias); 12 Feb 2014 16:53:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 14061 invoked by uid 89); 12 Feb 2014 16:53:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.4 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Feb 2014 16:53:30 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1CGrO1j005149 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 12 Feb 2014 11:53:24 -0500 Received: from host2.jankratochvil.net (ovpn-116-93.ams2.redhat.com [10.36.116.93]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s1CGrJXC018499 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Wed, 12 Feb 2014 11:53:23 -0500 Date: Wed, 12 Feb 2014 16:53:00 -0000 From: Jan Kratochvil To: Paul Fertser Cc: Eli Zaretskii , gdb-patches@sourceware.org, ktietz@redhat.com Subject: Re: [PATCH v3] Add IPv6 support for outgoing remote TCP connections Message-ID: <20140212165318.GA8969@host2.jankratochvil.net> References: <20140210195758.GA16956@host2.jankratochvil.net> <1392148089-18253-1-git-send-email-fercerpav@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1392148089-18253-1-git-send-email-fercerpav@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2014-02/txt/msg00420.txt.bz2 On Tue, 11 Feb 2014 20:48:09 +0100, Paul Fertser wrote: > --- a/gdb/configure.ac > +++ b/gdb/configure.ac > @@ -512,6 +512,9 @@ AC_CHECK_FUNC(wctype, [], > # Some systems (e.g. Solaris) have `gethostbyname' in libnsl. > AC_SEARCH_LIBS(gethostbyname, nsl) > > +# Borrow from gnulib, Solaris might additionally need nsl Missing trailing dot (.). > +AC_SEARCH_LIBS(getaddrinfo, [socket network net], [], [], [-lnsl]) Where is it stated in gnulib? I could not find it. > + > # Some systems (e.g. Solaris) have `socketpair' in libsocket. > AC_SEARCH_LIBS(socketpair, socket) > > diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c > index c288ab4..15f7648 100644 > --- a/gdb/ser-tcp.c > +++ b/gdb/ser-tcp.c > @@ -39,6 +39,7 @@ > > #ifdef USE_WIN32API > #include > +#include Put there AC_CHECK_HEADERS for it unless someone confirms all MS-Windows hosts really have that include file. I have no idea. > #ifndef ETIMEDOUT > #define ETIMEDOUT WSAETIMEDOUT > #endif > @@ -157,9 +158,10 @@ int > net_open (struct serial *scb, const char *name) > { > char *port_str, hostname[100]; > - int n, port, tmp; > + int n, tmp; > int use_udp; > - struct hostent *hostent; > + struct addrinfo hints; > + struct addrinfo *result, *rp; > struct sockaddr_in sockaddr; > #ifdef USE_WIN32API > u_long ioarg; > @@ -177,7 +179,7 @@ net_open (struct serial *scb, const char *name) > else if (strncmp (name, "tcp:", 4) == 0) > name = name + 4; > > - port_str = strchr (name, ':'); > + port_str = strrchr (name, ':'); > > if (!port_str) > error (_("net_open: No colon in host name!")); /* Shouldn't ever > @@ -186,124 +188,133 @@ net_open (struct serial *scb, const char *name) > tmp = min (port_str - name, (int) sizeof hostname - 1); > strncpy (hostname, name, tmp); /* Don't want colon. */ > hostname[tmp] = '\000'; /* Tie off host name. */ > - port = atoi (port_str + 1); > + port_str++; > > /* Default hostname is localhost. */ > if (!hostname[0]) > strcpy (hostname, "localhost"); > > - hostent = gethostbyname (hostname); > - if (!hostent) > + memset (&hints, 0, sizeof (struct addrinfo)); > + hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ > + if (use_udp) > + hints.ai_socktype = SOCK_DGRAM; > + else > + hints.ai_socktype = SOCK_STREAM; > + hints.ai_flags = 0; > + hints.ai_protocol = 0; > + > + tmp = getaddrinfo (hostname, port_str, &hints, &result); > + if (tmp) > { > fprintf_unfiltered (gdb_stderr, "%s: unknown host\n", hostname); It should use gai_strerror(). I understand you wrote # In this patch I was trying to change current behaviour as little as # possible. It can be a separate patch 2/2 or even in this one. > errno = ENOENT; > return -1; > } > > - sockaddr.sin_family = PF_INET; > - sockaddr.sin_port = htons (port); > - memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr, > - sizeof (struct in_addr)); > - > - retry: > - > - if (use_udp) > - scb->fd = gdb_socket_cloexec (PF_INET, SOCK_DGRAM, 0); > - else > - scb->fd = gdb_socket_cloexec (PF_INET, SOCK_STREAM, 0); > + for (rp = result; ; rp = rp->ai_next ? rp->ai_next : result) > + { > + scb->fd = gdb_socket_cloexec (rp->ai_family, rp->ai_socktype, > + rp->ai_protocol); > > - if (scb->fd == -1) > - return -1; > + if (scb->fd == -1) > + continue; Neither 'return -1' nor 'continue' are right here. It should not lock-up if none of the sockets can be created, it should return so that the error gets reported. > - /* Set socket nonblocking. */ > - ioarg = 1; > - ioctl (scb->fd, FIONBIO, &ioarg); > + /* Set socket nonblocking. */ > + ioarg = 1; > + ioctl (scb->fd, FIONBIO, &ioarg); [...] Thanks, Jan