config.h config file to centralize default values
This commit is contained in:
parent
79830a9745
commit
b869bbbc27
@ -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)
|
||||
add_executable(qotd main.c quote.c quote.h server.c server.h config.h)
|
||||
12
config.h
Normal file
12
config.h
Normal file
@ -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
|
||||
1
quote.c
1
quote.c
@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include "quote.h"
|
||||
#include "config.h"
|
||||
|
||||
void getRandomQuote(char quote[2048]) {
|
||||
int lineCount;
|
||||
|
||||
2
quote.h
2
quote.h
@ -11,8 +11,6 @@
|
||||
#include <bits/types/FILE.h>
|
||||
#include <bits/types/struct_FILE.h>
|
||||
|
||||
#define QUOTES_FILE "./quotes.txt"
|
||||
|
||||
void getRandomQuote(char quote[2048]);
|
||||
|
||||
void getQuote(long line, char quote[2048]);
|
||||
|
||||
5
server.c
5
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;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user