* include/endian.h: Move definitions of __BIG_ENDIAN, __LITTLE_ENDIAN,

and __BYTE_ORDER into ...
	* include/bits/endian.h: New file.
	* include/arpa/nameser_compat.h: Include endian.h rather than defining
	BYTE_ORDER here.
	* include/asm/byteorder.h: Include bits/endian.h.  Drop definition of
	__LITTLE_ENDIAN.
	* include/netinet/ip.h: Include bits/endian.h.  Drop definitions of
	BIG_ENDIAN, LITTLE_ENDIAN, and BYTE_ORDER.  Use underscored variants
	of aforementioned constants.
	* include/netinet/tcp.h: Ditto.
	* include/sys/param.h: Drop disabled definitions of BIG_ENDIAN,
	LITTLE_ENDIAN, and BYTE_ORDER.

	* include/netinet/ip.h: Reformat.  Define setsockopt IP_TOS options
	matching recent RFCs.  Tweak comments.
This commit is contained in:
Corinna Vinschen 2011-02-11 12:42:30 +00:00
parent 96b998db51
commit 7be671075d
8 changed files with 199 additions and 180 deletions

View File

@ -1,3 +1,22 @@
2011-02-11 Corinna Vinschen <corinna@vinschen.de>
* include/endian.h: Move definitions of __BIG_ENDIAN, __LITTLE_ENDIAN,
and __BYTE_ORDER into ...
* include/bits/endian.h: New file.
* include/arpa/nameser_compat.h: Include endian.h rather than defining
BYTE_ORDER here.
* include/asm/byteorder.h: Include bits/endian.h. Drop definition of
__LITTLE_ENDIAN.
* include/netinet/ip.h: Include bits/endian.h. Drop definitions of
BIG_ENDIAN, LITTLE_ENDIAN, and BYTE_ORDER. Use underscored variants
of aforementioned constants.
* include/netinet/tcp.h: Ditto.
* include/sys/param.h: Drop disabled definitions of BIG_ENDIAN,
LITTLE_ENDIAN, and BYTE_ORDER.
* include/netinet/ip.h: Reformat. Define setsockopt IP_TOS options
matching recent RFCs. Tweak comments.
2011-02-10 Eric Blake <eblake@redhat.com> 2011-02-10 Eric Blake <eblake@redhat.com>
* errno.cc (includes): Avoid compilation failure if <string.h> * errno.cc (includes): Avoid compilation failure if <string.h>

View File

@ -40,50 +40,7 @@
#define __BIND 19950621 /* (DEAD) interface version stamp. */ #define __BIND 19950621 /* (DEAD) interface version stamp. */
#ifndef BYTE_ORDER #include <endian.h>
#if (BSD >= 199103)
# include <machine/endian.h>
#else
#ifdef linux
# include <endian.h>
#else
#define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
#define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
defined(__alpha__) || defined(__alpha) || \
(defined(__Lynx__) && defined(__x86__))
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
defined(apollo) || defined(__convex__) || defined(_CRAY) || \
defined(__hppa) || defined(__hp9000) || \
defined(__hp9000s300) || defined(__hp9000s700) || \
defined(__hp3000s900) || defined(MPE) || \
defined (BIT_ZERO_ON_LEFT) || defined(m68k) || \
(defined(__Lynx__) && \
(defined(__68k__) || defined(__sparc__) || defined(__powerpc__)))
#define BYTE_ORDER BIG_ENDIAN
#endif
#endif /* linux */
#endif /* BSD */
#endif /* BYTE_ORDER */
#if !defined(BYTE_ORDER) || \
(BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
BYTE_ORDER != PDP_ENDIAN)
/* you must determine what the correct bit order is for
* your compiler - the next line is an intentional error
* which will force your compiles to bomb until you fix
* the above macros.
*/
error "Undefined or invalid BYTE_ORDER";
#endif
/* /*
* Structure for query header. The order of the fields is machine- and * Structure for query header. The order of the fields is machine- and

View File

@ -1,6 +1,6 @@
/* asm/byteorder.h /* asm/byteorder.h
Copyright 1996, 1998, 2001, 2006, 2009 Red Hat, Inc. Copyright 1996, 1998, 2001, 2006, 2009, 2011 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -13,15 +13,12 @@ details. */
#include <_ansi.h> #include <_ansi.h>
#include <stdint.h> #include <stdint.h>
#include <bits/endian.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifndef __LITTLE_ENDIAN
#define __LITTLE_ENDIAN 1234
#endif
#ifndef __LITTLE_ENDIAN_BITFIELD #ifndef __LITTLE_ENDIAN_BITFIELD
#define __LITTLE_ENDIAN_BITFIELD #define __LITTLE_ENDIAN_BITFIELD
#endif #endif

