Subject: Re: getnameinfo type incompatibility
To: Klaus Klein <klaus.klein@security.kpnqwest.com>
From: None <itojun@iijlab.net>
List: tech-net
Date: 05/21/2000 10:35:14
>> >> 	hmm, it looks fine...  i'll try this locally and then will
>> >> 	bring it to the repository.  btw, was it ansi that defines socklen_t?
>> >> 	or was it X/Open thing?
>> >Great!  As for socklen_t, it was first introduced in XSH5.
>> >(IPC would be really out of the scope of ANSI.)
>> 	do you think it okay to put socklen_t into <sys/ansi.h>?
>Oh, now I can see your point.  I proposed <sys/ansi.h> for __socklen_t
>because in a way it's similar to <machine/ansi.h>; the whole point of the
>exercise being the workaround for `multiple' typedefs, which was permitted
>in K&R IIRC.

	outline:
	include/netdb.h needs socklen_t declaration.
	simply including sys/types.h and sys/socket.h would have too many
	sideeffects (for example, include file requirement in gethostbyname(3)
	manpage gets changed).

	Klaus suggested the following patch.  it worked for me ("make build"
	goes just fine).  it adds sys/ansi.h (name suggested by Klaus).
	bsdi4 uses sys/sockettypes.h for similar usage.  not sure which
	filename sounds better - my vote goes to sys/sockettypes.h since
	socklen_t is outside ANSI.   any opinions, suggestions?

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/21 01:30:54
@@ -242,6 +242,17 @@
 #define SCOPE_DELIMITER '%'		/*KAME extension*/
 #endif /* !_XOPEN_SOURCE */
 
+/*
+ * Data types
+ */
+#if !defined(_XOPEN_SOURCE)
+#include <sys/ansi.h>
+#ifndef socklen_t
+typedef __socklen_t	socklen_t;
+#define socklen_t	socklen_t
+#endif
+#endif
+
 __BEGIN_DECLS
 void		endhostent __P((void));
 void		endnetent __P((void));
@@ -284,7 +295,7 @@
 #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 *,
+int		getnameinfo __P((const struct sockaddr *, socklen_t, char *,
 				 size_t, char *, size_t, int));
 void		freeaddrinfo __P((struct addrinfo *));
 char		*gai_strerror __P((int));
Index: sys/sys/Makefile
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/Makefile,v
retrieving revision 1.19
diff -u -r1.19 Makefile
--- Makefile	2000/01/11 10:53:01	1.19
+++ Makefile	2000/05/21 01:30:55
@@ -21,6 +21,7 @@
 	tprintf.h trace.h tty.h ttychars.h ttycom.h ttydefaults.h ttydev.h \
 	types.h ucred.h uio.h un.h unistd.h unpcb.h user.h utsname.h \
 	vadvise.h vmmeter.h vnode.h vnode_if.h vsio.h wait.h
+INCS+=	ansi.h
 
 SYMLINKS= sys/exec_elf.h /usr/include/elf.h \
 	sys/fcntl.h /usr/include/fcntl.h \
Index: sys/sys/ansi.h
===================================================================
RCS file: ansi.h
diff -N ansi.h
--- /dev/null	Sat May 20 14:30:01 2000
+++ ansi.h	Sat May 20 18:30:55 2000
@@ -0,0 +1,45 @@
+/*	$NetBSD$	*/
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ *
+ *	@(#)ansi.h	8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef	_SYS_ANSI_H_
+#define	_SYS_ANSI_H_
+
+#include <sys/cdefs.h>
+
+typedef unsigned int __socklen_t;
+
+#endif	/* _SYS_ANSI_H_ */
Index: sys/sys/socket.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/socket.h,v
retrieving revision 1.54
diff -u -r1.54 socket.h
--- socket.h	2000/04/03 11:49:25	1.54
+++ socket.h	2000/05/21 01:30:57
@@ -74,7 +74,11 @@
 /*
  * Data types.
  */
-typedef	unsigned int	socklen_t;
+#include <sys/ansi.h>
+#ifndef socklen_t
+typedef __socklen_t	socklen_t;
+#define socklen_t	socklen_t
+#endif
 
 /*
  * Socket types.