From eeb9dde5d61baf128256b8a34349db4de70c4dbd Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 29 Dec 2008 07:40:08 -0500 Subject: [PATCH 8/9] 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 --- include/linux/cdrom.h | 3 ++ 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, 87 insertions(+), 20 deletions(-) diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h index 78e9047..e1b6ba8 100644 --- a/include/linux/cdrom.h +++ b/include/linux/cdrom.h @@ -12,6 +12,9 @@ #define _LINUX_CDROM_H #include +#ifndef __KERNEL__ +# include +#endif #include /******************************************************* diff --git a/include/linux/if.h b/include/linux/if.h index 1108f3e..f89a9bb 100644 --- a/include/linux/if.h +++ b/include/linux/if.h @@ -19,6 +19,8 @@ #ifndef _LINUX_IF_H #define _LINUX_IF_H +#include + #include /* for "__kernel_caddr_t" et al */ #include /* for "struct sockaddr" et al */ #include /* for "__user" et al */ @@ -122,7 +124,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; @@ -158,7 +160,7 @@ struct if_settings * remainder may be interface specific. */ -struct ifreq +struct __kernel_ifreq { #define IFHWADDRLEN 6 union @@ -208,7 +210,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 d60122a..a2dc594 100644 --- a/include/linux/in.h +++ b/include/linux/in.h @@ -18,42 +18,88 @@ #ifndef _LINUX_IN_H #define _LINUX_IN_H +#include + #include #include /* 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; }; @@ -117,26 +163,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; @@ -148,20 +194,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 */ @@ -174,7 +220,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; @@ -183,7 +229,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 718bf21..5e46527 100644 --- a/include/linux/in6.h +++ b/include/linux/in6.h @@ -21,13 +21,15 @@ #ifndef _LINUX_IN6_H #define _LINUX_IN6_H +#include + #include /* * 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 #include #include @@ -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 f8f2fa9..3e9ec06 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -324,4 +324,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 +#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 +#endif + #endif diff --git a/include/linux/time.h b/include/linux/time.h index 242f624..beb5baf 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -1,4 +1,10 @@ #ifndef _LINUX_TIME_H +# include +# include +# define _LINUX_TIME_H +#endif + +#ifndef _LINUX_TIME_H #define _LINUX_TIME_H #include diff --git a/include/linux/types.h b/include/linux/types.h index 2061c67..6ac313e 100644 --- a/include/linux/types.h +++ b/include/linux/types.h @@ -11,6 +11,7 @@ #endif +#include #include #ifdef __KERNEL__ -- 1.6.3.3