-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef IPADDRESS_HPP | ||
#define IPADDRESS_HPP | ||
|
||
#include "Athena/Global.hpp" | ||
#include <string.h> | ||
|
||
#include <cstring> | ||
#include <utility> | ||
|
||
namespace Athena | ||
{ | ||
namespace net | ||
{ | ||
class IPAddress | ||
{ | ||
public: | ||
|
||
static const IPAddress None; | ||
static const IPAddress Any; | ||
static const IPAddress Localhost; | ||
static const IPAddress Broadcast; | ||
|
||
IPAddress() : m_address(~0u), m_valid(false) {} | ||
|
||
IPAddress(const std::string& address); | ||
|
||
IPAddress(atUint8 a, atUint8 b, atUint8 c, atUint8 d); | ||
|
||
IPAddress(atUint32 address); | ||
|
||
const std::string toString() const; | ||
const atUint32 toInt() const; | ||
|
||
static IPAddress localAddress(); | ||
private: | ||
|
||
atUint32 m_address; | ||
bool m_valid; | ||
void resolve(const std::string& address); | ||
}; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef OAUTH_HPP | ||
#define OAUTH_HPP | ||
|
||
#include <Athena/Global.hpp> | ||
|
||
namespace Athena | ||
{ | ||
namespace net | ||
{ | ||
class OAuth | ||
{ | ||
|
||
}; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef SOCKET_HPP | ||
#define SOCKET_HPP | ||
|
||
namespace Athena | ||
{ | ||
namespace net | ||
{ | ||
class Socket | ||
{ | ||
public: | ||
private: | ||
}; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "Athena/IPAddress.hpp" | ||
|
||
#ifdef __unix__ | ||
#include <sys/types.h> | ||
#include <sys/socket.h> | ||
#include <netinet/in.h> | ||
#include <netinet/tcp.h> | ||
#include <arpa/inet.h> | ||
#include <netdb.h> | ||
#include <unistd.h> | ||
#elif defined(_WIN32) | ||
#ifdef _WIN32_WINDOWS | ||
#undef _WIN32_WINDOWS | ||
#endif | ||
#ifdef _WIN32_WINNT | ||
#undef _WIN32_WINNT | ||
#endif | ||
#define _WIN32_WINDOWS 0x0501 | ||
#define _WIN32_WINNT 0x0501 | ||
#include <winsock2.h> | ||
#include <ws2tcpip.h> | ||
#endif | ||
|
||
namespace Athena | ||
{ | ||
namespace net | ||
{ | ||
const IPAddress IPAddress::Any; | ||
const IPAddress IPAddress::None = IPAddress( 0, 0, 0, 0); | ||
const IPAddress IPAddress::Localhost = IPAddress(127, 0, 0, 1); | ||
const IPAddress IPAddress::Broadcast = IPAddress(255, 255, 255, 255); | ||
|
||
IPAddress::IPAddress(const std::string& address) | ||
: m_valid(false) | ||
{ | ||
resolve(address); | ||
} | ||
|
||
IPAddress::IPAddress(atUint8 a, atUint8 b, atUint8 c, atUint8 d) | ||
: m_address(htonl((a << 24)| (b << 16) | (c << 8) | d)), | ||
m_valid(true) | ||
{ | ||
} | ||
|
||
IPAddress::IPAddress(atUint32 address) | ||
: m_address(htonl(address)), | ||
m_valid(true) | ||
{ | ||
} | ||
|
||
const std::string IPAddress::toString() const | ||
{ | ||
in_addr address; | ||
address.s_addr = m_address; | ||
return inet_ntoa(address); | ||
} | ||
|
||
void IPAddress::resolve(const std::string& address) | ||
{ | ||
if (address == "0.0.0.0") | ||
{ | ||
m_address = 0; | ||
m_valid = true; | ||
} | ||
else if(address == "255.255.255.255") | ||
{ | ||
m_address = ~0u; | ||
m_valid = true; | ||
} | ||
else | ||
{ | ||
atUint32 ip = inet_addr(address.c_str()); | ||
if (ip == INADDR_NONE) | ||
{ | ||
addrinfo hints = {0}; | ||
hints.ai_family = AF_INET; | ||
addrinfo* result = nullptr; | ||
if (getaddrinfo(address.c_str(), NULL, &hints, &result)) | ||
{ | ||
if (result) | ||
{ | ||
ip = reinterpret_cast<sockaddr_in*>(result->ai_addr)->sin_addr.s_addr; | ||
freeaddrinfo(result); | ||
m_address = ip; | ||
m_valid = true; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
m_address = ip; | ||
m_valid = true; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "Athena/OAuth.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "Athena/Socket.hpp" |