Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Paul Fertser <fercerpav@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
	gdb-patches@sourceware.org,        ktietz@redhat.com
Subject: Re: [PATCH v3] Add IPv6 support for outgoing remote TCP connections
Date: Wed, 12 Feb 2014 16:53:00 -0000	[thread overview]
Message-ID: <20140212165318.GA8969@host2.jankratochvil.net> (raw)
In-Reply-To: <1392148089-18253-1-git-send-email-fercerpav@gmail.com>

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 <winsock2.h>
> +#include <ws2tcpip.h>

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


  reply	other threads:[~2014-02-12 16:53 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-08 16:54 [PATCH] Add IPv6 support for " Paul Fertser
2014-02-09  8:31 ` Jan Kratochvil
2014-02-09  9:53   ` Paul Fertser
2014-02-09 13:05     ` Jan Kratochvil
2014-02-09 16:35       ` Eli Zaretskii
2014-02-09 16:47         ` Jan Kratochvil
2014-02-09 17:08           ` Paul Fertser
2014-02-09 17:29             ` Jan Kratochvil
     [not found]               ` <1392033768-16793-1-git-send-email-fercerpav@gmail.com>
2014-02-10 16:53                 ` [PATCH v2] " Eli Zaretskii
2014-02-10 17:02                   ` Paul Fertser
2014-02-10 17:45                     ` Eli Zaretskii
2014-02-10 19:58                       ` getaddrinfo available on all GDB hosts? [Re: [PATCH v2] Add IPv6 support for remote TCP connections] Jan Kratochvil
2014-02-11  3:42                         ` Joel Brobecker
2014-02-11 20:05                           ` Jan Kratochvil
2014-02-11 20:33                             ` Stan Shebs
2014-02-12  3:04                               ` Joel Brobecker
2014-02-12  3:00                             ` Joel Brobecker
2014-02-12 12:10                               ` Jan Kratochvil
2014-02-13  7:37                                 ` Joel Brobecker
2014-02-13 10:44                                   ` [patch] [sim] --disable-sim on ppc* by default (for AIX) [Re: getaddrinfo available on all GDB hosts?] Jan Kratochvil
2014-02-13 10:51                                     ` Pedro Alves
2014-02-13 11:04                                       ` Jan Kratochvil
2014-02-13 11:39                                         ` Pedro Alves
2014-02-13 11:51                                           ` Joel Brobecker
2014-02-13 12:08                                           ` [cancel] " Jan Kratochvil
2014-02-13 11:59                                     ` Joel Brobecker
2014-02-13 14:26                                 ` getaddrinfo available on all GDB hosts? [Re: [PATCH v2] Add IPv6 support for remote TCP connections] Tom Tromey
2014-02-13 11:36                           ` Jan Kratochvil
2014-02-13 11:55                             ` Joel Brobecker
2014-02-11 19:48                         ` [PATCH v3] Add IPv6 support for outgoing remote TCP connections Paul Fertser
2014-02-12 16:53                           ` Jan Kratochvil [this message]
2014-02-12 17:32                             ` Paul Fertser
2014-02-12 20:10                               ` Jan Kratochvil
2015-03-22 16:39             ` [PATCH] Add IPv6 support for " Jan Kratochvil
2015-03-22 16:54               ` Eli Zaretskii
2015-03-22 17:09                 ` Jan Kratochvil
2015-03-22 17:48                   ` Eli Zaretskii
2015-03-23 18:02                     ` Pedro Alves
2015-03-23 18:42                       ` Eli Zaretskii
2015-03-23 19:12                         ` Joel Brobecker
2015-03-23 19:18                           ` Eli Zaretskii
2015-04-13 15:12                             ` Pedro Alves
2015-04-13 15:27                               ` Eli Zaretskii
2015-04-13 16:10                                 ` Pedro Alves
2015-03-23 19:19                         ` Pedro Alves
2015-03-23 19:03               ` Corinna Vinschen
2015-03-23 19:12                 ` Pedro Alves
2014-02-09 16:29     ` Eli Zaretskii
2014-02-09 16:25   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140212165318.GA8969@host2.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=eliz@gnu.org \
    --cc=fercerpav@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=ktietz@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox