aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/1003-use-anonymous-union-to-provide-bsd-and-gnu-variants-.patch
blob: c5b81083d545e147c9f487f244bc370b287316fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
From 643c0776155ec3165198c21708f7a2f88fc02adc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Mon, 13 Jan 2014 13:29:10 +0200
Subject: [PATCH] use anonymous union to provide bsd and gnu variants of struct
 tcphdr and udphdr

---
 include/netinet/tcp.h | 92 ++++++++++++++++++++++++++++++++++-----------------
 include/netinet/udp.h | 26 ++++++++++-----
 2 files changed, 79 insertions(+), 39 deletions(-)

diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
index 5639b89..09c9279 100644
--- a/include/netinet/tcp.h
+++ b/include/netinet/tcp.h
@@ -44,42 +44,74 @@
 #define SOL_TCP 6
 #include <sys/types.h>
 #include <sys/socket.h>
-#endif
-
-#ifdef _GNU_SOURCE
 #include <endian.h>
-struct tcphdr
-{
-	u_int16_t source;
-	u_int16_t dest;
-	u_int32_t seq;
-	u_int32_t ack_seq;
+
+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 __GNUC__
+	__extension__
+#endif
+	union {
+		struct {
+			u_int16_t source;
+			u_int16_t dest;
+			u_int32_t seq;
+			u_int32_t ack_seq;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+			u_int16_t res1:4;
+			u_int16_t doff:4;
+			u_int16_t fin:1;
+			u_int16_t syn:1;
+			u_int16_t rst:1;
+			u_int16_t psh:1;
+			u_int16_t ack:1;
+			u_int16_t urg:1;
+			u_int16_t res2:2;
+#else
+			u_int16_t doff:4;
+			u_int16_t res1:4;
+			u_int16_t res2:2;
+			u_int16_t urg:1;
+			u_int16_t ack:1;
+			u_int16_t psh:1;
+			u_int16_t rst:1;
+			u_int16_t syn:1;
+			u_int16_t fin:1;
+#endif
+			u_int16_t window;
+			u_int16_t check;
+			u_int16_t urg_ptr;
+		};
+		struct {
+			u_int16_t th_sport;
+			u_int16_t th_dport;
+			tcp_seq th_seq;
+			tcp_seq th_ack;
 #if __BYTE_ORDER == __LITTLE_ENDIAN
-	u_int16_t res1:4;
-	u_int16_t doff:4;
-	u_int16_t fin:1;
-	u_int16_t syn:1;
-	u_int16_t rst:1;
-	u_int16_t psh:1;
-	u_int16_t ack:1;
-	u_int16_t urg:1;
-	u_int16_t res2:2;
+			u_int8_t th_x2:4;
+			u_int8_t th_off:4;
 #else
-	u_int16_t doff:4;
-	u_int16_t res1:4;
-	u_int16_t res2:2;
-	u_int16_t urg:1;
-	u_int16_t ack:1;
-	u_int16_t psh:1;
-	u_int16_t rst:1;
-	u_int16_t syn:1;
-	u_int16_t fin:1;
+			u_int8_t th_off:4;
+			u_int8_t th_x2:4;
 #endif
-	u_int16_t window;
-	u_int16_t check;
-	u_int16_t urg_ptr;
+			u_int8_t th_flags;
+			u_int16_t th_win;
+			u_int16_t th_sum;
+			u_int16_t th_urp;
+		};
+	};
 };
+#endif
 
+#ifdef _GNU_SOURCE
 #define TCPI_OPT_TIMESTAMPS	1
 #define TCPI_OPT_SACK		2
 #define TCPI_OPT_WSCALE		4
diff --git a/include/netinet/udp.h b/include/netinet/udp.h
index 15b9145..223a5e3 100644
--- a/include/netinet/udp.h
+++ b/include/netinet/udp.h
@@ -8,17 +8,25 @@ extern "C" {
 #include <stdint.h>
 
 struct udphdr {
-	uint16_t source;
-	uint16_t dest;
-	uint16_t len;
-	uint16_t check;
+#ifdef __GNUC__
+	__extension__
+#endif
+	union {
+		struct {
+			uint16_t source;
+			uint16_t dest;
+			uint16_t len;
+			uint16_t check;
+		};
+		struct {
+			uint16_t uh_sport;
+			uint16_t uh_dport;
+			uint16_t uh_ulen;
+			uint16_t uh_sum;
+		};
+	};
 };
 
-#define uh_sport source
-#define uh_dport dest
-#define uh_ulen len
-#define uh_sum check
-
 #define UDP_CORK	1
 #define UDP_ENCAP	100
 
-- 
1.8.5.2