summaryrefslogtreecommitdiff
path: root/src/main.c
blob: 13dae5715fd23d591b97022f9f7f1c87945abc33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "server/server.h"

#include <stdlib.h>
#include <sys/select.h>

#define DEFAULT_PORT 53

static uint16_t get_port(const char* port_str) {
    if (port_str == NULL) {
        return DEFAULT_PORT;
    }

    uint16_t port;
    if ((port = strtoul(port_str, NULL, 10)) == 0) {
        return DEFAULT_PORT;
    }

    return port;
}

int main(void) {

    const char* port_str = getenv("PORT");
    uint16_t port = get_port(port_str);

    Server server;
    server_init(port, &server);
    server_run(&server);
    server_free(&server);
    
    return EXIT_SUCCESS;
}