Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Apr 2002 01:18:22 -0400
From:      Mike Barcroft <mike@FreeBSD.org>
To:        standards@FreeBSD.org
Subject:   <netinet/in.h> changes for review
Message-ID:  <20020420011822.L29857@espresso.q9media.com>

next in thread | raw e-mail | index | archive | help

--VrqPEDrXMn8OVzN4
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


The attached patch brings <netinet/in.h> up to conformance with SUSv2,
and almost with POSIX.1-2001 (<netinet6/in6.h> still has too much
pollution).  Comments appreciated.

Best regards,
Mike Barcroft

--VrqPEDrXMn8OVzN4
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="in.diff"

in.diff

Rearrange <netinet/in.h> so that it is easier to conditionalize
sections for various standards.  Use standards conforming spelling for
types in the sockaddr_in structure.

Index: in.h
===================================================================
RCS file: /work/repo/src/sys/netinet/in.h,v
retrieving revision 1.67
diff -u -r1.67 in.h
--- in.h	20 Apr 2002 02:24:35 -0000	1.67
+++ in.h	20 Apr 2002 05:08:18 -0000
@@ -37,8 +37,93 @@
 #ifndef _NETINET_IN_H_
 #define _NETINET_IN_H_
 
+#include <machine/endian.h>
 #include <sys/_types.h>
 
+/* Protocols common to RFC 1700, POSIX, and X/Open. */
+#define	IPPROTO_IP		0		/* dummy for IP */
+#define	IPPROTO_ICMP		1		/* control message protocol */
+#define	IPPROTO_TCP		6		/* tcp */
+#define	IPPROTO_UDP		17		/* user datagram protocol */
+
+#define	INADDR_ANY		(u_int32_t)0x00000000
+#define	INADDR_BROADCAST	(u_int32_t)0xffffffff	/* must be masked */
+
+#ifndef _UINT8_T_DECLARED
+typedef	__uint8_t		uint8_t;
+#define	_UINT8_T_DECLARED
+#endif
+
+#ifndef _UINT16_T_DECLARED
+typedef	__uint16_t		uint16_t;
+#define	_UINT16_T_DECLARED
+#endif
+
+#ifndef _UINT32_T_DECLARED
+typedef	__uint32_t		uint32_t;
+#define	_UINT32_T_DECLARED
+#endif
+
+#ifndef _IN_ADDR_T_DECLARED
+typedef	uint32_t		in_addr_t;
+#define	_IN_ADDR_T_DECLARED
+#endif
+
+#ifndef _IN_PORT_T_DECLARED
+typedef	uint16_t		in_port_t;
+#define	_IN_PORT_T_DECLARED
+#endif
+
+#ifdef _BSD_SA_FAMILY_T_
+typedef	_BSD_SA_FAMILY_T_	sa_family_t;
+#undef _BSD_SA_FAMILY_T_ 
+#endif
+
+/* Internet address (a structure for historical reasons). */
+#ifndef	_STRUCT_IN_ADDR_DECLARED
+struct in_addr {
+	in_addr_t s_addr;
+};
+#define	_STRUCT_IN_ADDR_DECLARED
+#endif
+
+/* Socket address, internet style. */
+struct sockaddr_in {
+	uint8_t	sin_len;
+	sa_family_t	sin_family;
+	in_port_t	sin_port;
+	struct	in_addr sin_addr;
+	char	sin_zero[8];
+};
+
+#ifndef _KERNEL
+
+#ifndef _BYTEORDER_PROTOTYPED
+#define	_BYTEORDER_PROTOTYPED
+__BEGIN_DECLS
+uint32_t	htonl(uint32_t);
+uint16_t	htons(uint16_t);
+uint32_t	ntohl(uint32_t);
+uint16_t	ntohs(uint16_t);
+__END_DECLS
+#endif
+
+#ifndef _BYTEORDER_FUNC_DEFINED
+#define	_BYTEORDER_FUNC_DEFINED
+#define	htonl(x)	__htonl(x)
+#define	htons(x)	__htons(x)
+#define	ntohl(x)	__ntohl(x)
+#define	ntohs(x)	__ntohs(x)
+#endif
+
+#endif /* !_KERNEL */
+
+#if __POSIX_VISIBLE >= 200112
+#define	IPPROTO_RAW		255		/* raw IP packet */
+#define	INET_ADDRSTRLEN		16
+#endif
+
+#if __BSD_VISIBLE
 /*
  * Constants and structures defined by the internet system,
  * Per RFC 790, September 1981, and numerous additions.
@@ -47,14 +132,11 @@
 /*
  * Protocols (RFC 1700)
  */
-#define	IPPROTO_IP		0		/* dummy for IP */
 #define	IPPROTO_HOPOPTS		0		/* IP6 hop-by-hop options */
