diff --git a/Jupiter/Socket.cpp b/Jupiter/Socket.cpp index 7d40c01..cf8f448 100644 --- a/Jupiter/Socket.cpp +++ b/Jupiter/Socket.cpp @@ -300,6 +300,22 @@ char *Jupiter::Socket::resolveHostname(const char *hostname, unsigned int result return Jupiter::Socket::resolveHostname(info, result); } +uint32_t Jupiter::Socket::pton4(const char *str) +{ + in_addr r; + if (inet_pton(AF_INET, str, &r) <= 0) + return 0; + return *reinterpret_cast(&r); +} + +in_addr6 Jupiter::Socket::pton6(const char *str) +{ + in_addr6 r; + if (inet_pton(AF_INET6, str, &r) <= 0) + memset(&r, 0, sizeof(in_addr6)); + return r; +} + Jupiter::Socket *Jupiter::Socket::acceptConnection() { SOCKET tSock = accept(Socket::data_->rawSock, 0, 0); diff --git a/Jupiter/Socket.h b/Jupiter/Socket.h index b455ca6..06498c0 100644 --- a/Jupiter/Socket.h +++ b/Jupiter/Socket.h @@ -28,6 +28,7 @@ #include "Readable_String.h" struct addrinfo; +struct in_addr6; namespace Jupiter { @@ -163,6 +164,22 @@ namespace Jupiter */ static char *resolveHostname(const char *hostname, unsigned int result); + /** + * @brief Reinterprets an IPv4 address as a 32-bit integer in network byte order. + * + * @param str String representation of an IPv4 address. + * @return IPv4 address in network byte order. + */ + static uint32_t pton4(const char *str); + + /** + * @brief Reinterprets an IPv6 address as a 128-bit integer in network byte order. + * + * @param str String representation of an IPv6 address. + * @return IPv6 address in network byte order. + */ + static in_addr6 pton6(const char *str); + /** * @brief Interface to provide simple connection establishing. * Note: When using this method, the hostname and port are NOT stored; thus getHost(), getHostname(), diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index e93f437..ec0085b 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