diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index cf0ae5dc0..3ace345ed 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/llarp/net/ip_packet.cpp b/llarp/net/ip_packet.cpp index 9f822b818..3bda060d0 100644 --- a/llarp/net/ip_packet.cpp +++ b/llarp/net/ip_packet.cpp @@ -126,21 +126,22 @@ namespace llarp::net SockAddr IPPacket::src() const { - auto port = SrcPort(); + const auto port = SrcPort().value_or(net::port_t{}); + if (IsV4()) - return SockAddr{ToNet(srcv4()), *port}; + return SockAddr{ToNet(srcv4()), port}; else - return SockAddr{ToNet(srcv6()), *port}; + return SockAddr{ToNet(srcv6()), port}; } SockAddr IPPacket::dst() const { - auto port = DstPort(); + auto port = *DstPort(); if (IsV4()) - return SockAddr{ToNet(dstv4()), *port}; + return SockAddr{ToNet(dstv4()), port}; else - return SockAddr{ToNet(dstv6()), *port}; + return SockAddr{ToNet(dstv6()), port}; } IPPacket::IPPacket(std::vector&& stolen) : _buf{stolen} @@ -171,7 +172,8 @@ namespace llarp::net std::optional IPPacket::SrcPort() const { - switch (IPProtocol{Header()->protocol}) + IPProtocol proto{Header()->protocol}; + switch (proto) { case IPProtocol::TCP: case IPProtocol::UDP: diff --git a/llarp/net/ip_packet.hpp b/llarp/net/ip_packet.hpp index 14418d05f..5d297ff92 100644 --- a/llarp/net/ip_packet.hpp +++ b/llarp/net/ip_packet.hpp @@ -10,6 +10,7 @@ namespace llarp::net { +#pragma pack(push, 1) template struct ip_header_le { @@ -41,6 +42,7 @@ namespace llarp::net uint32_t saddr; uint32_t daddr; }; +#pragma pack(pop) using ip_header = ip_header_le; diff --git a/llarp/net/sock_addr.cpp b/llarp/net/sock_addr.cpp index 2e9595bc8..f42feb928 100644 --- a/llarp/net/sock_addr.cpp +++ b/llarp/net/sock_addr.cpp @@ -288,10 +288,7 @@ namespace llarp // TODO: review if (isEmpty()) return ""; - std::string str = hostString(); - str.append(1, ':'); - str.append(std::to_string(getPort())); - return str; + return fmt::format("{}:{}", hostString(), port()); } std::string diff --git a/llarp/util/buffer.cpp b/llarp/util/buffer.cpp index bc495dacd..7dc3d747c 100644 --- a/llarp/util/buffer.cpp +++ b/llarp/util/buffer.cpp @@ -115,7 +115,6 @@ llarp_buffer_t::copy() const return copy; } - namespace llarp { std::vector diff --git a/llarp/util/buffer.hpp b/llarp/util/buffer.hpp index 343b2f466..abb0cffa0 100644 --- a/llarp/util/buffer.hpp +++ b/llarp/util/buffer.hpp @@ -168,10 +168,12 @@ struct [[deprecated("this type is stupid, use something else")]] llarp_buffer_t return {cur, size_left()}; } - /// Part of the curse. Returns true if the remaining buffer space starts with the given string view. + /// Part of the curse. Returns true if the remaining buffer space starts with the given string + /// view. bool startswith(std::string_view prefix_str) const { - llarp::byte_view_t prefix{reinterpret_cast(prefix_str.data()), prefix_str.size()}; + llarp::byte_view_t prefix{ + reinterpret_cast(prefix_str.data()), prefix_str.size()}; return view_remaining().substr(0, prefix.size()) == prefix; } diff --git a/llarp/win32/windivert.cpp b/llarp/win32/windivert.cpp index 359d0f7b2..34bea2956 100644 --- a/llarp/win32/windivert.cpp +++ b/llarp/win32/windivert.cpp @@ -5,6 +5,7 @@ #include "handle.hpp" #include #include +#include #include extern "C" {