-#define	IPPROTO_ICMP		1		/* control message protocol */
 #define	IPPROTO_IGMP		2		/* group mgmt protocol */
 #define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
 #define IPPROTO_IPV4		4 		/* IPv4 encapsulation */
 #define IPPROTO_IPIP		IPPROTO_IPV4	/* for compatibility */
-#define	IPPROTO_TCP		6		/* tcp */
 #define	IPPROTO_ST		7		/* Stream protocol II */
 #define	IPPROTO_EGP		8		/* exterior gateway protocol */
 #define	IPPROTO_PIGP		9		/* private interior gateway */
@@ -65,7 +147,6 @@
 #define	IPPROTO_EMCON		14		/* EMCON */
 #define	IPPROTO_XNET		15		/* Cross Net Debugger */
 #define	IPPROTO_CHAOS		16		/* Chaos*/
-#define	IPPROTO_UDP		17		/* user datagram protocol */
 #define	IPPROTO_MUX		18		/* Multiplexing */
 #define	IPPROTO_MEAS		19		/* DCN Measurement Subsystems */
 #define	IPPROTO_HMP		20		/* Host Monitoring */
@@ -156,7 +237,6 @@
 /* 255: Reserved */
 /* BSD Private, local use, namespace incursion */
 #define	IPPROTO_DIVERT		254		/* divert pseudo-protocol */
-#define	IPPROTO_RAW		255		/* raw IP packet */
 #define	IPPROTO_MAX		256
 
 /* last return value of *_input(), meaning "all job for this pkt is done".  */
@@ -302,9 +382,7 @@
 #define	IN_EXPERIMENTAL(i)	(((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
 #define	IN_BADCLASS(i)		(((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
 
-#define	INADDR_ANY		(u_int32_t)0x00000000
 #define	INADDR_LOOPBACK		(u_int32_t)0x7f000001
-#define	INADDR_BROADCAST	(u_int32_t)0xffffffff	/* must be masked */
 #ifndef _KERNEL
 #define	INADDR_NONE		0xffffffff		/* -1 return */
 #endif
@@ -317,19 +395,6 @@
 #define	IN_LOOPBACKNET		127			/* official! */
 
 /*
- * Socket address, internet style.
- */
-struct sockaddr_in {
-	u_char	sin_len;
-	u_char	sin_family;
-	u_short	sin_port;
-	struct	in_addr sin_addr;
-	char	sin_zero[8];
-};
-
-#define	INET_ADDRSTRLEN                 16
-
-/*
  * Options for use with [gs]etsockopt at the IP level.
  * First word of comment is data type; bool is stored in int.
  */
@@ -496,17 +561,12 @@
 	{ "fastforwarding", CTLTYPE_INT }, \
 }
 
-#ifdef _KERNEL
-struct ifnet; struct mbuf;	/* forward declarations for Standard C */
-#endif
-
-/* INET6 stuff */
-#define	__KAME_NETINET_IN_H_INCLUDED_
-#include <netinet6/in6.h>
-#undef __KAME_NETINET_IN_H_INCLUDED_
+#endif /* __BSD_VISIBLE */
 
 #ifdef _KERNEL
 
+struct ifnet; struct mbuf;	/* forward declarations for Standard C */
+
 int	 in_broadcast(struct in_addr, struct ifnet *);
 int	 in_canforward(struct in_addr);
 int	 in_localaddr(struct in_addr);
@@ -517,26 +577,13 @@
 #define sintosa(sin)	((struct sockaddr *)(sin))
 #define ifatoia(ifa)	((struct in_ifaddr *)(ifa))
 
-#else /* !_KERNEL */
-
-#ifndef _BYTEORDER_PROTOTYPED
-#define	_BYTEORDER_PROTOTYPED
-__BEGIN_DECLS
-uint32_t	htonl(uint32_t);
-uint16_t	htons(uint16_t);
-uint32_t	ntohl(uint32_t);
-uint16_t	ntohs(uint16_t);
-__END_DECLS
-#endif
-
-#ifndef _BYTEORDER_FUNC_DEFINED
-#define	_BYTEORDER_FUNC_DEFINED
-#define	htonl(x)	__htonl(x)
-#define	htons(x)	__htons(x)
-#define	ntohl(x)	__ntohl(x)
-#define	ntohs(x)	__ntohs(x)
-#endif
-
 #endif /* _KERNEL */
 
+/* INET6 stuff */
+#if __POSIX_VISIBLE >= 200112
+#define	__KAME_NETINET_IN_H_INCLUDED_
+#include <netinet6/in6.h>
+#undef __KAME_NETINET_IN_H_INCLUDED_
 #endif
+
+#endif /* !_NETINET_IN_H_*/

--VrqPEDrXMn8OVzN4--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020420011822.L29857>