/** * Jingga * * @copyright Jingga * @license OMS License 2.0 * @version 1.0.0 * @link https://jingga.app */ #ifndef TOS_PLATFORM_WIN32_SERVER_H #define TOS_PLATFORM_WIN32_SERVER_H #include #include #include #include #include #include "../../network/SocketConnection.h" #include "../../utils/EndianUtils.h" #pragma comment(lib, "Ws2_32.lib") void socket_server_udp_create(const char* hostname, SocketConnection* con) { WSADATA wsaData; // Initialize Winsock if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { return; } // Create socket con->sd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); if (con->sd == INVALID_SOCKET) { WSACleanup(); return; } // Set socket to non-blocking mode u_long mode = 1; if (ioctlsocket(con->sd, FIONBIO, &mode) != NO_ERROR) { closesocket(con->sd); WSACleanup(); return; } // Bind socket con->addr.sin6_family = AF_INET6; con->addr.sin6_addr = in6addr_any; con->addr.sin6_port = SWAP_ENDIAN_BIG(con->port); if (bind(con->sd, (struct sockaddr *) &con->addr, sizeof(con->addr)) == SOCKET_ERROR) { closesocket(con->sd); WSACleanup(); return; } } #endif