summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2012-09-15 00:47:10 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2012-09-15 00:47:10 +0000
commitb8005e84f7f252e93a42d945290512c185156084 (patch)
treed51500072a07f4778f4251b87b6a045c98725b87
parent96cb08314b92757feed28175fe6860f2d3854e6a (diff)
Improve POSIX/SUS compliance of <netdb.h>, <sys/socket.h>, and <sys/un.h>.
Much ports testing of various versions by naddy@ and jasper@ ok matthew@, miller@
-rw-r--r--include/arpa/inet.h7
-rw-r--r--include/netdb.h84
-rw-r--r--sys/netinet/in.h7
-rw-r--r--sys/netinet6/in6.h8
-rw-r--r--sys/sys/domain.h7
-rw-r--r--sys/sys/socket.h56
-rw-r--r--sys/sys/socketvar.h7
-rw-r--r--sys/sys/types.h4
-rw-r--r--sys/sys/un.h17
9 files changed, 134 insertions, 63 deletions
diff --git a/include/arpa/inet.h b/include/arpa/inet.h
index af04ccf700f..31b68cceee6 100644
--- a/include/arpa/inet.h
+++ b/include/arpa/inet.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: inet.h,v 1.13 2012/07/10 11:49:42 guenther Exp $ */
+/* $OpenBSD: inet.h,v 1.14 2012/09/15 00:47:08 guenther Exp $ */
/*
* ++Copyright++ 1983, 1993
@@ -65,6 +65,11 @@
#include <sys/types.h>
#include <machine/endian.h>
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
/*
* Buffer lengths for strings containing printable IP addresses
*/
diff --git a/include/netdb.h b/include/netdb.h
index 302cd9e1437..a5a1c6b4ba0 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: netdb.h,v 1.30 2012/01/17 02:36:55 deraadt Exp $ */
+/* $OpenBSD: netdb.h,v 1.31 2012/09/15 00:47:08 guenther Exp $ */
/*
* ++Copyright++ 1980, 1983, 1988, 1993
@@ -87,17 +87,24 @@
#ifndef _NETDB_H_
#define _NETDB_H_
-#include <sys/param.h>
#include <sys/cdefs.h>
+#if __BSD_VISIBLE
+#include <sys/param.h>
+#endif
+#include <netinet/in.h>
+
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
#define _PATH_HEQUIV "/etc/hosts.equiv"
#define _PATH_HOSTS "/etc/hosts"
#define _PATH_NETWORKS "/etc/networks"
#define _PATH_PROTOCOLS "/etc/protocols"
#define _PATH_SERVICES "/etc/services"
-extern int h_errno;
-
/*
* Structures returned by network data base library. All addresses are
* supplied in host order, and returned in network order (suitable for
@@ -136,6 +143,9 @@ struct protoent {
int p_proto; /* protocol # */
};
+#if __BSD_VISIBLE || __POSIX_VISIBLE < 200809
+extern int h_errno;
+
/*
* Error return codes from gethostbyname() and gethostbyaddr()
* (left in extern int h_errno).
@@ -148,6 +158,7 @@ struct protoent {
#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
#define NO_DATA 4 /* Valid name, no data record of requested type */
#define NO_ADDRESS NO_DATA /* no address */
+#endif /* __BSD_VISIBLE || __POSIX_VISIBLE < 200809 */
/* Values for getaddrinfo() and getnameinfo() */
#define AI_PASSIVE 1 /* socket address is intended for bind() */
@@ -165,7 +176,9 @@ struct protoent {
#define NI_NOFQDN 4 /* return a short name if in the local domain */
#define NI_NAMEREQD 8 /* fail if either host or service name is unknown */
#define NI_DGRAM 16 /* look up datagram service instead of stream */
+/* #define NI_NUMERICSCOPE 32 return the scope number, not the name */
+#if __BSD_VISIBLE
#define NI_MAXHOST MAXHOSTNAMELEN /* max host name returned by getnameinfo */
#define NI_MAXSERV 32 /* max serv. name length returned by getnameinfo */
@@ -173,6 +186,7 @@ struct protoent {
* Scope delimit character (KAME hack)
*/
#define SCOPE_DELIMITER '%'
+#endif
#define EAI_BADFLAGS -1 /* invalid value for ai_flags */
#define EAI_NONAME -2 /* name or service is not known */
@@ -199,7 +213,8 @@ struct addrinfo {
char *ai_canonname; /* canonical name for service location (iff req) */
struct addrinfo *ai_next; /* pointer to next in list */
};
-
+
+#if __BSD_VISIBLE
/*
* Flags for getrrsetbyname()
*/
@@ -235,7 +250,6 @@ struct rrsetinfo {
struct rdatainfo *rri_sigs; /* individual signatures */
};
-#if __BSD_VISIBLE
struct servent_data {
void *fp;
char **aliases;
@@ -257,16 +271,14 @@ __BEGIN_DECLS
void endhostent(void);
void endnetent(void);
void endprotoent(void);
-#if __BSD_VISIBLE
-void endprotoent_r(struct protoent_data *);
-#endif
void endservent(void);
-#if __BSD_VISIBLE
-void endservent_r(struct servent_data *);
-#endif
+#if __BSD_VISIBLE || __POSIX_VISIBLE < 200809
struct hostent *gethostbyaddr(const void *, socklen_t, int);
struct hostent *gethostbyname(const char *);
+#endif
+#if __BSD_VISIBLE
struct hostent *gethostbyname2(const char *, int);
+#endif
struct hostent *gethostent(void);
struct netent *getnetbyaddr(in_addr_t, int);
struct netent *getnetbyname(const char *);
@@ -274,34 +286,33 @@ struct netent *getnetent(void);
struct protoent *getprotobyname(const char *);
struct protoent *getprotobynumber(int);
struct protoent *getprotoent(void);
-#if __BSD_VISIBLE
-int getprotobyname_r(const char *, struct protoent *,
- struct protoent_data *);
-int getprotobynumber_r(int, struct protoent *,
- struct protoent_data *);
-int getprotoent_r(struct protoent *, struct protoent_data *);
-#endif
struct servent *getservbyname(const char *, const char *);
struct servent *getservbyport(int, const char *);
struct servent *getservent(void);
#if __BSD_VISIBLE
-int getservbyname_r(const char *, const char *, struct servent *,
- struct servent_data *);
-int getservbyport_r(int, const char *, struct servent *,
- struct servent_data *);
-int getservent_r(struct servent *, struct servent_data *);
-#endif
void herror(const char *);
const char *hstrerror(int);
+#endif
void sethostent(int);
/* void sethostfile(const char *); */
void setnetent(int);
void setprotoent(int);
-#if __BSD_VISIBLE
-void setprotoent_r(int, struct protoent_data *);
-#endif
void setservent(int);
+
#if __BSD_VISIBLE
+void endprotoent_r(struct protoent_data *);
+void endservent_r(struct servent_data *);
+int getprotobyname_r(const char *, struct protoent *,
+ struct protoent_data *);
+int getprotobynumber_r(int, struct protoent *,
+ struct protoent_data *);
+int getservbyname_r(const char *, const char *, struct servent *,
+ struct servent_data *);
+int getservbyport_r(int, const char *, struct servent *,
+ struct servent_data *);
+int getservent_r(struct servent *, struct servent_data *);
+int getprotoent_r(struct protoent *, struct protoent_data *);
+void setprotoent_r(int, struct protoent_data *);
void setservent_r(int, struct servent_data *);
#endif
@@ -311,22 +322,11 @@ void freeaddrinfo(struct addrinfo *);
int getnameinfo(const struct sockaddr *, socklen_t,
char *, size_t, char *, size_t, int);
const char *gai_strerror(int);
+
+#if __BSD_VISIBLE
int getrrsetbyname(const char *, unsigned int, unsigned int, unsigned int, struct rrsetinfo **);
void freerrset(struct rrsetinfo *);
+#endif
__END_DECLS
-/* This is nec'y to make this include file properly replace the sun version. */
-#ifdef sun
-#ifdef __GNU_LIBRARY__
-#include <rpc/netdb.h>
-#else
-struct rpcent {
- char *r_name; /* name of server for this rpc program */
- char **r_aliases; /* alias list */
- int r_number; /* rpc program number */
-};
-struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent();
-#endif /* __GNU_LIBRARY__ */
-#endif /* sun */
-
#endif /* !_NETDB_H_ */
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 56e3986185a..e503188ddaf 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.h,v 1.93 2012/07/16 18:05:36 markus Exp $ */
+/* $OpenBSD: in.h,v 1.94 2012/09/15 00:47:08 guenther Exp $ */
/* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */
/*
@@ -47,6 +47,11 @@
#include <machine/endian.h>
#endif
+#ifndef _SA_FAMILY_T_DEFINED_
+#define _SA_FAMILY_T_DEFINED_
+typedef __sa_family_t sa_family_t; /* sockaddr address family type */
+#endif
+
/*
* Protocols
*/
diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h
index 664bca96119..70a5f0858c6 100644
--- a/sys/netinet6/in6.h
+++ b/sys/netinet6/in6.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6.h,v 1.57 2012/07/10 11:49:42 guenther Exp $ */
+/* $OpenBSD: in6.h,v 1.58 2012/09/15 00:47:08 guenther Exp $ */
/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */
/*
@@ -769,6 +769,12 @@ int in6_mask2len(struct in6_addr *, u_char *);
#endif /* _KERNEL */
#if __BSD_VISIBLE
+
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
__BEGIN_DECLS
struct cmsghdr;
diff --git a/sys/sys/domain.h b/sys/sys/domain.h
index 2e6f01e8c33..7f80bb826a2 100644
--- a/sys/sys/domain.h
+++ b/sys/sys/domain.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: domain.h,v 1.9 2009/02/22 07:47:22 otto Exp $ */
+/* $OpenBSD: domain.h,v 1.10 2012/09/15 00:47:08 guenther Exp $ */
/* $NetBSD: domain.h,v 1.10 1996/02/09 18:25:07 christos Exp $ */
/*
@@ -36,6 +36,11 @@
* Structure per communications domain.
*/
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
/*
* Forward structure declarations for function prototypes [sic].
*/
diff --git a/sys/sys/socket.h b/sys/sys/socket.h
index 6145db35596..3f52d86e7f0 100644
--- a/sys/sys/socket.h
+++ b/sys/sys/socket.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: socket.h,v 1.81 2012/04/11 17:10:20 deraadt Exp $ */
+/* $OpenBSD: socket.h,v 1.82 2012/09/15 00:47:08 guenther Exp $ */
/* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */
/*
@@ -35,7 +35,34 @@
#ifndef _SYS_SOCKET_H_
#define _SYS_SOCKET_H_
+#include <sys/cdefs.h>
+
+#if __BSD_VISIBLE
+#include <sys/types.h> /* for off_t, uid_t, and gid_t */
+#else
#include <sys/_types.h>
+#endif
+
+#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.
@@ -184,6 +211,7 @@ struct sockaddr_storage {
unsigned char __ss_pad3[240]; /* pad to a total of 256 bytes */
};
+#ifdef _KERNEL
/*
* Structure used by kernel to pass protocol
* information in raw sockets.
@@ -192,6 +220,7 @@ struct sockproto {
unsigned short sp_family; /* address family */
unsigned short sp_protocol; /* protocol */
};
+#endif /* _KERNEL */
/*
* Protocol families, same as address families for now.
@@ -244,13 +273,14 @@ struct sockproto {
#define SHUT_RDWR 2
#if __BSD_VISIBLE
+#define SA_LEN(x) ((x)->sa_len)
+
/* Read using getsockopt() with SOL_SOCKET, SO_PEERCRED */
struct sockpeercred {
uid_t uid; /* effective user id */
gid_t gid; /* effective group id */
pid_t pid;
};
-#endif /* __BSD_VISIBLE */
/*
* Definitions for network related sysctl, CTL_NET.
@@ -363,6 +393,7 @@ struct sockpeercred {
{ 0, 0 }, \
{ "stats", CTLTYPE_STRUCT }, \
}
+#endif /* __BSD_VISIBLE */
/*
* Maximum queue length specifiable by listen(2).
@@ -414,11 +445,11 @@ struct cmsghdr {
/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
#define CMSG_NXTHDR(mhdr, cmsg) \
- (((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
+ (((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
_ALIGN(sizeof(struct cmsghdr)) > \
- ((caddr_t)(mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
+ ((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
(struct cmsghdr *)NULL : \
- (struct cmsghdr *)((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
+ (struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
/*
* RFC 2292 requires to check msg_controllen, in case that the kernel returns
@@ -444,25 +475,23 @@ struct cmsghdr {
#define SCM_RIGHTS 0x01 /* access rights (array of int) */
#define SCM_TIMESTAMP 0x04 /* timestamp (struct timeval) */
+#if __BSD_VISIBLE
/*
* 4.3 compat sockaddr, move to compat file later
+ * XXX Needed by protocols/talkd.h
*/
struct osockaddr {
unsigned short sa_family; /* address family */
char sa_data[14]; /* up to 14 bytes of direct address */
};
+#endif /* __BSD_VISIBLE */
-#define SA_LEN(x) ((x)->sa_len)
-
-#ifndef _KERNEL
-
-#include <sys/cdefs.h>
+#ifndef _KERNEL
__BEGIN_DECLS
int accept(int, struct sockaddr *, socklen_t *);
int bind(int, const struct sockaddr *, socklen_t);
int connect(int, const struct sockaddr *, socklen_t);
-int getpeereid(int, uid_t *, gid_t *);
int getpeername(int, struct sockaddr *, socklen_t *);
int getsockname(int, struct sockaddr *, socklen_t *);
int getsockopt(int, int, int, void *, socklen_t *);
@@ -478,8 +507,13 @@ int setsockopt(int, int, int, const void *, socklen_t);
int shutdown(int, int);
int socket(int, int, int);
int socketpair(int, int, int, int *);
+
+#if __BSD_VISIBLE
+int getpeereid(int, uid_t *, gid_t *);
int getrtable(void);
int setrtable(int);
+#endif /* __BSD_VISIBLE */
+
__END_DECLS
#else
diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h
index d5c34e06f59..732cead85c4 100644
--- a/sys/sys/socketvar.h
+++ b/sys/sys/socketvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: socketvar.h,v 1.52 2012/07/13 10:51:30 claudio Exp $ */
+/* $OpenBSD: socketvar.h,v 1.53 2012/09/15 00:47:08 guenther Exp $ */
/* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */
/*-
@@ -36,6 +36,11 @@
#include <sys/queue.h>
#include <sys/timeout.h>
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
TAILQ_HEAD(soqhead, socket);
/*
diff --git a/sys/sys/types.h b/sys/sys/types.h
index c2ebbb10898..fc7bc5370de 100644
--- a/sys/sys/types.h
+++ b/sys/sys/types.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: types.h,v 1.32 2011/03/19 18:26:06 deraadt Exp $ */
+/* $OpenBSD: types.h,v 1.33 2012/09/15 00:47:09 guenther Exp $ */
/* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */
/*-
@@ -159,8 +159,6 @@ typedef __fsfilcnt_t fsfilcnt_t; /* file system file count */
*/
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.
diff --git a/sys/sys/un.h b/sys/sys/un.h
index aea01eb8d64..26b726b6107 100644
--- a/sys/sys/un.h
+++ b/sys/sys/un.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: un.h,v 1.11 2011/07/05 23:06:43 claudio Exp $ */
+/* $OpenBSD: un.h,v 1.12 2012/09/15 00:47:09 guenther Exp $ */
/* $NetBSD: un.h,v 1.11 1996/02/04 02:12:47 christos Exp $ */
/*
@@ -35,12 +35,20 @@
#ifndef _SYS_UN_H_
#define _SYS_UN_H_
+#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
+
/*
* Definitions for UNIX IPC domain.
*/
struct sockaddr_un {
unsigned char sun_len; /* sockaddr len excluding NUL */
- unsigned char sun_family; /* AF_UNIX */
+ sa_family_t sun_family; /* AF_UNIX */
char sun_path[104]; /* path name (gag) */
};
@@ -65,8 +73,13 @@ int unp_internalize(struct mbuf *, struct proc *);
void unp_dispose(struct mbuf *);
#else /* !_KERNEL */
+#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_ */