bug-gnulib
[Top][All Lists]
Advanced

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

Re: getaddrinfo: compilation error on OSF/1 5.1


From: Bruno Haible
Subject: Re: getaddrinfo: compilation error on OSF/1 5.1
Date: Sat, 31 Mar 2007 19:26:22 +0200
User-agent: KMail/1.5.4

Hi Simon,

This getaddrinfo.c error on OSF/1 is now the only remaining compilation error
of all of gnulib on OSF/1, HP-UX, AIX, Solaris, IRIX.

> >   int getnameinfo(
> >           const struct sockaddr *sa,
> >           socklen_t salen,
> >           char *node,
> >           size_t *nodelen,
> >           char *serv,
> >           size_t servlen,
> >           int flags);
> >
> > which is different from what getaddrinfo.c does.
> 
> One problem is that getaddrinfo.c use socklen_t for the strings, which
> seems wrong.  But this is what
> http://www.opengroup.org/onlinepubs/009695399/functions/getnameinfo.html
> says!  Isn't that bad?

Yes, it is bad. Using 'socklen_t' to denote the length of a string is bad: it
forces the caller to check whether the lengths of the given strings actually
fit into such a small integer. I too deplore that the POSIX standardization
commitee sometimes does not have the courage to fix blatant mistakes during
the standardization review. (It's not only getnameinfo, it's also iconv's
prototype, it's the naming of 'fstatat', 'fopenat'..., and the naming of
open_memstream compared to fmemopen.)

> As far as I understand, socklen_t should be
> used for 'struct sockaddr's?  It might be too late to change this now,
> though...

Yes. gnulib should do as POSIX says, even when it makes little sense.

> One solution would be for getaddrinfo.m4 to check what the prototype
> in the system header is, and have getaddrinfo.c use the same
> prototype.

No, getaddrinfo.c should use the POSIX prototype. We don't want #if
distinction in code that invokes getnameinfo. Use a
  #define getnameinfo rpl_getnameinfo
to avoid a clash of the prototypes.

> So I suppose getaddrinfo.m4 should finally test whether:
> 
> 1) The POSIX prototype:
> 
> #include <sys/types.h>
> #ifdef HAVE_SYS_SOCKET_H
> #include <sys/socket.h>
> #endif
> #ifdef HAVE_NETDB_H
> #include <netdb.h>
> #endif
> #ifdef HAVE_WS2TCPIP_H
> #include <ws2tcpip.h>
> #endif
> extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
>                      char *restrict node, socklen_t nodelen,
>                      char *restrict service, socklen_t servicelen,
>                      int flags);
> 
> or
> 
> 2) The OSF/1 approach:
> 
> #include <sys/types.h>
> #ifdef HAVE_SYS_SOCKET_H
> #include <sys/socket.h>
> #endif
> #ifdef HAVE_NETDB_H
> #include <netdb.h>
> #endif
> #ifdef HAVE_WS2TCPIP_H
> #include <ws2tcpip.h>
> #endif
> extern int getnameinfo(const struct sockaddr *sa, socklen_t salen,
>                      char *node, size_t nodelen,
>                      char *service, size_t servicelen,
>                      int flags);
> 
> parses correctly, and then set some #define depending on which is
> used

Yes.

> which getaddrinfo.c could use?

getaddrinfo.c needs this info in order to invoke the system's getnameinfo
function. But the function it provides should be POSIX compliant.

Bruno





reply via email to

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