summaryrefslogtreecommitdiff
path: root/src/main.c
blob: b142fd57217b655946a13c552714edfc5eb38f95 (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
#include "server/server.h"

#include <stdlib.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;
}