lokinet/llarp/net/net_inaddr.hpp

82 lines
1.4 KiB
C++
Raw Normal View History

#ifndef LLARP_NET_INADDR_HPP
#define LLARP_NET_INADDR_HPP
#include <net/net.hpp>
namespace llarp
{
/// IPv4 or IPv6 holder
struct inAddr
{
// unsigned char s6_addr[16];
struct in6_addr _addr; // store in network order
2018-10-24 10:22:26 +00:00
/// zero out
void
reset();
2018-10-24 10:22:26 +00:00
/// from char*
bool
from_char_array(const char* str);
2018-10-24 10:22:26 +00:00
/// convert from SIIT to IPv4 Mode
void
fromSIIT();
2018-10-24 10:22:26 +00:00
/// convert from IPv4 Mode to SIIT
void
toSIIT();
2018-10-24 10:22:26 +00:00
/// not IPv4 Mode (an actual IPv6 address)
inline bool
isIPv6Mode() const;
2018-10-24 10:22:26 +00:00
/// IPv4 mode (not SIIT)
bool
isIPv4Mode() const;
2018-10-24 10:22:26 +00:00
/// clear out bytes 5-15 (Last 12 bytes)
/// This is how inet_pton works with IPv4 addresses
void
setIPv4Mode();
2018-10-24 10:22:26 +00:00
/// make debugging/testing easier
void
hexDebug();
//
// IPv4 specific functions
//
2018-10-24 10:22:26 +00:00
/// make ipv4 in_addr struct
in_addr
toIAddr();
2018-10-24 10:22:26 +00:00
/// set an IPv4 addr
void
from4int(const uint8_t one, const uint8_t two, const uint8_t three,
const uint8_t four);
2018-10-24 10:22:26 +00:00
/// set from an net-order uint32_t
void
fromN32(nuint32_t in);
2018-10-24 10:22:26 +00:00
/// set from an host-order uint32_t
void
fromH32(huint32_t in);
2018-10-24 10:22:26 +00:00
/// output as net-order uint32_t
nuint32_t
toN32();
2018-10-24 10:22:26 +00:00
/// output as host-order uint32_t
huint32_t
toH32();
//
// IPv6 specific functions
//
2018-10-24 10:22:26 +00:00
// coming soon
};
} // namespace llarp
#endif