mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-11 07:10:36 +00:00
871c3e3281
* wintun vpn platform for windows * bundle config snippets into nsis installer for exit node, keyfile persisting, reduced hops mode. * use wintun for vpn platform * isolate all windows platform specific code into their own compilation units and libraries * split up internal libraries into more specific components * rename liblokinet.a target to liblokinet-amalgum.a to elimiate ambiguity with liblokinet.so * DNS platform for win32 * rename llarp/ev/ev_libuv.{c,h}pp to llarp/ev/libuv.{c,h}pp as the old name was idiotic * split up net platform into win32 and posix specific compilation units * rename lokinet_init.c to easter_eggs.cpp as that is what they are for and it does not need to be a c compilation target * add cmake option STRIP_SYMBOLS for seperating out debug symbols for windows builds * intercept dns traffic on all interfaces on windows using windivert and feed it into lokinet
54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
#pragma once
|
|
#include "net_int.hpp"
|
|
|
|
namespace llarp
|
|
{
|
|
/// get a netmask with the higest numset bits set
|
|
constexpr huint128_t
|
|
_netmask_ipv6_bits(uint32_t numset)
|
|
{
|
|
return (128 - numset) ? (huint128_t{1} << numset) | _netmask_ipv6_bits(numset + 1)
|
|
: huint128_t{0};
|
|
}
|
|
|
|
constexpr huint128_t
|
|
netmask_ipv6_bits(uint32_t numset)
|
|
{
|
|
return _netmask_ipv6_bits(128 - numset);
|
|
}
|
|
|
|
/// get a netmask with the higest numset bits set
|
|
constexpr uint32_t
|
|
_netmask_ipv4_bits(uint32_t numset)
|
|
{
|
|
return (32 - numset) ? (1 << numset) | _netmask_ipv4_bits(numset + 1) : 0;
|
|
}
|
|
|
|
/// get a netmask given some /N range
|
|
constexpr huint32_t
|
|
netmask_ipv4_bits(uint32_t num)
|
|
{
|
|
return huint32_t{_netmask_ipv4_bits(32 - num)};
|
|
}
|
|
|
|
constexpr huint32_t
|
|
ipaddr_ipv4_bits(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
|
|
{
|
|
return huint32_t{(d) | (c << 8) | (b << 16) | (a << 24)};
|
|
}
|
|
|
|
// IPv4 mapped address live at ::ffff:0:0/96
|
|
constexpr std::array<uint8_t, 12> ipv4_map_prefix{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff};
|
|
|
|
namespace net
|
|
{
|
|
inline auto
|
|
ipaddr_netmask_bits(uint32_t bits, int af)
|
|
{
|
|
if (af == AF_INET6)
|
|
return netmask_ipv6_bits(bits);
|
|
return ExpandV4(netmask_ipv4_bits(bits));
|
|
};
|
|
} // namespace net
|
|
} // namespace llarp
|