commit c455885c35c066ca9eaf3f34a020f97f23cadc2e Author: Jezura777 Date: Sun Apr 6 22:29:54 2025 +0200 first commit diff --git a/a.out b/a.out new file mode 100755 index 0000000..97ef108 Binary files /dev/null and b/a.out differ diff --git a/dump.bin b/dump.bin new file mode 100644 index 0000000..8340671 Binary files /dev/null and b/dump.bin differ diff --git a/main.c b/main.c new file mode 100644 index 0000000..2c986c5 --- /dev/null +++ b/main.c @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#include +#include +#include + +#define PORT 8080 +#define BUFFER_SIZE 1024 + +enum PacketTypeClient { + + LOGIN = 0x02 + +}; + +enum PacketTypeServer { + + LOGIN_OK = 0x00 +}; + +struct Packet { + uint8_t type; + union { + struct { + uint16_t padd1; + uint8_t padd2; + wchar_t name[256]; + }; + }; +}; + +int main() { + int server_fd, new_socket; + struct sockaddr_in address; + int opt = 1; + int addrlen = sizeof(address); + char buffer[BUFFER_SIZE]; + + // Create socket file descriptor + if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) { + perror("socket failed"); + exit(EXIT_FAILURE); + } + + // Attach socket to the port + if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) { + perror("setsockopt"); + exit(EXIT_FAILURE); + } + + address.sin_family = AF_INET; + address.sin_addr.s_addr = INADDR_ANY; + address.sin_port = htons(PORT); + + // Bind the socket to the address + if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) < 0) { + perror("bind failed"); + exit(EXIT_FAILURE); + } + + // Start listening for connections + if (listen(server_fd, 3) < 0) { + perror("listen"); + exit(EXIT_FAILURE); + } + +// printf("Server listening on port %d\n", PORT); + + while (1) { + // Accept a new connection + if ((new_socket = accept(server_fd, (struct sockaddr *)&address, (socklen_t*)&addrlen)) < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + // Read data from the socket + ssize_t bytes_read; + struct Packet *p; + // while ((bytes_read = read(new_socket, buffer, BUFFER_SIZE)) > 0) { + while (1) { + bytes_read = read(new_socket, buffer, BUFFER_SIZE); + p = (struct Packet *)&buffer; + printf("type: %x; padd: %x %x", p->type, p->padd1, p->padd2); + fputws(p->name, stdout); + // Print the raw bytes to stdout + //fwrite(buffer, 1, bytes_read, stdout); + fflush(stdout); // Ensure the output is flushed immediately + } + + // Close the socket after reading + close(new_socket); + } + + // Close the server socket (this line will never be reached in this example) + close(server_fd); + return 0; +} +