summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort00fcxen <t00fcxen>2014-10-01 19:54:29 +0000
committert00fcxen <t00fcxen>2014-10-01 19:54:29 +0000
commitd5685d4cc67d1fba57b7cb0024fc9065971e5ac1 (patch)
tree09f63226c3e60c24a670e0899f134d2722fc217c
parent00e26b77903bfb859552f0924b2ba07e02215d8e (diff)
downloadusrsctplib-d5685d4cc67d1fba57b7cb0024fc9065971e5ac1.tar.gz
Add support for Native Client used for Chrome Remote Desktop.
The patch is provided by Sergey Ulanov from Google. git-svn-id: http://sctp-refimpl.googlecode.com/svn/trunk/KERN/usrsctp/usrsctplib@9029 9df1edf5-d72c-5b5f-11c0-5f5209eb73f7
-rwxr-xr-xnetinet/sctp_os_userspace.h152
-rwxr-xr-xnetinet/sctp_userspace.c10
-rwxr-xr-xnetinet/sctp_usrreq.c2
-rwxr-xr-xuser_sctp_timer_iterate.c3
-rwxr-xr-xuser_socketvar.h4
5 files changed, 98 insertions, 73 deletions
diff --git a/netinet/sctp_os_userspace.h b/netinet/sctp_os_userspace.h
index eca3e18..e8de92f 100755
--- a/netinet/sctp_os_userspace.h
+++ b/netinet/sctp_os_userspace.h
@@ -103,7 +103,6 @@ typedef HANDLE userland_thread_t;
#define n_time unsigned __int32
#define sa_family_t unsigned __int8
#define ssize_t __int64
-#define IFNAMSIZ 64
#define __func__ __FUNCTION__
#ifndef EWOULDBLOCK
@@ -222,8 +221,6 @@ typedef char* caddr_t;
#define snprintf(data, size, format, ...) _snprintf_s(data, size, _TRUNCATE, format, __VA_ARGS__)
#define inline __inline
#define __inline__ __inline
-#define random() rand()
-#define srandom(s) srand(s)
#define MSG_EOR 0x8 /* data completes record */
#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
@@ -265,6 +262,37 @@ typedef char* caddr_t;
#define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) 1 /* compiles... TODO use routing socket to determine */
+#define BIG_ENDIAN 1
+#define LITTLE_ENDIAN 0
+#ifdef WORDS_BIGENDIAN
+#define BYTE_ORDER BIG_ENDIAN
+#else
+#define BYTE_ORDER LITTLE_ENDIAN
+#endif
+
+int Win_getifaddrs(struct ifaddrs**);
+#define getifaddrs(interfaces) (int)Win_getifaddrs(interfaces)
+int win_if_nametoindex(const char *);
+#define if_nametoindex(x) win_if_nametoindex(x)
+
+#else /* !defined(Userspace_os_Windows) */
+#include <sys/cdefs.h> /* needed? added from old __FreeBSD__ */
+#include <sys/socket.h>
+#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Linux) || defined(__Userspace_os_NetBSD) || defined(__Userspace_os_OpenBSD) || defined(__Userspace_os_NaCl)
+#include <pthread.h>
+#endif
+typedef pthread_mutex_t userland_mutex_t;
+typedef pthread_cond_t userland_cond_t;
+typedef pthread_t userland_thread_t;
+#endif
+
+#if defined(__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
+
+#define IFNAMSIZ 64
+
+#define random() rand()
+#define srandom(s) srand(s)
+
#define timeradd(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
@@ -285,30 +313,57 @@ typedef char* caddr_t;
} \
} while (0)
-#define BIG_ENDIAN 1
-#define LITTLE_ENDIAN 0
-#ifdef WORDS_BIGENDIAN
-#define BYTE_ORDER BIG_ENDIAN
-#else
-#define BYTE_ORDER LITTLE_ENDIAN
-#endif
+/*#include <packon.h>
+#pragma pack(push, 1)*/
+struct ip {
+ u_char ip_hl:4, ip_v:4;
+ u_char ip_tos;
+ u_short ip_len;
+ u_short ip_id;
+ u_short ip_off;
+#define IP_RP 0x8000
+#define IP_DF 0x4000
+#define IP_MF 0x2000
+#define IP_OFFMASK 0x1fff
+ u_char ip_ttl;
+ u_char ip_p;
+ u_short ip_sum;
+ struct in_addr ip_src, ip_dst;
+};
+
+struct ifaddrs {
+ struct ifaddrs *ifa_next;
+ char *ifa_name;
+ unsigned int ifa_flags;
+ struct sockaddr *ifa_addr;
+ struct sockaddr *ifa_netmask;
+ struct sockaddr *ifa_dstaddr;
+ void *ifa_data;
+};
+
+struct udphdr {
+ uint16_t uh_sport;
+ uint16_t uh_dport;
+ uint16_t uh_ulen;
+ uint16_t uh_sum;
+};
struct iovec {
- ULONG len;
- CHAR FAR *buf;
+ unsigned long len;
+ char *buf;
};
#define iov_base buf
#define iov_len len
struct ifa_msghdr {
- unsigned __int16 ifam_msglen;
+ uint16_t ifam_msglen;
unsigned char ifam_version;
unsigned char ifam_type;
- __int32 ifam_addrs;
- __int32 ifam_flags;
- unsigned __int16 ifam_index;
- __int32 ifam_metric;
+ uint32_t ifam_addrs;
+ uint32_t ifam_flags;
+ uint16_t ifam_index;
+ uint32_t ifam_metric;
};
struct ifdevmtu {
@@ -341,7 +396,7 @@ struct ifreq {
char* ifru_data;
struct ifdevmtu ifru_devmtu;
struct ifkpi ifru_kpi;
- unsigned __int32 ifru_wake_flags;
+ uint32_t ifru_wake_flags;
} ifr_ifru;
#define ifr_addr ifr_ifru.ifru_addr
#define ifr_dstaddr ifr_ifru.ifru_dstaddr
@@ -359,55 +414,6 @@ struct ifreq {
#define ifr_wake_flags ifr_ifru.ifru_wake_flags
};
-/*#include <packon.h>
-#pragma pack(push, 1)*/
-struct ip {
- u_char ip_hl:4, ip_v:4;
- u_char ip_tos;
- u_short ip_len;
- u_short ip_id;
- u_short ip_off;
-#define IP_RP 0x8000
-#define IP_DF 0x4000
-#define IP_MF 0x2000
-#define IP_OFFMASK 0x1fff
- u_char ip_ttl;
- u_char ip_p;
- u_short ip_sum;
- struct in_addr ip_src, ip_dst;
-};
-
-struct ifaddrs {
- struct ifaddrs *ifa_next;
- char *ifa_name;
- unsigned int ifa_flags;
- struct sockaddr *ifa_addr;
- struct sockaddr *ifa_netmask;
- struct sockaddr *ifa_dstaddr;
- void *ifa_data;
-};
-
-struct udphdr {
- unsigned __int16 uh_sport;
- unsigned __int16 uh_dport;
- unsigned __int16 uh_ulen;
- unsigned __int16 uh_sum;
-};
-
-int Win_getifaddrs(struct ifaddrs**);
-#define getifaddrs(interfaces) (int)Win_getifaddrs(interfaces)
-int win_if_nametoindex(const char *);
-#define if_nametoindex(x) win_if_nametoindex(x)
-
-#else /* !defined(Userspace_os_Windows) */
-#include <sys/cdefs.h> /* needed? added from old __FreeBSD__ */
-#include <sys/socket.h>
-#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Linux) || defined(__Userspace_os_NetBSD) || defined(__Userspace_os_OpenBSD)
-#include <pthread.h>
-#endif
-typedef pthread_mutex_t userland_mutex_t;
-typedef pthread_cond_t userland_cond_t;
-typedef pthread_t userland_thread_t;
#endif
#define mtx_lock(arg1)
@@ -469,7 +475,7 @@ struct sx {int dummy;};
* userspace as well? */
/* on FreeBSD, this results in a redefintion of struct route */
/* #include <net/route.h> */
-#if !defined(__Userspace_os_Windows)
+#if !defined(__Userspace_os_Windows) && !defined(__Userspace_os_NaCl)
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@@ -1095,7 +1101,7 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
/* with the current included files, this is defined in Linux but
* in FreeBSD, it is behind a _KERNEL in sys/socket.h ...
*/
-#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD)
+#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) || defined(__Userspace_os_NaCl)
/* stolen from /usr/include/sys/socket.h */
#define CMSG_ALIGN(n) _ALIGN(n)
#elif defined(__Userspace_os_NetBSD)
@@ -1153,4 +1159,12 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
#define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE
#define LIST_FOREACH_SAFE LIST_FOREACH_MUTABLE
#endif
+
+#if defined(__Userspace_os_NaCl)
+#define timercmp(tvp, uvp, cmp) \
+ (((tvp)->tv_sec == (uvp)->tv_sec) ? \
+ ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
+ ((tvp)->tv_sec cmp (uvp)->tv_sec))
+#endif
+
#endif
diff --git a/netinet/sctp_userspace.c b/netinet/sctp_userspace.c
index e6d01a9..7841a89 100755
--- a/netinet/sctp_userspace.c
+++ b/netinet/sctp_userspace.c
@@ -35,7 +35,7 @@
#endif
#include <netinet/sctp_os_userspace.h>
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__Userspace_os_NaCl)
int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
{
@@ -55,6 +55,14 @@ sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
}
#endif
+#if defined(__Userspace_os_NaCl)
+int
+sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
+{
+ return 1280;
+}
+#endif
+
#ifdef _WIN32
int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
diff --git a/netinet/sctp_usrreq.c b/netinet/sctp_usrreq.c
index 3c134f8..e04e598 100755
--- a/netinet/sctp_usrreq.c
+++ b/netinet/sctp_usrreq.c
@@ -106,7 +106,7 @@ sctp_init(void)
/* Initialize and modify the sysctled variables */
sctp_init_sysctls();
#if defined(__Userspace__)
-#if defined(__Userspace_os_Windows)
+#if defined(__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
srand((unsigned int)time(NULL));
#else
srandom(getpid()); /* so inp->sctp_ep.random_numbers are truly random... */
diff --git a/user_sctp_timer_iterate.c b/user_sctp_timer_iterate.c
index 0a9dbce..67684fd 100755
--- a/user_sctp_timer_iterate.c
+++ b/user_sctp_timer_iterate.c
@@ -31,6 +31,9 @@
#include <unistd.h>
#include <pthread.h>
#endif
+#if defined(__Userspace_os_NaCl)
+#include <sys/select.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
diff --git a/user_socketvar.h b/user_socketvar.h
index dd4ff10..5c3d9ee 100755
--- a/user_socketvar.h
+++ b/user_socketvar.h
@@ -42,7 +42,7 @@
/* #include <sys/_lock.h> was 0 byte file */
/* #include <sys/_mutex.h> was 0 byte file */
/* #include <sys/_sx.h> */ /*__Userspace__ alternative?*/
-#if !defined(__Userspace_os_DragonFly) && !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_Windows)
+#if !defined(__Userspace_os_DragonFly) && !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_Windows) && !defined(__Userspace_os_NaCl)
#include <sys/uio.h>
#endif
#define SOCK_MAXADDRLEN 255
@@ -54,7 +54,7 @@
#define SS_CANTRCVMORE 0x020
#define SS_CANTSENDMORE 0x010
-#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) || defined (__Userspace_os_Windows)
+#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) || defined (__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
#define UIO_MAXIOV 1024
#define ERESTART (-1)
#endif