On Thu, Dec 30, 2004 at 10:47:28AM +0100, Michal Trojnara wrote:
Peter Pentchev wrote:
The second chunk of the patch fixes getnameinfo() error reporting - just like with getaddrinfo(), getnameinfo() errors should be displayed using s_gai_strerror() instead of sockerror().
Manuals seem to claim just the opposite.
Oops. I should have guessed that much when I saw that you had chosen that way; instead of checking why, I just wondered briefly and let it go.
Linux Manual: RETURN VALUE On success 0 is returned, and node and service names, if requested, are filled with NUL-terminated strings, possibly truncated to fit the specified buffer lengths. On error a nonzero value is returned, and errno is set appropriately.
That's funny. Which IPv6 implementation is that - USAGI?
Microsoft: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/win... Return Values Success returns zero. Any nonzero return value indicates failure. Use the WSAGetLastError function to retrieve error information.
That's not so funny, but still interesting.
The problem is, FreeBSD uses the KAME implementation, and the getnameinfo(3) manpage claims POSIX 1003.1g conformance, as well as RFC 2553 conformance. You can see the FreeBSD manual page at http://www.FreeBSD.org/cgi/man.cgi?query=getnameinfo&sektion=3 and RFC 2553 at http://www.faqs.org/rfc/rfc2553.txt - both say that getnameinfo() should return the error directly, and the error should be one of the EAI_* constants, just like getaddrinfo().
What do you think about the following version of the patch, which adds a configure check for the KAME version of getnameinfo()?
G'luck, Peter
--- configure.ac.orig Sun Dec 26 01:30:48 2004 +++ configure.ac Thu Dec 30 13:18:26 2004 @@ -176,6 +176,30 @@ AC_MSG_NOTICE([**************************************** library functions]) AC_CHECK_FUNCS(snprintf vsnprintf openpty _getpty daemon waitpid wait4 sysconf getrlimit pthread_sigmask setgroups localtime_r chroot endhostent setsid getaddrinfo getnameinfo poll)
+AC_MSG_CHECKING([for KAME getnameinfo]) +AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [ + [#include <sys/types.h>] + [#include <sys/socket.h>] + [#include <stdio.h>] + [#include <stdlib.h>] + [#include <errno.h>] + [#include <netdb.h>] + ], + [ + [int err;] + [err = getnameinfo(NULL, -1, NULL, -1, NULL, -1, -1);] + [return (err != EAI_FAIL);] + ]) + ], + [ + AC_MSG_RESULT([yes]); + AC_DEFINE(HAVE_KAME_GETNAMEINFO) + ], + [AC_MSG_RESULT([no])] +) + AC_MSG_NOTICE([**************************************** optional features]) # Use RSA? AC_MSG_CHECKING([whether to disable RSA support]) --- src/network.c.orig Thu Oct 14 18:03:49 2004 +++ src/network.c Thu Dec 30 13:26:23 2004 @@ -563,9 +563,18 @@ char *s_ntop(char *text, SOCKADDR_UNION *addr) { char host[20], port[6];
+#ifdef HAVE_KAME_GETNAMEINFO + int err; + err = getnameinfo(&addr->sa, addr_len(*addr), + host, 20, port, 6, NI_NUMERICHOST|NI_NUMERICSERV); + if (err) { + s_log(LOG_ERR, "Error resolving the specified address: %s", + s_gai_strerror(err)); +#else if(getnameinfo(&addr->sa, addr_len(*addr), host, 20, port, 6, NI_NUMERICHOST|NI_NUMERICSERV)) { sockerror("getnameinfo"); +#endif strcpy(text, "unresolvable IP"); return text; }