From c6a3fc255a12c56056533b8cebef36b7b48c953a Mon Sep 17 00:00:00 2001 From: Rick Date: Thu, 20 Dec 2018 07:56:16 -0600 Subject: [PATCH] ok fix ip header struct which was broken for a while apparently --- llarp/ev_win32.hpp | 3 ++- llarp/ip.hpp | 61 +++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/llarp/ev_win32.hpp b/llarp/ev_win32.hpp index bbe8bf413..d4bd89b63 100644 --- a/llarp/ev_win32.hpp +++ b/llarp/ev_win32.hpp @@ -280,6 +280,7 @@ tun_ev_loop(void* unused) if(ev->t->recvpkt) ev->t->recvpkt(ev->t, llarp::InitBuffer(pkt->buf, size)); ev->flush_write(); + ev->read(ev->readbuf, sizeof(ev->readbuf)); } else { @@ -364,7 +365,7 @@ namespace llarp { socklen_t slen = sizeof(sockaddr_in); if(_addr.ss_family == AF_UNIX) - slen = 115; + slen = sizeof(sockaddr_un); else if(_addr.ss_family == AF_INET6) slen = sizeof(sockaddr_in6); int result = ::connect(fd, (const sockaddr*)&_addr, slen); diff --git a/llarp/ip.hpp b/llarp/ip.hpp index 30ef49a45..7634a3063 100644 --- a/llarp/ip.hpp +++ b/llarp/ip.hpp @@ -11,6 +11,32 @@ #include // FreeBSD needs this for uchar for ip.h #include #include +// anything not win32 +struct ip_header +{ +#if __BYTE_ORDER == __LITTLE_ENDIAN + unsigned int ihl : 4; + unsigned int version : 4; +#elif __BYTE_ORDER == __BIG_ENDIAN + unsigned int version : 4; + unsigned int ihl : 4; +#else +#error "Please fix " +#endif + +#if defined(__linux__) +#define ip_version version +#endif + uint8_t tos; + uint16_t tot_len; + uint16_t id; + uint16_t frag_off; + uint8_t ttl; + uint8_t protocol; + uint16_t check; + uint32_t saddr; + uint32_t daddr; +}; #else // windows nt #include @@ -19,7 +45,7 @@ typedef struct ip_hdr unsigned char ip_header_len : 4; // 4-bit header length (in 32-bit words) normally=5 // (Means 20 Bytes may be 24 also) - unsigned char ip_version : 4; // 4-bit IPv4 version + unsigned char version : 4; // 4-bit IPv4 version unsigned char ip_tos; // IP type of service unsigned short ip_total_length; // Total length unsigned short ip_id; // Unique identifier @@ -38,42 +64,17 @@ typedef struct ip_hdr unsigned int ip_srcaddr; // Source address unsigned int ip_destaddr; // Source address } IPV4_HDR; -#define iphdr IPV4_HDR +#define ip_header IPV4_HDR #define saddr ip_srcaddr #define daddr ip_destaddr #define check ip_checksum #define ihl ip_header_len -#define ip_version version -#endif +#define protocol ip_protocol +#define frag_off ip_frag_offset -#include - -// anything not win32 -struct ip_header -{ -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int ihl : 4; - unsigned int version : 4; -#elif __BYTE_ORDER == __BIG_ENDIAN - unsigned int version : 4; - unsigned int ihl : 4; -#else -#error "Please fix " #endif -#if defined(__linux__) -#define ip_version version -#endif - uint8_t tos; - uint16_t tot_len; - uint16_t id; - uint16_t frag_off; - uint8_t ttl; - uint8_t protocol; - uint16_t check; - uint32_t saddr; - uint32_t daddr; -}; +#include namespace llarp {