View File

@ -0,0 +1,25 @@
/* bits/endian.h
Copyright 2011 Red Hat, Inc.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef _BITS_ENDIAN_H_
#define _BITS_ENDIAN_H_
#ifndef __BIG_ENDIAN
# define __BIG_ENDIAN 4321
#endif
#ifndef __LITTLE_ENDIAN
# define __LITTLE_ENDIAN 1234
#endif
#ifndef __BYTE_ORDER
# define __BYTE_ORDER __LITTLE_ENDIAN
#endif
#endif /* _BITS_ENDIAN_H_ */

View File

@ -1,6 +1,6 @@
/* endian.h /* endian.h
Copyright 2005, 2010 Red Hat, Inc. Copyright 2005, 2010, 2011 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -12,17 +12,7 @@ details. */
#define _ENDIAN_H_ #define _ENDIAN_H_
#include <sys/config.h> #include <sys/config.h>
#include <bits/endian.h>
#ifndef __BIG_ENDIAN
#define __BIG_ENDIAN 4321
#endif
#ifndef __LITTLE_ENDIAN
#define __LITTLE_ENDIAN 1234
#endif
#ifndef __BYTE_ORDER
# define __BYTE_ORDER __LITTLE_ENDIAN
#endif
/*#ifdef __USE_BSD*/ /*#ifdef __USE_BSD*/
# define LITTLE_ENDIAN __LITTLE_ENDIAN # define LITTLE_ENDIAN __LITTLE_ENDIAN

View File

