mirror of https://github.com/oxen-io/lokinet
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.4 KiB
C++
82 lines
1.4 KiB
C++
6 years ago
|
#ifndef LLARP_NET_INADDR_HPP
|
||
|
#define LLARP_NET_INADDR_HPP
|
||
|
|
||
6 years ago
|
#include <net/net.hpp>
|
||
6 years ago
|
|
||
|
namespace llarp
|
||
|
{
|
||
|
/// IPv4 or IPv6 holder
|
||
|
struct inAddr
|
||
|
{
|
||
|
// unsigned char s6_addr[16];
|
||
|
struct in6_addr _addr; // store in network order
|
||
|
|
||
6 years ago
|
/// zero out
|
||
6 years ago
|
void
|
||
|
reset();
|
||
|
|
||
6 years ago
|
/// from char*
|
||
6 years ago
|
bool
|
||
|
from_char_array(const char* str);
|
||
|
|
||
6 years ago
|
/// convert from SIIT to IPv4 Mode
|
||
6 years ago
|
void
|
||
|
fromSIIT();
|
||
|
|
||
6 years ago
|
/// convert from IPv4 Mode to SIIT
|
||
6 years ago
|
void
|
||
|
toSIIT();
|
||
|
|
||
6 years ago
|
/// not IPv4 Mode (an actual IPv6 address)
|
||
6 years ago
|
inline bool
|
||
|
isIPv6Mode() const;
|
||
|
|
||
6 years ago
|
/// IPv4 mode (not SIIT)
|
||
6 years ago
|
bool
|
||
|
isIPv4Mode() const;
|
||
|
|
||
6 years ago
|
/// clear out bytes 5-15 (Last 12 bytes)
|
||
|
/// This is how inet_pton works with IPv4 addresses
|
||
6 years ago
|
void
|
||
|
setIPv4Mode();
|
||
6 years ago
|
|
||
|
/// make debugging/testing easier
|
||
6 years ago
|
void
|
||
|
hexDebug();
|
||
|
|
||
|
//
|
||
|
// IPv4 specific functions
|
||
|
//
|
||
|
|
||
6 years ago
|
/// make ipv4 in_addr struct
|
||
6 years ago
|
in_addr
|
||
|
toIAddr();
|
||
|
|
||
6 years ago
|
/// set an IPv4 addr
|
||
6 years ago
|
void
|
||
|
from4int(const uint8_t one, const uint8_t two, const uint8_t three,
|
||
|
const uint8_t four);
|
||
|
|
||
6 years ago
|
/// set from an net-order uint32_t
|
||
6 years ago
|
void
|
||
|
fromN32(nuint32_t in);
|
||
6 years ago
|
/// set from an host-order uint32_t
|
||
6 years ago
|
void
|
||
|
fromH32(huint32_t in);
|
||
6 years ago
|
/// output as net-order uint32_t
|
||
6 years ago
|
nuint32_t
|
||
|
toN32();
|
||
6 years ago
|
/// output as host-order uint32_t
|
||
6 years ago
|
huint32_t
|
||
|
toH32();
|
||
|
|
||
|
//
|
||
|
// IPv6 specific functions
|
||
|
//
|
||
6 years ago
|
// coming soon
|
||
6 years ago
|
};
|
||
|
|
||
|
} // namespace llarp
|
||
|
|
||
|
#endif
|