Browse Source

Added ntop4(), ntop6(), and ntop() to Jupiter::Socket.

release/0.19
JustinAJ 10 years ago
parent
commit
4fdd55288d
  1. 29
      Jupiter/Socket.cpp
  2. 27
      Jupiter/Socket.h
  3. BIN
      Release/Jupiter.lib

29
Jupiter/Socket.cpp

@ -316,6 +316,35 @@ in_addr6 Jupiter::Socket::pton6(const char *str)
return r;
}
Jupiter::StringS Jupiter::Socket::ntop4(uint32_t ip)
{
static char buf[16];
if (inet_ntop(AF_INET, &ip, buf, sizeof(buf)) == nullptr)
return Jupiter::StringS::empty;
return Jupiter::String(buf);
}
Jupiter::StringS Jupiter::Socket::ntop6(in_addr6 ip)
{
static char buf[46];
if (inet_ntop(AF_INET6, &ip, buf, sizeof(buf)) == nullptr)
return Jupiter::StringS::empty;
return Jupiter::String(buf);
}
Jupiter::StringS Jupiter::Socket::ntop(void *ip, size_t size)
{
switch (size)
{
case 4:
return ntop4(*reinterpret_cast<uint32_t *>(ip));
case 16:
return ntop6(*reinterpret_cast<in_addr6 *>(ip));
default:
return Jupiter::StringS::empty;
}
}
Jupiter::Socket *Jupiter::Socket::acceptConnection()
{
SOCKET tSock = accept(Socket::data_->rawSock, 0, 0);

27
Jupiter/Socket.h

@ -26,6 +26,7 @@
#include <cstring>
#include "Jupiter.h"
#include "Readable_String.h"
#include "String.h"
struct addrinfo;
struct in_addr6;
@ -180,6 +181,32 @@ namespace Jupiter
*/
static in_addr6 pton6(const char *str);
/**
* @brief Formats an IPv4 address in its string presentation format.
*
* @param ip IP to format
* @return String containing the address's string presentation.
*/
static Jupiter::StringS ntop4(uint32_t ip);
/**
* @brief Formats an IPv6 address in its string presentation format.
*
* @param ip IP to format
* @return String containing the address's string presentation.
*/
static Jupiter::StringS ntop6(in_addr6 ip);
/**
* @brief Formats an IPvX address in its string presentation format.
* Currently supports: IPv4, IPv6.
*
* @param ip IP to format
* @param size Size of the input type
* @return String containing the address's string presentation.
*/
static Jupiter::StringS ntop(void *ip, size_t size);
/**
* @brief Interface to provide simple connection establishing.
* Note: When using this method, the hostname and port are NOT stored; thus getHost(), getHostname(),

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save