Browse Source

added some '_alloc' versions of 'Socket::resolveHostname' which do NOT use a static memory buffer.

release/0.19
Jessica James 9 years ago
parent
commit
5e34f3d750
  1. 21
      Jupiter/Socket.cpp
  2. 4
      Jupiter/Socket.h
  3. BIN
      Release/Jupiter.lib

21
Jupiter/Socket.cpp

@ -324,6 +324,13 @@ char *Jupiter::Socket::resolveAddress(const char *hostname, unsigned int result)
char *Jupiter::Socket::resolveHostname(addrinfo *addr) // static
{
static char resolved[NI_MAXHOST];
getnameinfo(addr->ai_addr, addr->ai_addrlen, resolved, sizeof(resolved), 0, 0, 0);
return resolved;
}
char *Jupiter::Socket::resolveHostname_alloc(addrinfo *addr) // static
{
char *resolved = new char[NI_MAXHOST];
getnameinfo(addr->ai_addr, addr->ai_addrlen, resolved, NI_MAXHOST, 0, 0, 0);
return resolved;
}
@ -335,6 +342,13 @@ char *Jupiter::Socket::resolveHostname(addrinfo *addr, unsigned int result) // s
return Jupiter::Socket::resolveHostname(ptr);
}
char *Jupiter::Socket::resolveHostname_alloc(addrinfo *addr, unsigned int result) // static
{
addrinfo *ptr = Jupiter::Socket::getAddrInfo(addr, result);
if (ptr == nullptr) return nullptr;
return Jupiter::Socket::resolveHostname_alloc(ptr);
}
char *Jupiter::Socket::resolveHostname(const char *hostname, unsigned int result) // static
{
addrinfo *info = Jupiter::Socket::getAddrInfo(hostname, 0);
@ -342,6 +356,13 @@ char *Jupiter::Socket::resolveHostname(const char *hostname, unsigned int result
return Jupiter::Socket::resolveHostname(info, result);
}
char *Jupiter::Socket::resolveHostname_alloc(const char *hostname, unsigned int result) // static
{
addrinfo *info = Jupiter::Socket::getAddrInfo(hostname, 0);
if (info == nullptr) return nullptr;
return Jupiter::Socket::resolveHostname_alloc(info, result);
}
uint32_t Jupiter::Socket::pton4(const char *str)
{
in_addr r;

4
Jupiter/Socket.h

@ -126,11 +126,13 @@ namespace Jupiter
/**
* @brief Resolves an address to a hostname. (Reverse DNS)
* Note: the '_alloc' version of this does NOT use a static buffer.
*
* @param addr Address info containing IP address.
* @return String containing the hostname of the stored address on success, nullptr otherwise.
*/
static char *resolveHostname(addrinfo *addr);
static char *resolveHostname_alloc(addrinfo *addr);
/**
* @brief Resolves an address to a hostname. (Reverse DNS)
@ -140,6 +142,7 @@ namespace Jupiter
* @return String containing the hostname of the stored address on success, nullptr otherwise.
*/
static char *resolveHostname(addrinfo *addr, unsigned int result);
static char *resolveHostname_alloc(addrinfo *addr, unsigned int result);
/**
* @brief Resolves an address to a hostname. (Reverse DNS)
@ -149,6 +152,7 @@ namespace Jupiter
* @return String containing the hostname of the resolved address on success, nullptr otherwise.
*/
static char *resolveHostname(const char *hostname, unsigned int result);
static char *resolveHostname_alloc(const char *hostname, unsigned int result);
/**
* @brief Reinterprets an IPv4 address as a 32-bit integer in network byte order.

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save