Subject: getnameinfo type incompatibility
To: None <tech-net@netbsd.org>
From: None <itojun@iijlab.net>
List: tech-net
Date: 05/06/2000 00:56:49
	KAME codebase made a mistake about 2nd argument type of getnameinfo
	(rfc2553 uses socklen_t.  KAME uses size_t based on pre-2553 document).
	does the following patch look reasonable?  if you have better name for
	__RENAME() hack please let me know.

	really sorry for this, we should have noticed it earlier...

itojun


Index: include/netdb.h
===================================================================
RCS file: /cvsroot/basesrc/include/netdb.h,v
retrieving revision 1.17
diff -u -r1.17 netdb.h
--- netdb.h	2000/02/09 12:25:07	1.17
+++ netdb.h	2000/05/05 15:54:00
@@ -284,8 +284,9 @@
 #if !defined(_XOPEN_SOURCE)
 int		getaddrinfo __P((const char *, const char *,
 				 const struct addrinfo *, struct addrinfo **));
-int		getnameinfo __P((const struct sockaddr *, size_t, char *,
-				 size_t, char *, size_t, int));
+int		getnameinfo __P((const struct sockaddr *, socklen_t, char *,
+				 size_t, char *, size_t, int))
+				__RENAME(__rfc2553_getnameinfo);
 void		freeaddrinfo __P((struct addrinfo *));
 char		*gai_strerror __P((int));
 #endif
Index: lib/libc/net/Makefile.inc
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/net/Makefile.inc,v
retrieving revision 1.54
diff -u -r1.54 Makefile.inc
--- Makefile.inc	2000/04/24 10:24:47	1.54
+++ Makefile.inc	2000/05/05 15:54:00
@@ -18,7 +18,7 @@
 CPPFLAGS+=-DRESOLVSORT -I.
 
 # IPv6
-SRCS+=	getaddrinfo.c getnameinfo.c ip6opt.c rthdr.c vars6.c
+SRCS+=	getaddrinfo.c getnameinfo.c getnameinfo_compat.c ip6opt.c rthdr.c vars6.c
 SRCS+=	if_indextoname.c if_nameindex.c if_nametoindex.c
 
 LPREFIX=_nsyy
Index: lib/libc/net/getnameinfo.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/net/getnameinfo.c,v
retrieving revision 1.16
diff -u -r1.16 getnameinfo.c
--- getnameinfo.c	2000/04/26 16:08:38	1.16
+++ getnameinfo.c	2000/05/05 15:54:01
@@ -61,9 +61,11 @@
 #include <string.h>
 #include <stddef.h>
 
+#if 0	/*see getnameinfo_compat.c*/
 #ifdef __weak_alias
 __weak_alias(getnameinfo,_getnameinfo)
 #endif
+#endif
 
 #define SUCCESS 0
 #define ANY 0
@@ -108,7 +110,7 @@
 int
 getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
 	const struct sockaddr *sa;
-	size_t salen;
+	socklen_t salen;
 	char *host;
 	size_t hostlen;
 	char *serv;
Index: lib/libc/net/getnameinfo_compat.c
===================================================================
RCS file: getnameinfo_compat.c
diff -N getnameinfo_compat.c
--- /dev/null	Fri May  5 03:52:13 2000
+++ getnameinfo_compat.c	Fri May  5 08:54:01 2000
@@ -0,0 +1,64 @@
+/*	$NetBSD$	*/
+
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: getnameinfo.c,v 1.16 2000/04/26 16:08:38 itojun Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#ifdef __weak_alias
+__weak_alias(getnameinfo,_getnameinfo)
+#endif
+
+/* pre-2553 */
+int getnameinfo __P((const struct sockaddr *, size_t,
+		char *, size_t, char *, size_t, int));
+/* rfc2553 */
+extern int __rfc2553_getnameinfo __P((const struct sockaddr *, socklen_t,
+		char *, size_t, char *, size_t, int));
+
+int
+getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
+	const struct sockaddr *sa;
+	size_t salen;
+	char *host;
+	size_t hostlen;
+	char *serv;
+	size_t servlen;
+	int flags;
+{
+	return __rfc2553_getnameinfo(sa, salen, host, hostlen, serv, servlen,
+		flags);
+}