o Remove some GCCisms in src/powerpc/include/endian.h.
o Unify <machine/endian.h>'s across all architectures. o Make bswapXX() functions use a different spelling of u_int16_t and friends to reduce namespace pollution. The bswapXX() functions don't actually exist, but we'll probably import these at some point. Atleast one driver (if_de) depends on bswapXX() for big endian cases. o Deprecate byteorder(3) prototypes from <sys/types.h>, these are now prototyped indirectly in <arpa/inet.h>. o Deprecate in_addr_t and in_port_t typedefs in <sys/types.h>, these are now typedef'd in <arpa/inet.h>. o Change byteorder(3) prototypes to use standards compliant uint32_t (spelled __uint32_t to reduce namespace pollution). o Document new preferred headers and standards compliance. Discussed with: bde PR: 29946 Reviewed by: bmilekic
This commit is contained in:
parent
e7e2b80184
commit
03516cfeb0
@ -44,15 +44,15 @@
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <sys/param.h>
|
||||
.Ft u_long
|
||||
.Fn htonl "u_long hostlong"
|
||||
.Ft u_short
|
||||
.Fn htons "u_short hostshort"
|
||||
.Ft u_long
|
||||
.Fn ntohl "u_long netlong"
|
||||
.Ft u_short
|
||||
.Fn ntohs "u_short netshort"
|
||||
.Fd #include <arpa/inet.h>
|
||||
.Ft uint32_t
|
||||
.Fn htonl "uint32_t hostlong"
|
||||
.Ft uint16_t
|
||||
.Fn htons "uint16_t hostshort"
|
||||
.Ft uint32_t
|
||||
.Fn ntohl "uint32_t netlong"
|
||||
.Ft uint16_t
|
||||
.Fn ntohs "uint16_t netshort"
|
||||
.Sh DESCRIPTION
|
||||
These routines convert 16 and 32 bit quantities between network
|
||||
byte order and host byte order.
|
||||
@ -67,6 +67,11 @@ and
|
||||
.Sh SEE ALSO
|
||||
.Xr gethostbyname 3 ,
|
||||
.Xr getservent 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm byteorder
|
||||
functions are expected to conform with IEEE Std POSIX.1-200x
|
||||
.Pq Dq POSIX.1 .
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm byteorder
|
||||
|
@ -49,6 +49,8 @@
|
||||
*/
|
||||
#define _BSD_CLOCK_T_ int /* clock() */
|
||||
#define _BSD_CLOCKID_T_ int /* clockid_t */
|
||||
#define _BSD_IN_ADDR_T_ __uint32_t /* inet(3) functions */
|
||||
#define _BSD_IN_PORT_T_ __uint16_t
|
||||
#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
|
||||
#define _BSD_PTRDIFF_T_ long /* ptr1 - ptr2 */
|
||||
#define _BSD_RUNE_T_ _BSD_CT_RUNE_T_ /* rune_t (see below) */
|
||||
|
@ -56,17 +56,19 @@
|
||||
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
|
||||
#ifndef _KERNEL
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <machine/ansi.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__uint32_t htonl __P((__uint32_t));
|
||||
__uint16_t htons __P((__uint16_t));
|
||||
__uint32_t ntohl __P((__uint32_t));
|
||||
__uint16_t ntohs __P((__uint16_t));
|
||||
__uint16_t bswap16 __P((__uint16_t));
|
||||
__uint32_t bswap32 __P((__uint32_t));
|
||||
__uint64_t bswap64 __P((__uint64_t));
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
@ -85,10 +87,10 @@ __END_DECLS
|
||||
|
||||
#else
|
||||
|
||||
#define NTOHL(x) (x) = ntohl((in_addr_t)x)
|
||||
#define NTOHS(x) (x) = ntohs((in_port_t)x)
|
||||
#define HTONL(x) (x) = htonl((in_addr_t)x)
|
||||
#define HTONS(x) (x) = htons((in_port_t)x)
|
||||
#define NTOHL(x) (x) = ntohl((__uint32_t)x)
|
||||
#define NTOHS(x) (x) = ntohs((__uint16_t)x)
|
||||
#define HTONL(x) (x) = htonl((__uint32_t)x)
|
||||
#define HTONS(x) (x) = htons((__uint16_t)x)
|
||||
#endif
|
||||
#endif /* !_POSIX_SOURCE */
|
||||
#endif /* !_ENDIAN_H_ */
|
||||
|
@ -49,6 +49,8 @@
|
||||
*/
|
||||
#define _BSD_CLOCK_T_ int /* clock() */
|
||||
#define _BSD_CLOCKID_T_ int /* clockid_t */
|
||||
#define _BSD_IN_ADDR_T_ __uint32_t /* inet(3) functions */
|
||||
#define _BSD_IN_PORT_T_ __uint16_t
|
||||
#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
|
||||
#define _BSD_PTRDIFF_T_ int /* ptr1 - ptr2 */
|
||||
#define _BSD_RUNE_T_ _BSD_CT_RUNE_T_ /* rune_t (see below) */
|
||||
|
@ -48,6 +48,8 @@
|
||||
*/
|
||||
#define _BSD_CLOCK_T_ unsigned long /* clock()... */
|
||||
#define _BSD_CLOCKID_T_ int /* clock_gettime()... */
|
||||
#define _BSD_IN_ADDR_T_ __uint32_t /* inet(3) functions */
|
||||
#define _BSD_IN_PORT_T_ __uint16_t
|
||||
#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
|
||||
#define _BSD_PTRDIFF_T_ int /* ptr1 - ptr2 */
|
||||
#define _BSD_RUNE_T_ _BSD_CT_RUNE_T_ /* rune_t (see below) */
|
||||
|
@ -58,26 +58,27 @@
|
||||
#ifndef _KERNEL
|
||||
#include <sys/cdefs.h>
|
||||
#endif
|
||||
#include <machine/ansi.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
unsigned long htonl(unsigned long);
|
||||
unsigned short htons(unsigned short);
|
||||
unsigned long ntohl(unsigned long);
|
||||
unsigned short ntohs(unsigned short);
|
||||
__uint32_t htonl(__uint32_t);
|
||||
__uint16_t htons(__uint16_t);
|
||||
__uint32_t ntohl(__uint32_t);
|
||||
__uint16_t ntohs(__uint16_t);
|
||||
__END_DECLS
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
static __inline unsigned long
|
||||
__uint16_swap_uint32(unsigned long __x)
|
||||
static __inline __uint32_t
|
||||
__uint16_swap_uint32(__uint32_t __x)
|
||||
{
|
||||
__asm ("rorl $16, %1" : "=r" (__x) : "0" (__x));
|
||||
|
||||
return __x;
|
||||
}
|
||||
|
||||
static __inline unsigned long
|
||||
__uint8_swap_uint32(unsigned long __x)
|
||||
static __inline __uint32_t
|
||||
__uint8_swap_uint32(__uint32_t __x)
|
||||
{
|
||||
#if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU)
|
||||
__asm ("bswap %0" : "=r" (__x) : "0" (__x));
|
||||
@ -88,8 +89,8 @@ __uint8_swap_uint32(unsigned long __x)
|
||||
return __x;
|
||||
}
|
||||
|
||||
static __inline unsigned short
|
||||
__uint8_swap_uint16(unsigned short __x)
|
||||
static __inline __uint16_t
|
||||
__uint8_swap_uint16(__uint16_t __x)
|
||||
{
|
||||
__asm ("xchgb %h1, %b1" : "=q" (__x) : "0" (__x));
|
||||
|
||||
|
@ -49,6 +49,8 @@
|
||||
*/
|
||||
#define _BSD_CLOCK_T_ int /* clock() */
|
||||
#define _BSD_CLOCKID_T_ int /* clockid_t */
|
||||
#define _BSD_IN_ADDR_T_ __uint32_t /* inet(3) functions */
|
||||
#define _BSD_IN_PORT_T_ __uint16_t
|
||||
#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
|
||||
#define _BSD_PTRDIFF_T_ long /* ptr1 - ptr2 */
|
||||
#define _BSD_RUNE_T_ _BSD_CT_RUNE_T_ /* rune_t (see below) */
|
||||
|
@ -56,17 +56,19 @@
|
||||
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
|
||||
#ifndef _KERNEL
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <machine/ansi.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__uint32_t htonl __P((__uint32_t));
|
||||
__uint16_t htons __P((__uint16_t));
|
||||
__uint32_t ntohl __P((__uint32_t));
|
||||
__uint16_t ntohs __P((__uint16_t));
|
||||
__uint16_t bswap16 __P((__uint16_t));
|
||||
__uint32_t bswap32 __P((__uint32_t));
|
||||
__uint64_t bswap64 __P((__uint64_t));
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
@ -85,10 +87,10 @@ __END_DECLS
|
||||
|
||||
#else
|
||||
|
||||
#define NTOHL(x) (x) = ntohl((in_addr_t)x)
|
||||
#define NTOHS(x) (x) = ntohs((in_port_t)x)
|
||||
#define HTONL(x) (x) = htonl((in_addr_t)x)
|
||||
#define HTONS(x) (x) = htons((in_port_t)x)
|
||||
#define NTOHL(x) (x) = ntohl((__uint32_t)x)
|
||||
#define NTOHS(x) (x) = ntohs((__uint16_t)x)
|
||||
#define HTONL(x) (x) = htonl((__uint32_t)x)
|
||||
#define HTONS(x) (x) = htons((__uint16_t)x)
|
||||
#endif
|
||||
#endif /* !_POSIX_SOURCE */
|
||||
#endif /* !_ENDIAN_H_ */
|
||||
|
@ -48,6 +48,8 @@
|
||||
*/
|
||||
#define _BSD_CLOCK_T_ int /* clock() */
|
||||
#define _BSD_CLOCKID_T_ int /* clockid_t */
|
||||
#define _BSD_IN_ADDR_T_ __uint32_t /* inet(3) functions */
|
||||
#define _BSD_IN_PORT_T_ __uint16_t
|
||||
#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
|
||||
#define _BSD_PTRDIFF_T_ int /* ptr1 - ptr2 */
|
||||
#define _BSD_RUNE_T_ _BSD_CT_RUNE_T_ /* rune_t (see below) */
|
||||
|
@ -55,17 +55,19 @@
|
||||
|
||||
#define BYTE_ORDER BIG_ENDIAN
|
||||
|
||||
#ifndef _KERNEL
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <machine/ansi.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
in_addr_t htonl __P((in_addr_t)) __attribute__((__const__));
|
||||
in_port_t htons __P((in_port_t)) __attribute__((__const__));
|
||||
in_addr_t ntohl __P((in_addr_t)) __attribute__((__const__));
|
||||
in_port_t ntohs __P((in_port_t)) __attribute__((__const__));
|
||||
u_int16_t bswap16 __P((u_int16_t)) __attribute__((__const__));
|
||||
u_int32_t bswap32 __P((u_int32_t)) __attribute__((__const__));
|
||||
u_int64_t bswap64 __P((u_int64_t)) __attribute__((__const__));
|
||||
__uint32_t htonl __P((__uint32_t));
|
||||
__uint16_t htons __P((__uint16_t));
|
||||
__uint32_t ntohl __P((__uint32_t));
|
||||
__uint16_t ntohs __P((__uint16_t));
|
||||
__uint16_t bswap16 __P((__uint16_t));
|
||||
__uint32_t bswap32 __P((__uint32_t));
|
||||
__uint64_t bswap64 __P((__uint64_t));
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
@ -84,10 +86,10 @@ __END_DECLS
|
||||
|
||||
#else
|
||||
|
||||
#define NTOHL(x) (x) = ntohl((in_addr_t)(x))
|
||||
#define NTOHS(x) (x) = ntohs((in_port_t)(x))
|
||||
#define HTONL(x) (x) = htonl((in_addr_t)(x))
|
||||
#define HTONS(x) (x) = htons((in_port_t)(x))
|
||||
#define NTOHL(x) (x) = ntohl((__uint32_t)(x))
|
||||
#define NTOHS(x) (x) = ntohs((__uint16_t)(x))
|
||||
#define HTONL(x) (x) = htonl((__uint32_t)(x))
|
||||
#define HTONS(x) (x) = htons((__uint16_t)(x))
|
||||
#endif
|
||||
|
||||
#endif /* !_POSIX_SOURCE */
|
||||
|
@ -49,6 +49,8 @@
|
||||
*/
|
||||
#define _BSD_CLOCK_T_ int /* clock() */
|
||||
#define _BSD_CLOCKID_T_ int /* clock_gettime()... */
|
||||
#define _BSD_IN_ADDR_T_ __uint32_t /* inet(3) functions */
|
||||
#define _BSD_IN_PORT_T_ __uint16_t
|
||||
#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
|
||||
#define _BSD_PTRDIFF_T_ long /* ptr1 - ptr2 */
|
||||
#define _BSD_RUNE_T_ _BSD_CT_RUNE_T_ /* rune_t (see below) */
|
||||
|
@ -47,17 +47,19 @@
|
||||
|
||||
#define BYTE_ORDER BIG_ENDIAN
|
||||
|
||||
#ifndef _KERNEL
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <machine/ansi.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__uint32_t htonl __P((__uint32_t));
|
||||
__uint16_t htons __P((__uint16_t));
|
||||
__uint32_t ntohl __P((__uint32_t));
|
||||
__uint16_t ntohs __P((__uint16_t));
|
||||
__uint16_t bswap16 __P((__uint16_t));
|
||||
__uint32_t bswap32 __P((__uint32_t));
|
||||
__uint64_t bswap64 __P((__uint64_t));
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
|
@ -73,8 +73,6 @@ typedef int32_t daddr_t; /* disk address */
|
||||
typedef u_int32_t u_daddr_t; /* unsigned disk address */
|
||||
typedef u_int32_t fixpt_t; /* fixed point number */
|
||||
typedef u_int32_t gid_t; /* group id */
|
||||
typedef u_int32_t in_addr_t; /* base type for internet address */
|
||||
typedef u_int16_t in_port_t;
|
||||
typedef u_int32_t ino_t; /* inode number */
|
||||
typedef long key_t; /* IPC key (for Sys V IPC) */
|
||||
typedef u_int16_t mode_t; /* permissions */
|
||||
@ -124,6 +122,10 @@ typedef u_int32_t dev_t; /* device number */
|
||||
|
||||
#endif /* !_KERNEL */
|
||||
|
||||
/*
|
||||
* XXX: Deprecated;
|
||||
* byteorder(3) functions now defined in <apra/inet.h>.
|
||||
*/
|
||||
#include <machine/endian.h>
|
||||
|
||||
#ifdef _BSD_CLOCK_T_
|
||||
@ -136,6 +138,18 @@ typedef _BSD_CLOCKID_T_ clockid_t;
|
||||
#undef _BSD_CLOCKID_T_
|
||||
#endif
|
||||
|
||||
/* XXX: Deprecated; now defined in <apra/inet.h>. */
|
||||
#ifdef _BSD_IN_ADDR_T_
|
||||
typedef _BSD_IN_ADDR_T_ in_addr_t;
|
||||
#undef _BSD_IN_ADDR_T_
|
||||
#endif
|
||||
|
||||
/* XXX: Deprecated; now defined in <apra/inet.h>. */
|
||||
#ifdef _BSD_IN_PORT_T_
|
||||
typedef _BSD_IN_PORT_T_ in_port_t;
|
||||
#undef _BSD_IN_PORT_T_
|
||||
#endif
|
||||
|
||||
#ifdef _BSD_SIZE_T_
|
||||
typedef _BSD_SIZE_T_ size_t;
|
||||
#undef _BSD_SIZE_T_
|
||||
|
Loading…
x
Reference in New Issue
Block a user