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: Simon Josefsson
Subject: Re: getaddrinfo: compilation error on OSF/1 5.1
Date: Mon, 12 Mar 2007 12:28:20 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.94 (gnu/linux)

Bruno Haible <address@hidden> writes:

> Hi Simon,
>
> On OSF/1 5.1, with cc as compiler, the getaddrinfo module fails to compile:
>
> cc: Warning: getaddrinfo.c, line 334: In this declaration, parameter 2 has a 
> different type than specified in an earlier declaration of this function. 
> (mismatparam)
> int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
> ----^
> cc: Error: getaddrinfo.c, line 334: In this declaration, the type of 
> "getnameinfo" is not compatible with the type of a previous declaration of 
> "getnameinfo" at line number 290 in file /usr/include/netdb.h. (notcompat)
> int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
> ----^
>
> The reason is that <netdb.h> declares the functions as follows:
>
>   int getaddrinfo(
>           const char *nodename,
>           const char *servname,
>           const struct addrinfo *hints,
>           struct addrinfo **res);
>
>   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?  As far as I understand, socklen_t should be
used for 'struct sockaddr's?  It might be too late to change this now,
though...

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.  The problems are:

1) Should 'restrict' be used?
2) Use socklen_t or size_t.

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, which getaddrinfo.c could use?

What do you think?  Is there no better alternative?

/Simon




reply via email to

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