bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] Re: getaddrinfo


From: Paul Eggert
Subject: Re: [Bug-gnulib] Re: getaddrinfo
Date: Mon, 08 Nov 2004 12:37:20 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Simon Josefsson <address@hidden> writes:

> +# define EAI_BADFLAGS          -1    /* Invalid value for `ai_flags' field.  
> */

"-1" should be parenthesized here, and similarly for the other macros.

> +  if (hints &&
> +      hints->ai_protocol != SOCK_STREAM &&
> +      hints->ai_protocol != SOCK_DGRAM)
> +      /* FIXME: Support other protocols. */
> +    return EAI_SERVICE; /* FIXME: Better return code? */
> ...
> +  if (servname)
> +    {
> +      /* FIXME: Use getservbyname_r if available. */
> +      se = getservbyname (servname,
> +                       hints->ai_protocol == SOCK_DGRAM ? "udp" : "tcp");
> +      if (!se)
> +     return EAI_SERVICE;
> +    }

This dumps core if (servname && !hints).  Also, I don't see why the code
cares about hints->ai_protocol when !servname.

freeaddrinfo has a memory leak: it doesn't free the struct sockaddr_in
or struct sockaddr_in6 structure allocated by getaddrinfo.  To fix
this I would modify getaddrinfo to invoke malloc just once, to
allocate all the memory that it needs, rather than invoking it twice.

> +const char *
> +gai_strerror (int code)
> +{
> +  size_t i;
> +  for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i)
> +    if (values[i].code == code)
> +      return _(values[i].msg);

A small point: since you specify the encoding for "code" you could
make gai_strerror an O(1) operation (by using "code" as an index
directly into a table) rather than O(N).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]