SSL Test pt. 2
This commit is contained in:
parent
fd62679c25
commit
f30eeffc90
@ -17,12 +17,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#ifdef IBM
|
|
||||||
#endif
|
|
||||||
#ifdef APL
|
|
||||||
#endif
|
|
||||||
#ifdef LIN
|
#ifdef LIN
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
@ -44,6 +41,8 @@ class Socket
|
|||||||
|
|
||||||
#ifdef LIN
|
#ifdef LIN
|
||||||
void logSSL();
|
void logSSL();
|
||||||
|
void *getSinAddr(addrinfo *addr);
|
||||||
|
in_addr_t resolveHost(const char *host);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -21,7 +21,7 @@ Socket::Socket(std::string url, std::function<void(const std::string)> toLog)
|
|||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sin_family = AF_INET;
|
sa.sin_family = AF_INET;
|
||||||
sa.sin_addr.s_addr =
|
sa.sin_addr.s_addr =
|
||||||
inet_addr("136.243.123.153"); // address of german-airlines.de
|
resolveHost("german-airlines.de"); // address of german-airlines.de
|
||||||
sa.sin_port = htons(443);
|
sa.sin_port = htons(443);
|
||||||
socklen_t socklen = sizeof(sa);
|
socklen_t socklen = sizeof(sa);
|
||||||
if (connect(s, (struct sockaddr *)&sa, socklen)) {
|
if (connect(s, (struct sockaddr *)&sa, socklen)) {
|
||||||
@ -58,11 +58,15 @@ Socket::Socket(std::string url, std::function<void(const std::string)> toLog)
|
|||||||
|
|
||||||
Socket::~Socket()
|
Socket::~Socket()
|
||||||
{
|
{
|
||||||
// PLATFORM AGNOSTIC
|
|
||||||
#ifdef IBM
|
#ifdef IBM
|
||||||
// WSA DEINIT
|
// WSA DEINIT
|
||||||
int a = 0;
|
int a = 0;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef LIN
|
||||||
|
close(sock);
|
||||||
|
SSL_shutdown(ssl);
|
||||||
|
SSL_free(ssl);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::sendData(data d)
|
void Socket::sendData(data d)
|
||||||
@ -102,4 +106,53 @@ void Socket::logSSL()
|
|||||||
toLog(str);
|
toLog(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *Socket::getSinAddr(addrinfo *addr)
|
||||||
|
{
|
||||||
|
switch (addr->ai_family) {
|
||||||
|
case AF_INET:
|
||||||
|
return &(reinterpret_cast<sockaddr_in *>(addr->ai_addr)->sin_addr);
|
||||||
|
case AF_INET6:
|
||||||
|
return &(reinterpret_cast<sockaddr_in6 *>(addr->ai_addr)->sin6_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_addr_t Socket::resolveHost(const char *host)
|
||||||
|
{
|
||||||
|
addrinfo hints = {};
|
||||||
|
hints.ai_flags = AI_CANONNAME;
|
||||||
|
hints.ai_family = AF_INET;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
|
|
||||||
|
addrinfo *res;
|
||||||
|
|
||||||
|
int ret = getaddrinfo(host, NULL, &hints, &res);
|
||||||
|
if (ret != 0) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "getaddrinfo() failed: " << gai_strerror(ret);
|
||||||
|
toLog(msg.str());
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << res->ai_canonname;
|
||||||
|
toLog(msg.str());
|
||||||
|
|
||||||
|
in_addr_t retVal = 0;
|
||||||
|
|
||||||
|
for (addrinfo *addr = res; addr != NULL; addr = addr->ai_next) {
|
||||||
|
if (addr->ai_family == AF_INET) {
|
||||||
|
retVal =
|
||||||
|
(reinterpret_cast<sockaddr_in *>(addr->ai_addr))->sin_addr.s_addr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
freeaddrinfo(res);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user