about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-02-05 16:55:30 -0500
committerRich Felker <dalias@aerifal.cx>2014-02-05 16:55:30 -0500
commitfdaaa68d827430caa930e4c966fa8d8a9f8f64c4 (patch)
tree204e1429ecf0dfe0d88cc99b614f4baf564106ad
parentad87c2eecf70c6f2852a4908b04a6329cbebaf7d (diff)
downloadmusl-fdaaa68d827430caa930e4c966fa8d8a9f8f64c4.tar.gz
musl-fdaaa68d827430caa930e4c966fa8d8a9f8f64c4.tar.xz
musl-fdaaa68d827430caa930e4c966fa8d8a9f8f64c4.zip
add support for BSD struct tcphdr in netinet/tcp.h
there are two versions of this structure: the BSD version and the GNU
version. previously only the GNU version was supported. the only way
to support both simultaneously is with an anonymous union, which was a
nonstandard extension prior to C11, so some effort is made to avoid
breakage with compilers which do not support anonymous unions.

this commit is based on a patch by Timo Teräs, but with some changes.
in particular, the GNU version of the structure is not exposed unless
_GNU_SOURCE is defined; this both avoids namespace pollution and
dependency on anonymous unions in the default feature profile.
-rw-r--r--include/netinet/tcp.h45
1 files changed, 41 insertions, 4 deletions
diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
index 5639b89a..9be2b940 100644
--- a/include/netinet/tcp.h
+++ b/include/netinet/tcp.h
@@ -44,12 +44,24 @@
 #define SOL_TCP 6
 #include <sys/types.h>
 #include <sys/socket.h>
-#endif
+#include <endian.h>
+
+typedef u_int32_t tcp_seq;
 
+#define TH_FIN 0x01
+#define TH_SYN 0x02
+#define TH_RST 0x04
+#define TH_PUSH 0x08
+#define TH_ACK 0x10
+#define TH_URG 0x20
+
+struct tcphdr {
 #ifdef _GNU_SOURCE
-#include <endian.h>
-struct tcphdr
-{
+#ifdef __GNUC__
+	__extension__
+#endif
+	union { struct {
+
 	u_int16_t source;
 	u_int16_t dest;
 	u_int32_t seq;
@@ -78,8 +90,33 @@ struct tcphdr
 	u_int16_t window;
 	u_int16_t check;
 	u_int16_t urg_ptr;
+
+	}; struct {
+#endif
+
+	u_int16_t th_sport;
+	u_int16_t th_dport;
+	u_int32_t th_seq;
+	u_int32_t th_ack;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+	u_int8_t th_x2:4;
+	u_int8_t th_off:4;
+#else
+	u_int8_t th_off:4;
+	u_int8_t th_x2:4;
+#endif
+	u_int8_t th_flags;
+	u_int16_t th_win;
+	u_int16_t th_sum;
+	u_int16_t th_urp;
+
+#ifdef _GNU_SOURCE
+	}; };
+#endif
 };
+#endif
 
+#ifdef _GNU_SOURCE
 #define TCPI_OPT_TIMESTAMPS	1
 #define TCPI_OPT_SACK		2
 #define TCPI_OPT_WSCALE		4