diff --git a/CMakeLists.txt b/CMakeLists.txt index 32c9999..5bb56d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,4 +3,4 @@ project(qotd C) set(CMAKE_C_STANDARD 99) -add_executable(qotd main.c quote.c quote.h server.c server.h) \ No newline at end of file +add_executable(qotd main.c quote.c quote.h server.c server.h config.h) \ No newline at end of file diff --git a/config.h b/config.h new file mode 100644 index 0000000..9083199 --- /dev/null +++ b/config.h @@ -0,0 +1,12 @@ +// +// Created by k0rb4k on 26/11/2021. +// + +#ifndef QOTD_CONFIG_H +#define QOTD_CONFIG_H + +#define QUOTES_FILE "./quotes.txt" +#define MESSAGE_STRING_LENGTH 2048 +#define DEFAULT_LISTEN_PORT 17 // should be 17 to be RFC compliant + +#endif //QOTD_CONFIG_H diff --git a/quote.c b/quote.c index 5c746b4..9645269 100644 --- a/quote.c +++ b/quote.c @@ -3,6 +3,7 @@ // #include "quote.h" +#include "config.h" void getRandomQuote(char quote[2048]) { int lineCount; diff --git a/quote.h b/quote.h index fba8603..b7deeda 100644 --- a/quote.h +++ b/quote.h @@ -11,8 +11,6 @@ #include #include -#define QUOTES_FILE "./quotes.txt" - void getRandomQuote(char quote[2048]); void getQuote(long line, char quote[2048]); diff --git a/server.c b/server.c index e715820..d753a20 100644 --- a/server.c +++ b/server.c @@ -3,6 +3,7 @@ // #include "server.h" +#include "config.h" //TODO: object-like C @@ -71,7 +72,7 @@ void server(int tcp, int ipv6) { if (ipv6) { serverAddress6.sin6_family = AF_INET6; serverAddress6.sin6_addr = in6addr_any; - serverAddress6.sin6_port = htons(17); + serverAddress6.sin6_port = htons(DEFAULT_LISTEN_PORT); serverAddress = (struct sockaddr *) &serverAddress6; serverAddressLength = sizeof serverAddress6; @@ -81,7 +82,7 @@ void server(int tcp, int ipv6) { } else { serverAddress4.sin_family = AF_INET; serverAddress4.sin_addr.s_addr = INADDR_ANY; - serverAddress4.sin_port = htons(17); + serverAddress4.sin_port = htons(DEFAULT_LISTEN_PORT); serverAddress = (struct sockaddr *) &serverAddress4; serverAddressLength = sizeof serverAddress4; diff --git a/server.h b/server.h index 2d133e7..5f4a381 100644 --- a/server.h +++ b/server.h @@ -17,8 +17,6 @@ #include "quote.h" -#define MESSAGE_STRING_LENGTH 2048 - void server(int tcp, int ipv6); void tcpListen(int serverSocket, struct sockaddr *clientAddress, unsigned long addressLength);