diff --git a/CMakeLists.txt b/CMakeLists.txt index fa90f3b33..cd174955a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,12 +165,12 @@ if(UNIX) set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) - elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c) - elseif (${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") + elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c) else() message(FATAL_ERROR "Your operating system is not supported yet") endif() diff --git a/include/llarp/endian.h b/include/llarp/endian.h index 5a195f4e5..6405dd97b 100644 --- a/include/llarp/endian.h +++ b/include/llarp/endian.h @@ -8,6 +8,26 @@ #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #include +#elif defined(__sun) +#include +#define htobe16(x) htons(x) +#define htole16(x) (x) +#define be16toh(x) ntohs(x) +#define le16toh(x) (x) + +#define htobe32(x) htonl(x) +#define htole32(x) (x) +#define be32toh(x) ntohl(x) +#define le32toh(x) (x) + +#define htobe64(x) \ + (((uint64_t)htonl(((uint32_t)(((uint64_t)(x)) >> 32)))) \ + | (((uint64_t)htonl(((uint32_t)(x)))) << 32)) +#define htole64(x) (x) +#define be64toh(x) \ + (((uint64_t)ntohl(((uint32_t)(((uint64_t)(x)) >> 32)))) \ + | (((uint64_t)ntohl(((uint32_t)(x)))) << 32)) +#define le64toh(x) (x) #elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GLIBC__) #include #elif defined(__APPLE__) && defined(__MACH__) diff --git a/include/llarp/ip.hpp b/include/llarp/ip.hpp index 8fc46fe5c..02861f901 100644 --- a/include/llarp/ip.hpp +++ b/include/llarp/ip.hpp @@ -2,8 +2,15 @@ #define LLARP_IP_HPP #include #include +#include #include #include +#ifdef __sun +// slightly different type names on sunos +#define iphdr ip +#define saddr ip_src.s_addr +#define daddr ip_dst.s_addr +#endif namespace llarp { diff --git a/include/llarp/iwp/server.hpp b/include/llarp/iwp/server.hpp index ce349761e..853cc4ee9 100644 --- a/include/llarp/iwp/server.hpp +++ b/include/llarp/iwp/server.hpp @@ -5,6 +5,12 @@ #include "router.hpp" #include "session.hpp" +#ifdef __sun +#ifdef saddr +#undef saddr +#endif +#endif + #include #include diff --git a/include/tuntap.h b/include/tuntap.h index cb42d20c7..005eedada 100644 --- a/include/tuntap.h +++ b/include/tuntap.h @@ -56,7 +56,7 @@ */ #if defined ETH_ALEN /* Linux */ #define ETHER_ADDR_LEN ETH_ALEN -#elif defined Windows +#elif defined Windows || defined __sun__ #define ETHER_ADDR_LEN 6 #endif @@ -86,7 +86,7 @@ */ #if defined Windows #include -#include +#include typedef HANDLE t_tun; typedef IN_ADDR t_tun_in_addr; typedef IN6_ADDR t_tun_in6_addr; diff --git a/llarp/context.cpp b/llarp/context.cpp index b797b86f5..e3185bca4 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -20,7 +20,7 @@ extern "C" void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName); #endif -#ifdef _WIN32 +#if _WIN32 || __sun #define wmin(x, y) (((x) < (y)) ? (x) : (y)) #define MIN wmin #endif diff --git a/llarp/ev.cpp b/llarp/ev.cpp index f0e2ca5ca..67d4ec255 100644 --- a/llarp/ev.cpp +++ b/llarp/ev.cpp @@ -5,7 +5,7 @@ #define EV_TICK_INTERVAL 100 // apparently current Solaris will emulate epoll. -#if __linux__ || __SunOS_5_11 +#if __linux__ || __sun__ #include "ev_epoll.hpp" #endif #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \ @@ -19,7 +19,7 @@ void llarp_ev_loop_alloc(struct llarp_ev_loop **ev) { -#if __linux__ || __SunOS_5_11 +#if __linux__ || __sun__ *ev = new llarp_epoll_loop; #endif #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \ @@ -111,4 +111,4 @@ bool llarp_ev_tun_async_write(struct llarp_tun_io *tun, const void *pkt, size_t sz) { return static_cast< llarp::ev_io * >(tun->impl)->queue_write(pkt, sz); -} \ No newline at end of file +} diff --git a/llarp/ev.hpp b/llarp/ev.hpp index 6237a1246..1099706a0 100644 --- a/llarp/ev.hpp +++ b/llarp/ev.hpp @@ -54,6 +54,14 @@ namespace llarp m_writeq.Process([this](const std::unique_ptr< WriteBuffer >& buffer) { write(fd, buffer->buf, buffer->bufsz); }); + // todo: wtf??? +#ifndef _WIN32 +#else +#if 0 + DWORD bytes_written = 0; + if(::WriteFile((HANDLE)fd, buffer->payload.data(), buffer->payload.size(), &bytes_written, nullptr)) +#endif +#endif /// reset errno errno = 0; } diff --git a/llarp/ev_win32.hpp b/llarp/ev_win32.hpp index c949c073d..4c62f1c78 100644 --- a/llarp/ev_win32.hpp +++ b/llarp/ev_win32.hpp @@ -21,13 +21,7 @@ namespace llarp WSAOVERLAPPED portfds[2] = {0}; size_t iosz; - // the unique completion key that helps us to - // identify the object instance for which we receive data - // Here, we'll use the address of the udp_listener instance, converted to - // its literal int/int64 representation. - ULONG_PTR listener_id = 0; - - udp_listener(SOCKET fd, llarp_udp_io* u) : ev_io(fd), udp(u){}; + udp_listener(SOCKET fd, llarp_udp_io* u) : ev_io(fd), udp(u){}; ~udp_listener() { diff --git a/llarp/fs.hpp b/llarp/fs.hpp index ad6d06dd3..9b0e71889 100644 --- a/llarp/fs.hpp +++ b/llarp/fs.hpp @@ -12,7 +12,7 @@ // win32 is the only one that doesn't use cpp17::filesystem // because cpp17::filesystem is unimplemented for Windows // -despair86 -#if defined(__MINGW32__) || defined(_MSC_VER) +#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__sun) namespace fs = std::experimental::filesystem; #else namespace fs = std::filesystem; diff --git a/vendor/cppbackport-master/lib/filesystem.h b/vendor/cppbackport-master/lib/filesystem.h index 9d925f2a0..94cdddb5b 100644 --- a/vendor/cppbackport-master/lib/filesystem.h +++ b/vendor/cppbackport-master/lib/filesystem.h @@ -39,7 +39,7 @@ #include "version.h" #if defined(CPP17) && defined(USE_CXX17_FILESYSTEM) -#if defined(__MINGW32__) || defined(_MSC_VER) +#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__sun) // win32 needs experimental #include #else