...and here's a diff for discussion that removes the sa_family_t and 
socklen_t typedefs from sys/types.h, transferring them to sys/socket.h and 
duping them in netinet/in.h, netinet6/in6.h, and sys/un.h as necessary.

There are only two user-land fixes necessary for a build with this, in 
sasyncd and bind (the latter in the locally written privsep bits)

This diff also includes some compliance fixes for netinet/in.h that I had 
been noodelling on, hiding behind __BSD_VISIBLE various things which are 
not permitted by the standard.

The switching from socklen_t to __socklen_t in the pure kernel headers 
(sys/domain.h and sys/socketvar.h) is perhaps a bit dubious; suggestions 
are welcome.  Perhaps sys/types.h should continue to declare sa_family_t 
and socklen_t under __BSD_VISIBLE...

Philip Guenther


Index: include/netdb.h
===================================================================
RCS file: /cvs/src/include/netdb.h,v
retrieving revision 1.27
diff -u -p -r1.27 netdb.h
--- include/netdb.h     2 Jun 2009 16:47:50 -0000       1.27
+++ include/netdb.h     21 Nov 2010 08:37:30 -0000
@@ -89,6 +89,7 @@
 
 #include <sys/param.h>
 #include <sys/cdefs.h>
+#include <sys/socket.h>
 
 #define        _PATH_HEQUIV    "/etc/hosts.equiv"
 #define        _PATH_HOSTS     "/etc/hosts"