@ -39,132 +39,183 @@
#include <netinet/in_systm.h> #include <netinet/in_systm.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <bits/endian.h>
/* Added by Wu Yongwei */
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234
#define BIG_ENDIAN 4321
#endif
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#endif
/* /*
* Definitions for internet protocol version 4. * Definitions for internet protocol version 4.
* Per RFC 791, September 1981. * Per RFC 791, September 1981.
*/ */
#define IPVERSION 4 #define IPVERSION 4
/* /*
* Structure of an internet header, naked of options. * Structure of an internet header, naked of options.
*/ */
struct ip { struct ip {
#ifdef _IP_VHL #ifdef _IP_VHL
u_char ip_vhl; /* version << 4 | header length >> 2 */ u_char ip_vhl; /* version << 4 | header length >> 2 */
#else #else
#if BYTE_ORDER == LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
u_int ip_hl:4, /* header length */ u_int ip_hl:4, /* header length */
ip_v:4; /* version */ ip_v:4; /* version */
#endif #endif
#if BYTE_ORDER == BIG_ENDIAN #if __BYTE_ORDER == __BIG_ENDIAN
u_int ip_v:4, /* version */ u_int ip_v:4, /* version */
ip_hl:4; /* header length */ ip_hl:4; /* header length */
#endif #endif
#endif /* not _IP_VHL */ #endif /* not _IP_VHL */
u_char ip_tos; /* type of service */ u_char ip_tos; /* type of service */
u_short ip_len; /* total length */ u_short ip_len; /* total length */
u_short ip_id; /* identification */ u_short ip_id; /* identification */
u_short ip_off; /* fragment offset field */ u_short ip_off; /* fragment offset field */
#define IP_RF 0x8000 /* reserved fragment flag */ #define IP_RF 0x8000 /* reserved fragment flag */
#define IP_DF 0x4000 /* dont fragment flag */ #define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */ #define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
u_char ip_ttl; /* time to live */ u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */ u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */ u_short ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */ struct in_addr ip_src,ip_dst; /* source and dest address */
}; };
#ifdef _IP_VHL #ifdef _IP_VHL
#define IP_MAKE_VHL(v, hl) ((v) << 4 | (hl)) #define IP_MAKE_VHL(v, hl) ((v) << 4 | (hl))
#define IP_VHL_HL(vhl) ((vhl) & 0x0f) #define IP_VHL_HL(vhl) ((vhl) & 0x0f)
#define IP_VHL_V(vhl) ((vhl) >> 4) #define IP_VHL_V(vhl) ((vhl) >> 4)
#define IP_VHL_BORING 0x45 #define IP_VHL_BORING 0x45
#endif #endif
#define IP_MAXPACKET 65535 /* maximum packet size */ #define IP_MAXPACKET 65535 /* maximum packet size */
/* /*
* Definitions for IP type of service (ip_tos) * Definitions for DiffServ Codepoints as per RFC2474
*/
#define IPTOS_DSCP_CS0 0x00
#define IPTOS_DSCP_CS1 0x20
#define IPTOS_DSCP_AF11 0x28
#define IPTOS_DSCP_AF12 0x30
#define IPTOS_DSCP_AF13 0x38
#define IPTOS_DSCP_CS2 0x40
#define IPTOS_DSCP_AF21 0x48
#define IPTOS_DSCP_AF22 0x50
#define IPTOS_DSCP_AF23 0x58
#define IPTOS_DSCP_CS3 0x60
#define IPTOS_DSCP_AF31 0x68
#define IPTOS_DSCP_AF32 0x70
#define IPTOS_DSCP_AF33 0x78
#define IPTOS_DSCP_CS4 0x80
#define IPTOS_DSCP_AF41 0x88
#define IPTOS_DSCP_AF42 0x90
#define IPTOS_DSCP_AF43 0x98
#define IPTOS_DSCP_CS5 0xa0
#define IPTOS_DSCP_EF 0xb8
#define IPTOS_DSCP_CS6 0xc0
#define IPTOS_DSCP_CS7 0xe0
/*
* Definitions for DiffServ Class Selector Codepoints as defined by Linux.
* Linux uses different names than OpenBSD, unfortunately.
*/
#define IPTOS_CLASS_CS0 0x00
#define IPTOS_CLASS_CS1 0x20
#define IPTOS_CLASS_CS2 0x40
#define IPTOS_CLASS_CS3 0x60
#define IPTOS_CLASS_CS4 0x80
#define IPTOS_CLASS_CS5 0xa0
#define IPTOS_CLASS_CS6 0xc0
#define IPTOS_CLASS_CS7 0xe0
#define IPTOS_CLASS_DEFAULT IPTOS_CLASS_CS0
/* Linux also defined masks and access macros. */
#define IPTOS_CLASS_MASK 0xe0
#define IPTOS_CLASS(cs) ((cs) & IPTOS_CLASS_MASK)
#define IPTOS_DSCP_MASK 0xfc
#define IPTOS_DSCP(cp) ((cp) & IPTOS_DSCP_MASK)
/*
* ECN (Explicit Congestion Notification) codepoints in RFC3168
* mapped to the lower 2 bits of the TOS field.
*/
#define IPTOS_ECN_NOTECT 0x00 /* not-ECT */
#define IPTOS_ECN_ECT1 0x01 /* ECN-capable transport (1) */
#define IPTOS_ECN_ECT0 0x02 /* ECN-capable transport (0) */
#define IPTOS_ECN_CE 0x03 /* congestion experienced */
#define IPTOS_ECN_MASK 0x03 /* ECN field mask */
/* Linux also defined an access macro.
* The name of IPTOS_ECN_NOTECT differs, too, unfortunately. */
#define IPTOS_ECN(cn) ((cn) & IPTOS_ECN_MASK)
#define IPTOS_ECN_NOT_ECT 0x00
/*
* Definitions for IP type of service per RFC1349 (ip_tos)
* DEPRECATED
*/ */
#ifndef IPTOS_LOWDELAY #ifndef IPTOS_LOWDELAY
#define IPTOS_LOWDELAY 0x10 #define IPTOS_LOWDELAY 0x10
#define IPTOS_THROUGHPUT 0x08 #define IPTOS_THROUGHPUT 0x08
#define IPTOS_RELIABILITY 0x04 #define IPTOS_RELIABILITY 0x04
#endif #endif
#define IPTOS_MINCOST 0x02 #define IPTOS_MINCOST 0x02
/* ECN bits proposed by Sally Floyd */ /* ECN RFC3168 obsoletes RFC2481, and these will be deprecated soon. */
#define IPTOS_CE 0x01 /* congestion experienced */ #define IPTOS_CE 0x01 /* congestion experienced */
#define IPTOS_ECT 0x02 /* ECN-capable transport */ #define IPTOS_ECT 0x02 /* ECN-capable transport */
/* /*
* Definitions for IP precedence (also in ip_tos) (hopefully unused) * Definitions for IP precedence per RFC1195 (also in ip_tos) (hopefully unused)
*/ */
#define IPTOS_PREC_NETCONTROL 0xe0 #define IPTOS_PREC_NETCONTROL 0xe0
#define IPTOS_PREC_INTERNETCONTROL 0xc0 #define IPTOS_PREC_INTERNETCONTROL 0xc0
#define IPTOS_PREC_CRITIC_ECP 0xa0 #define IPTOS_PREC_CRITIC_ECP 0xa0
#define IPTOS_PREC_FLASHOVERRIDE 0x80 #define IPTOS_PREC_FLASHOVERRIDE 0x80
#define IPTOS_PREC_FLASH 0x60 #define IPTOS_PREC_FLASH 0x60
#define IPTOS_PREC_IMMEDIATE 0x40 #define IPTOS_PREC_IMMEDIATE 0x40
#define IPTOS_PREC_PRIORITY 0x20 #define IPTOS_PREC_PRIORITY 0x20
#define IPTOS_PREC_ROUTINE 0x00 #define IPTOS_PREC_ROUTINE 0x00
/* /*
* Definitions for options. * Definitions for options.
*/ */
#define IPOPT_COPIED(o) ((o)&0x80) #define IPOPT_COPIED(o) ((o)&0x80)
#define IPOPT_CLASS(o) ((o)&0x60) #define IPOPT_CLASS(o) ((o)&0x60)
#define IPOPT_NUMBER(o) ((o)&0x1f) #define IPOPT_NUMBER(o) ((o)&0x1f)
#define IPOPT_CONTROL 0x00 #define IPOPT_CONTROL 0x00
#define IPOPT_RESERVED1 0x20 #define IPOPT_RESERVED1 0x20
#define IPOPT_DEBMEAS 0x40 #define IPOPT_DEBMEAS 0x40
#define IPOPT_RESERVED2 0x60 #define IPOPT_RESERVED2 0x60
#define IPOPT_EOL 0 /* end of option list */ #define IPOPT_EOL 0 /* end of option list */
#define IPOPT_NOP 1 /* no operation */ #define IPOPT_NOP 1 /* no operation */
#define IPOPT_RR 7 /* record packet route */ #define IPOPT_RR 7 /* record packet route */
#define IPOPT_TS 68 /* timestamp */ #define IPOPT_TS 68 /* timestamp */
#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
#define IPOPT_LSRR 131 /* loose source route */ #define IPOPT_LSRR 131 /* loose source route */
#define IPOPT_SATID 136 /* satnet id */ #define IPOPT_SATID 136 /* satnet id */
#define IPOPT_SSRR 137 /* strict source route */ #define IPOPT_SSRR 137 /* strict source route */
#define IPOPT_RA 148 /* router alert */ #define IPOPT_RA 148 /* router alert */
/* /*
* Offsets to fields in options other than EOL and NOP. * Offsets to fields in options other than EOL and NOP.
*/ */
#define IPOPT_OPTVAL 0 /* option ID */ #define IPOPT_OPTVAL 0 /* option ID */
#define IPOPT_OLEN 1 /* option length */ #define IPOPT_OLEN 1 /* option length */
#define IPOPT_OFFSET 2 /* offset within option */ #define IPOPT_OFFSET 2 /* offset within option */
#define IPOPT_MINOFF 4 /* min value of above */ #define IPOPT_MINOFF 4 /* min value of above */
/* /*
* Time stamp option structure. * Time stamp option structure.
*/ */
struct ip_timestamp { struct ip_timestamp {
u_char ipt_code; /* IPOPT_TS */ u_char ipt_code; /* IPOPT_TS */
u_char ipt_len; /* size of structure (variable) */ u_char ipt_len; /* size of structure (variable) */
u_char ipt_ptr; /* index of current entry */ u_char ipt_ptr; /* index of current entry */
#if BYTE_ORDER == LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
u_int ipt_flg:4, /* flags, see below */ u_int ipt_flg:4, /* flags, see below */
ipt_oflw:4; /* overflow counter */ ipt_oflw:4; /* overflow counter */
#endif #endif
#if BYTE_ORDER == BIG_ENDIAN #if __BYTE_ORDER == __BIG_ENDIAN
u_int ipt_oflw:4, /* overflow counter */ u_int ipt_oflw:4, /* overflow counter */
ipt_flg:4; /* flags, see below */ ipt_flg:4; /* flags, see below */
#endif #endif
union ipt_timestamp { union ipt_timestamp {
n_long ipt_time[1]; n_long ipt_time[1];
@ -176,27 +227,27 @@ struct ip_timestamp {
}; };
/* flag bits for ipt_flg */ /* flag bits for ipt_flg */
#define IPOPT_TS_TSONLY 0 /* timestamps only */ #define IPOPT_TS_TSONLY 0 /* timestamps only */
#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
#define IPOPT_TS_PRESPEC 3 /* specified modules only */ #define IPOPT_TS_PRESPEC 3 /* specified modules only */
/* bits for security (not byte swapped) */ /* bits for security (not byte swapped) */
#define IPOPT_SECUR_UNCLASS 0x0000 #define IPOPT_SECUR_UNCLASS 0x0000
#define IPOPT_SECUR_CONFID 0xf135 #define IPOPT_SECUR_CONFID 0xf135
#define IPOPT_SECUR_EFTO 0x789a #define IPOPT_SECUR_EFTO 0x789a
#define IPOPT_SECUR_MMMM 0xbc4d #define IPOPT_SECUR_MMMM 0xbc4d
#define IPOPT_SECUR_RESTR 0xaf13 #define IPOPT_SECUR_RESTR 0xaf13
#define IPOPT_SECUR_SECRET 0xd788 #define IPOPT_SECUR_SECRET 0xd788
#define IPOPT_SECUR_TOPSECRET 0x6bc5 #define IPOPT_SECUR_TOPSECRET 0x6bc5
/* /*
* Internet implementation parameters. * Internet implementation parameters.
*/ */
#define MAXTTL 255 /* maximum time to live (seconds) */ #define MAXTTL 255 /* maximum time to live (seconds) */
#define IPDEFTTL 64 /* default ttl, from RFC 1340 */ #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
#define IPFRAGTTL 60 /* time to live for frags, slowhz */ #define IPFRAGTTL 60 /* time to live for frags, slowhz */
#define IPTTLDEC 1 /* subtracted when forwarding */ #define IPTTLDEC 1 /* subtracted when forwarding */
#define IP_MSS 576 /* default maximum segment size */ #define IP_MSS 576 /* default maximum segment size */
#endif #endif

View File

@ -37,14 +37,7 @@
#ifndef _NETINET_TCP_H #ifndef _NETINET_TCP_H
#define _NETINET_TCP_H #define _NETINET_TCP_H
/* Added by Wu Yongwei */ #include <bits/endian.h>
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234
#define BIG_ENDIAN 4321
#endif
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#endif
typedef u_int32_t tcp_seq; typedef u_int32_t tcp_seq;
typedef u_int32_t tcp_cc; /* connection count per rfc1644 */ typedef u_int32_t tcp_cc; /* connection count per rfc1644 */
@ -61,11 +54,11 @@ struct tcphdr {
u_short th_dport; /* destination port */ u_short th_dport; /* destination port */
tcp_seq th_seq; /* sequence number */ tcp_seq th_seq; /* sequence number */
tcp_seq th_ack; /* acknowledgement number */ tcp_seq th_ack; /* acknowledgement number */
#if BYTE_ORDER == LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
u_int th_x2:4, /* (unused) */ u_int th_x2:4, /* (unused) */
th_off:4; /* data offset */ th_off:4; /* data offset */
#endif #endif
#if BYTE_ORDER == BIG_ENDIAN #if __BYTE_ORDER == __BIG_ENDIAN
u_int th_off:4, /* data offset */ u_int th_off:4, /* data offset */
th_x2:4; /* (unused) */ th_x2:4; /* (unused) */
#endif #endif

View File

@ -1,6 +1,6 @@
/* sys/param.h /* sys/param.h
Copyright 2001, 2003, 2007 Red Hat, Inc. Copyright 2001, 2003, 2007,2 2011 Red Hat, Inc.
This software is a copyrighted work licensed under the terms of the This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for Cygwin license. Please consult the file "CYGWIN_LICENSE" for
@ -37,19 +37,6 @@
BSD variant of this constant. */ BSD variant of this constant. */
#define DEV_BSIZE 1024 #define DEV_BSIZE 1024
#if 0 /* defined in endian.h */
/* Some autoconf'd packages check for endianness. When cross-building we
can't run programs on the target. Fortunately, autoconf supports the
definition of byte order in sys/param.h (that's us!).
The values here are the same as used in gdb/defs.h (are the more
appropriate values?). */
#define BIG_ENDIAN 4321
#define LITTLE_ENDIAN 1234
/* All known win32 systems are little endian. */
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#ifndef NULL #ifndef NULL
#define NULL 0L #define NULL 0L
#endif #endif