diff --git a/.vscode/settings.json b/.vscode/settings.json index 0f61f28..9e6766f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,75 @@ "files.associations": { "assert": "cpp", "zstring": "cpp", - "ostream": "cpp" + "ostream": "cpp", + "cctype": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "bitset": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "format": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "semaphore": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "variant": "cpp", + "__bit_reference": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__verbose_abort": "cpp", + "ios": "cpp", + "locale": "cpp", + "print": "cpp", + "queue": "cpp", + "stack": "cpp" } } \ No newline at end of file diff --git a/Server/src/server.cpp b/Server/src/server.cpp index bda5eb8..4ac3c62 100644 --- a/Server/src/server.cpp +++ b/Server/src/server.cpp @@ -4,5 +4,12 @@ int main() { struct Chattr::Socket_Init sock(AF_INET, SOCK_DGRAM, 0); - std::cout << "Hello, world!" << sock << std::endl; + + struct sockaddr_in serveraddr = {}; + serveraddr.sin_family = AF_INET; + serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); + serveraddr.sin_port = htons(9010); + + sock.bind(sock, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); + std::cout << sock << std::endl; } \ No newline at end of file diff --git a/impl/Socket/Socket_Init.cpp b/impl/Socket/Socket_Init.cpp index 94e2119..832e235 100644 --- a/impl/Socket/Socket_Init.cpp +++ b/impl/Socket/Socket_Init.cpp @@ -9,11 +9,11 @@ Socket_Init::Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t pr #ifdef _WIN32 WSADATA wsa; if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) - log::critical("WSAStartup()", true); + log::critical("WSAStartup()"); #endif sock_ = socket(domain, type, protocol); if (sock_ == INVALID_SOCKET) - log::critical("socket()", true); + log::critical("socket()"); valid_ = true; } @@ -36,4 +36,10 @@ Socket_Init::operator SOCKET() const { return INVALID_SOCKET; }; +void Socket_Init::bind(int __fd, const sockaddr *__addr, socklen_t __len) { + int retVal = ::bind(__fd, __addr, __len); + if (retVal == INVALID_SOCKET) + log::critical("bind()"); +} + } \ No newline at end of file diff --git a/include/Socket/Log.hpp b/include/Socket/Log.hpp index f5479d2..40f1623 100644 --- a/include/Socket/Log.hpp +++ b/include/Socket/Log.hpp @@ -2,6 +2,6 @@ #include "precomp.hpp" namespace Chattr::log { -void critical(gsl::czstring msg, bool bShowDBGMessage); -void error(gsl::czstring msg, bool bShowDBGMessage); +void critical(gsl::czstring msg, bool bShowDBGMessage = true); +void error(gsl::czstring msg, bool bShowDBGMessage = true); } \ No newline at end of file diff --git a/include/Socket/Socket_Init.hpp b/include/Socket/Socket_Init.hpp index 56bf813..7591ac3 100644 --- a/include/Socket/Socket_Init.hpp +++ b/include/Socket/Socket_Init.hpp @@ -8,10 +8,12 @@ public: Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t protocol); ~Socket_Init(); + operator SOCKET() const; + + void bind(int __fd, const sockaddr *__addr, socklen_t __len); + Socket_Init(const Socket_Init&) = delete; Socket_Init& operator=(const Socket_Init&) = delete; - - operator SOCKET() const; private: bool valid_ = false; SOCKET sock_ = INVALID_SOCKET; diff --git a/include/precomp.hpp b/include/precomp.hpp index 43e9640..c330d5f 100644 --- a/include/precomp.hpp +++ b/include/precomp.hpp @@ -2,11 +2,13 @@ #ifdef _WIN32 #include +#include #include #elif __linux__ #include #include #include +#include #define SOCKET int #define INVALID_SOCKET -1 #else