5 #include <openssl/ssl.h>
6 #include <openssl/err.h>
13 #include <arpa/inet.h>
14 #include <netinet/in.h>
15 #include <sys/socket.h>
34 bool Network::initialize() {
37 SSL_load_error_strings();
38 ERR_load_crypto_strings();
42 auto result = WSAStartup(MAKEWORD(2,2), &wsaData);
44 Console::println(
"WinSock2 initialization failed: " + to_string(result));
52 auto hostEnt = gethostbyname(hostname.c_str());
54 if (hostEnt ==
nullptr) {
58 switch (hostEnt->h_addrtype) {
60 if (hostEnt->h_addr_list[0] !=
nullptr) {
62 addr.s_addr = *(uint32_t*)hostEnt->h_addr_list[0];
63 return string(inet_ntoa(addr));
67 if (hostEnt->h_addr_list[0] !=
nullptr) {
68 char ipv6AddressString[46];
69 return string(inet_ntop(AF_INET6, (in6_addr*)hostEnt->h_addr_list[0], ipv6AddressString, INET6_ADDRSTRLEN) == NULL?
"":ipv6AddressString);
Base exception class for network exceptions.
Base class of network sockets.
static const string getIpByHostname(const string &hostname)
Get IP by hostname.