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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
From 958b7b63cb221eec91fa25a6aa884eb14341f3a6 Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Mon, 29 Dec 2008 07:40:08 -0500
Subject: [PATCH] HACK: linux/*: pull in C library headers
pull in the libc versions of these headers so that the proper userspace
defines/typedefs are utilized.
the trouble here is that some of the linux/ headers define structs that the
libc net/ headers define (like the if.h header). we cannot simply say
"your program should not include linux/if.h when using net/if.h" because some
of the other linux/ headers may correctly be utilized with net/if.h but they
correctly include linux/if.h. we also cannot say "just use the linux/ headers
and not the libc net/ headers" because the libc headers include more
definitions than its kernel equivalent.
since there is no obvious (at least to me) answer here, we hack the linux/
headers to simply pull in userspace headers and ignore the linux/ ones
completely. this seems to give a proper clean userspace experience.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
include/linux/cdrom.h | 4 +++
include/linux/if.h | 8 +++--
include/linux/in.h | 66 ++++++++++++++++++++++++++++++++++++++++-------
include/linux/in6.h | 11 +++----
include/linux/ip.h | 3 +-
include/linux/socket.h | 5 +++
include/linux/stat.h | 4 +++
include/linux/time.h | 6 ++++
include/linux/types.h | 1 +
9 files changed, 88 insertions(+), 20 deletions(-)
diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
index 0b49e08..257a03d 100644
--- a/include/linux/cdrom.h
+++ b/include/linux/cdrom.h
@@ -11,6 +11,10 @@
#ifndef _LINUX_CDROM_H
#define _LINUX_CDROM_H
+#ifndef __KERNEL__
+# include <limits.h>
+#endif
+
#include <asm/byteorder.h>
/*******************************************************
diff --git a/include/linux/if.h b/include/linux/if.h
index 6524684..0ef24c6 100644
--- a/include/linux/if.h
+++ b/include/linux/if.h
@@ -19,6 +19,8 @@
#ifndef _LINUX_IF_H
#define _LINUX_IF_H
+#include <net/if.h>
+
#include <linux/types.h> /* for "__kernel_caddr_t" et al */
#include <linux/socket.h> /* for "struct sockaddr" et al */
#include <linux/compiler.h> /* for "__user" et al */
@@ -120,7 +122,7 @@ enum {
* being very small might be worth keeping for clean configuration.
*/
-struct ifmap
+struct __kernel_ifmap
{
unsigned long mem_start;
unsigned long mem_end;
@@ -156,7 +158,7 @@ struct if_settings
* remainder may be interface specific.
*/
-struct ifreq
+struct __kernel_ifreq
{
#define IFHWADDRLEN 6
union
@@ -206,7 +208,7 @@ struct ifreq
* must know all networks accessible).
*/
-struct ifconf
+struct __kernel_ifconf
{
int ifc_len; /* size of buffer */
union
diff --git a/include/linux/in.h b/include/linux/in.h
index db458be..c7643a7 100644
--- a/include/linux/in.h
+++ b/include/linux/in.h
@@ -18,42 +18,88 @@
#ifndef _LINUX_IN_H
#define _LINUX_IN_H
+#include <netinet/in.h>
+
#include <linux/types.h>
#include <linux/socket.h>
/* Standard well-defined IP protocols. */
enum {
+#ifndef IPPROTO_IP
IPPROTO_IP = 0, /* Dummy protocol for TCP */
+#endif
+#ifndef IPPROTO_ICMP
IPPROTO_ICMP = 1, /* Internet Control Message Protocol */
+#endif
+#ifndef IPPROTO_IGMP
IPPROTO_IGMP = 2, /* Internet Group Management Protocol */
+#endif
+#ifndef IPPROTO_IPIP
IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94) */
+#endif
+#ifndef IPPROTO_TCP
IPPROTO_TCP = 6, /* Transmission Control Protocol */
+#endif
+#ifndef IPPROTO_EGP
IPPROTO_EGP = 8, /* Exterior Gateway Protocol */
+#endif
+#ifndef IPPROTO_PUP
IPPROTO_PUP = 12, /* PUP protocol */
+#endif
+#ifndef IPPROTO_UDP
IPPROTO_UDP = 17, /* User Datagram Protocol */
+#endif
+#ifndef IPPROTO_IDP
IPPROTO_IDP = 22, /* XNS IDP protocol */
+#endif
+#ifndef IPPROTO_DCCP
IPPROTO_DCCP = 33, /* Datagram Congestion Control Protocol */
+#endif
+#ifndef IPPROTO_RSVP
IPPROTO_RSVP = 46, /* RSVP protocol */
+#endif
+#ifndef IPPROTO_GRE
IPPROTO_GRE = 47, /* Cisco GRE tunnels (rfc 1701,1702) */
+#endif
+#ifndef IPPROTO_IPV6
IPPROTO_IPV6 = 41, /* IPv6-in-IPv4 tunnelling */
+#endif
+#ifndef IPPROTO_ESP
IPPROTO_ESP = 50, /* Encapsulation Security Payload protocol */
+#endif
+#ifndef IPPROTO_AH
IPPROTO_AH = 51, /* Authentication Header protocol */
+#endif
+#ifndef IPPROTO_BEETPH
IPPROTO_BEETPH = 94, /* IP option pseudo header for BEET */
+#endif
+#ifndef IPPROTO_PIM
IPPROTO_PIM = 103, /* Protocol Independent Multicast */
+#endif
+#ifndef IPPROTO_COMP
IPPROTO_COMP = 108, /* Compression Header protocol */
+#endif
+#ifndef IPPROTO_SCTP
IPPROTO_SCTP = 132, /* Stream Control Transport Protocol */
+#endif
+#ifndef IPPROTO_UDPLITE
IPPROTO_UDPLITE = 136, /* UDP-Lite (RFC 3828) */
+#endif
+#ifndef IPPROTO_RAW
IPPROTO_RAW = 255, /* Raw IP packets */
+#endif
+#if 0
IPPROTO_MAX
+#endif
};
/* Internet address. */
-struct in_addr {
+struct __kernel_in_addr {
__be32 s_addr;
};
@@ -113,26 +159,26 @@ struct in_addr {
/* Request struct for multicast socket ops */
-struct ip_mreq
+struct __kernel_ip_mreq
{
struct in_addr imr_multiaddr; /* IP multicast address of group */
struct in_addr imr_interface; /* local IP address of interface */
};
-struct ip_mreqn
+struct __kernel_ip_mreqn
{
struct in_addr imr_multiaddr; /* IP multicast address of group */
struct in_addr imr_address; /* local IP address of interface */
int imr_ifindex; /* Interface index */
};
-struct ip_mreq_source {
+struct __kernel_ip_mreq_source {
__be32 imr_multiaddr;
__be32 imr_interface;
__be32 imr_sourceaddr;
};
-struct ip_msfilter {
+struct __kernel_ip_msfilter {
__be32 imsf_multiaddr;
__be32 imsf_interface;
__u32 imsf_fmode;
@@ -144,20 +190,20 @@ struct ip_msfilter {
(sizeof(struct ip_msfilter) - sizeof(__u32) \
+ (numsrc) * sizeof(__u32))
-struct group_req
+struct __kernel_group_req
{
__u32 gr_interface; /* interface index */
struct __kernel_sockaddr_storage gr_group; /* group address */
};
-struct group_source_req
+struct __kernel_group_source_req
{
__u32 gsr_interface; /* interface index */
struct __kernel_sockaddr_storage gsr_group; /* group address */
struct __kernel_sockaddr_storage gsr_source; /* source address */
};
-struct group_filter
+struct __kernel_group_filter
{
__u32 gf_interface; /* interface index */
struct __kernel_sockaddr_storage gf_group; /* multicast address */
@@ -170,7 +216,7 @@ struct group_filter
(sizeof(struct group_filter) - sizeof(struct __kernel_sockaddr_storage) \
+ (numsrc) * sizeof(struct __kernel_sockaddr_storage))
-struct in_pktinfo
+struct __kernel_in_pktinfo
{
int ipi_ifindex;
struct in_addr ipi_spec_dst;
@@ -179,7 +225,7 @@ struct in_pktinfo
/* Structure describing an Internet (IP) socket address. */
#define __SOCK_SIZE__ 16 /* sizeof(struct sockaddr) */
-struct sockaddr_in {
+struct __kernel_sockaddr_in {
sa_family_t sin_family; /* Address family */
__be16 sin_port; /* Port number */
struct in_addr sin_addr; /* Internet address */
diff --git a/include/linux/in6.h b/include/linux/in6.h
index bc49204..28c949c 100644
--- a/include/linux/in6.h
+++ b/include/linux/in6.h
@@ -21,13 +21,15 @@
#ifndef _LINUX_IN6_H
#define _LINUX_IN6_H
+#include <netinet/in.h>
+
#include <linux/types.h>
/*
* IPv6 address structure
*/
-struct in6_addr
+struct __kernel_in6_addr
{
union
{
@@ -35,9 +37,6 @@ struct in6_addr
__be16 u6_addr16[8];
__be32 u6_addr32[4];
} in6_u;
-#define s6_addr in6_u.u6_addr8
-#define s6_addr16 in6_u.u6_addr16
-#define s6_addr32 in6_u.u6_addr32
};
/* IPv6 Wildcard Address (::) and Loopback Address (::1) defined in RFC2553
@@ -57,7 +56,7 @@ extern const struct in6_addr in6addr_linklocal_allrouters;
{ { { 0xff,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2 } } }
#endif
-struct sockaddr_in6 {
+struct __kernel_sockaddr_in6 {
unsigned short int sin6_family; /* AF_INET6 */
__be16 sin6_port; /* Transport layer port # */
__be32 sin6_flowinfo; /* IPv6 flow information */
@@ -65,7 +64,7 @@ struct sockaddr_in6 {
__u32 sin6_scope_id; /* scope id (new in RFC2553) */
};
-struct ipv6_mreq {
+struct __kernel_ipv6_mreq {
/* IPv6 multicast address of group */
struct in6_addr ipv6mr_multiaddr;
diff --git a/include/linux/ip.h b/include/linux/ip.h
index bd0a2a8..19619cc 100644
--- a/include/linux/ip.h
+++ b/include/linux/ip.h
@@ -16,6 +16,7 @@
*/
#ifndef _LINUX_IP_H
#define _LINUX_IP_H
+#include <netinet/ip.h>
#include <linux/types.h>
#include <asm/byteorder.h>
@@ -82,7 +83,7 @@
#define IPV4_BEET_PHMAXLEN 8
-struct iphdr {
+struct __kernel_iphdr {
#if defined(__LITTLE_ENDIAN_BITFIELD)
__u8 ihl:4,
version:4;
diff --git a/include/linux/socket.h b/include/linux/socket.h
index d9b4492..1c6c14c 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -319,4 +319,9 @@ extern int put_cmsg(struct msghdr*, int level, int type, int len, void *data);
#endif
#endif /* not kernel and not glibc */
+
+#ifndef __KERNEL__
+# include <sys/socket.h>
+#endif
+
#endif /* _LINUX_SOCKET_H */
diff --git a/include/linux/stat.h b/include/linux/stat.h
index 5460344..a90fdb2 100644
--- a/include/linux/stat.h
+++ b/include/linux/stat.h
@@ -77,4 +77,8 @@ struct kstat {
#endif
+#ifndef __KERNEL__
+# include <sys/stat.h>
+#endif
+
#endif
diff --git a/include/linux/time.h b/include/linux/time.h
index ce321ac..f0f9347 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -1,4 +1,10 @@
#ifndef _LINUX_TIME_H
+# include <time.h>
+# include <sys/time.h>
+# define _LINUX_TIME_H
+#endif
+
+#ifndef _LINUX_TIME_H
#define _LINUX_TIME_H
#include <linux/types.h>
diff --git a/include/linux/types.h b/include/linux/types.h
index a999d0c..8a2be87 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -8,6 +8,7 @@
#endif
+#include <sys/types.h>
#include <linux/posix_types.h>
#include <asm/types.h>
--
1.6.0.6
|