Index: sys/sys/domain.h
===================================================================
RCS file: /cvs/src/sys/sys/domain.h,v
retrieving revision 1.9
diff -u -p -r1.9 domain.h
--- sys/sys/domain.h    22 Feb 2009 07:47:22 -0000      1.9
+++ sys/sys/domain.h    21 Nov 2010 08:25:46 -0000
@@ -47,7 +47,7 @@ struct        domain {
        char    *dom_name;
        void    (*dom_init)(void);      /* initialize domain data structures */
                                        /* externalize access rights */
-       int     (*dom_externalize)(struct mbuf *, socklen_t);
+       int     (*dom_externalize)(struct mbuf *, __socklen_t);
                                        /* dispose of internalized rights */
        void    (*dom_dispose)(struct mbuf *);
        struct  protosw *dom_protosw, *dom_protoswNPROTOSW;
Index: sys/sys/socket.h
===================================================================
RCS file: /cvs/src/sys/sys/socket.h,v
retrieving revision 1.70
diff -u -p -r1.70 socket.h
--- sys/sys/socket.h    5 Jul 2010 22:20:22 -0000       1.70
+++ sys/sys/socket.h    21 Nov 2010 08:25:48 -0000
@@ -35,10 +35,30 @@
 #ifndef _SYS_SOCKET_H_
 #define        _SYS_SOCKET_H_
 
-/*
- * needed for ALIGNBYTES
- */
-#include <machine/param.h>
+#include <sys/cdefs.h>
+#include <sys/_types.h>
+#include <machine/param.h>             /* needed for ALIGN() */
+
+#ifndef        _SOCKLEN_T_DEFINED_
+#define        _SOCKLEN_T_DEFINED_
+typedef        __socklen_t     socklen_t;      /* length type for network 
syscalls */
+#endif
+
+#ifndef        _SA_FAMILY_T_DEFINED_
+#define        _SA_FAMILY_T_DEFINED_
+typedef        __sa_family_t   sa_family_t;    /* sockaddr address family type 
*/
+#endif
+
+#ifndef        _SIZE_T_DEFINED_
+#define        _SIZE_T_DEFINED_
+typedef        __size_t        size_t;
+#endif
+
+#ifndef        _SSIZE_T_DEFINED_
+#define        _SSIZE_T_DEFINED_
+typedef        __ssize_t       ssize_t;
+#endif
+
 
 /*
  * Definitions related to sockets: types, address families, options.
Index: sys/sys/socketvar.h
===================================================================
RCS file: /cvs/src/sys/sys/socketvar.h,v
retrieving revision 1.47
diff -u -p -r1.47 socketvar.h
--- sys/sys/socketvar.h 24 Sep 2010 02:59:46 -0000      1.47
+++ sys/sys/socketvar.h 21 Nov 2010 08:25:49 -0000
@@ -297,7 +297,7 @@ void        soqinsque(struct socket *head, stru
 int    soqremque(struct socket *so, int q);
 int    soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio,
            struct mbuf **mp0, struct mbuf **controlp, int *flagsp,
-           socklen_t controllen);
+           __socklen_t controllen);
 int    soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
 void   sorflush(struct socket *so);
 int    sosend(struct socket *so, struct mbuf *addr, struct uio *uio,
Index: sys/sys/types.h
===================================================================
RCS file: /cvs/src/sys/sys/types.h,v
retrieving revision 1.31
diff -u -p -r1.31 types.h
--- sys/sys/types.h     16 Mar 2008 19:42:57 -0000      1.31
+++ sys/sys/types.h     21 Nov 2010 08:25:52 -0000
@@ -159,8 +159,6 @@ typedef     __fsfilcnt_t    fsfilcnt_t;     /* file
  */
 typedef __in_addr_t    in_addr_t;      /* base type for internet address */
 typedef __in_port_t    in_port_t;      /* IP port type */
-typedef __sa_family_t  sa_family_t;    /* sockaddr address family type */
-typedef __socklen_t    socklen_t;      /* length type for network syscalls */
 
 /*
  * The following types may be defined in multiple header files.
Index: sys/sys/un.h
===================================================================
RCS file: /cvs/src/sys/sys/un.h,v
retrieving revision 1.10
diff -u -p -r1.10 un.h
--- sys/sys/un.h        22 Feb 2009 07:47:22 -0000      1.10
+++ sys/sys/un.h        21 Nov 2010 08:25:52 -0000
@@ -65,8 +65,19 @@ int  unp_internalize(struct mbuf *, struc
 void   unp_dispose(struct mbuf *);
 #else /* !_KERNEL */
 
+#include <sys/cdefs.h>
+#include <sys/_types.h>
+
+#ifndef        _SA_FAMILY_T_DEFINED_
+#define        _SA_FAMILY_T_DEFINED_
+typedef        __sa_family_t   sa_family_t;    /* sockaddr address family type 
*/
+#endif
+
+#if __BSD_VISIBLE
 /* actual length of an initialized sockaddr_un */
 #define SUN_LEN(su) \
        (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
+#endif /* __BSD_VISIBLE */
+
 #endif /* _KERNEL */
 #endif /* !_SYS_UN_H_ */
Index: sys/netinet/in.h
===================================================================
RCS file: /cvs/src/sys/netinet/in.h,v
retrieving revision 1.85
diff -u -p -r1.85 in.h
--- sys/netinet/in.h    23 Sep 2010 04:45:15 -0000      1.85
+++ sys/netinet/in.h    21 Nov 2010 08:25:55 -0000
@@ -40,6 +40,16 @@
 #ifndef _NETINET_IN_H_
 #define        _NETINET_IN_H_
 
+#include <sys/cdefs.h>
+#include <sys/_types.h>
+#include <sys/endian.h>                /* XXX should be machine/endian.h? */
+
+#ifndef        _SA_FAMILY_T_DEFINED_
+#define        _SA_FAMILY_T_DEFINED_
+typedef        __sa_family_t   sa_family_t;    /* sockaddr address family type 
*/
+#endif
+
+
 /*
  * Protocols
  */
@@ -230,6 +240,12 @@ struct sockaddr_in {
 };
 
 /*
+ * Buffer lengths for strings containing printable IP addresses
+ */
+#define INET_ADDRSTRLEN                16
+
+#if __BSD_VISIBLE
+/*
  * Structure used to describe IP options.
  * Used to store options internally, to pass them to a process,
  * or to restore options retrieved earlier.
@@ -329,11 +345,6 @@ struct ip_mreq {
 #define IP_PORTRANGE_LOW       2       /* "low" - vouchsafe security */
 
 /*
- * Buffer lengths for strings containing printable IP addresses
- */
-#define INET_ADDRSTRLEN                16
-
-/*
  * Definitions for inet sysctl operations.
  *
  * Third level is protocol number.
@@ -726,15 +737,16 @@ struct ip_mreq {
        NULL, \
        &la_hold_total \
 }
+#endif /* __BSD_VISIBLE */
 
 /* INET6 stuff */
 #define __KAME_NETINET_IN_H_INCLUDED_
 #include <netinet6/in6.h>
 #undef __KAME_NETINET_IN_H_INCLUDED_
 
-#ifndef _KERNEL
 
-#include <sys/cdefs.h>
+#if __BSD_VISIBLE
+#ifndef _KERNEL
 
 __BEGIN_DECLS
 int       bindresvport(int, struct sockaddr_in *);
@@ -808,4 +820,5 @@ char          *inet_ntoa(struct in_addr);
 #define        sintosa(sin)    ((struct sockaddr *)(sin))
 #define        ifatoia(ifa)    ((struct in_ifaddr *)(ifa))
 #endif /* _KERNEL */
+#endif /* __BSD_VISIBLE */
 #endif /* _NETINET_IN_H_ */
Index: sys/netinet6/in6.h
===================================================================
RCS file: /cvs/src/sys/netinet6/in6.h,v
retrieving revision 1.52
diff -u -p -r1.52 in6.h
--- sys/netinet6/in6.h  23 Sep 2010 04:45:15 -0000      1.52
+++ sys/netinet6/in6.h  21 Nov 2010 08:25:59 -0000
@@ -791,6 +791,13 @@ void       in6_get_rand_ifid(struct ifnet *, 
 #define        ifatoia6(ifa)   ((struct in6_ifaddr *)(ifa))
 #endif /* _KERNEL */
 
+#if __BSD_VISIBLE
+
+#ifndef        _SOCKLEN_T_DEFINED_
+#define        _SOCKLEN_T_DEFINED_
+typedef        __socklen_t     socklen_t;
+#endif
+
 __BEGIN_DECLS
 struct cmsghdr;
 
@@ -833,5 +840,7 @@ extern int inet6_rth_reverse(const void 
 extern int inet6_rth_segments(const void *);
 extern struct in6_addr *inet6_rth_getaddr(const void *, int);
 __END_DECLS
+
+#endif /* __BSD_VISIBLE */
 
 #endif /* !_NETINET6_IN6_H_ */
Index: usr.sbin/sasyncd/sasyncd.h
===================================================================
RCS file: /cvs/src/usr.sbin/sasyncd/sasyncd.h,v
retrieving revision 1.15
diff -u -p -r1.15 sasyncd.h
--- usr.sbin/sasyncd/sasyncd.h  16 Jun 2010 17:39:05 -0000      1.15
+++ usr.sbin/sasyncd/sasyncd.h  21 Nov 2010 08:25:59 -0000
@@ -31,6 +31,7 @@
 
 
 #include <sys/queue.h>
+#include <sys/socket.h>
 
 enum RUNSTATE          { INIT = 0, SLAVE, MASTER, FAIL };
 #define CARPSTATES     { "INIT", "SLAVE", "MASTER", "FAIL" }
Index: usr.sbin/bind/lib/isc/unix/include/isc/privsep.h
===================================================================
RCS file: /cvs/src/usr.sbin/bind/lib/isc/unix/include/isc/privsep.h,v
retrieving revision 1.2
diff -u -p -r1.2 privsep.h
--- usr.sbin/bind/lib/isc/unix/include/isc/privsep.h    19 Nov 2004 15:37:37 
-0000      1.2
+++ usr.sbin/bind/lib/isc/unix/include/isc/privsep.h    21 Nov 2010 08:26:01 
-0000
@@ -17,6 +17,8 @@
 #ifndef _PRIVSEP_H_
 #define _PRIVSEP_H_
 
+#include <sys/socket.h>                /* for socklen_t */
+
 enum cmd_types {
        PRIV_BIND               /* bind to a privileged port */
 };
@@ -25,7 +27,6 @@ enum cmd_types {
 int    isc_priv_init(int);
 int    isc_drop_privs(const char *username, const char *dir);
 
-struct sockaddr;
 int    isc_priv_bind(int, struct sockaddr *, socklen_t);
 
 /* File descriptor send/recv */

Reply via email to