diff options
-rw-r--r-- | plop.c | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -4,7 +4,7 @@ #include <sys/types.h> #include <unistd.h> -int main(int argc, char ** argv) +int make_server(const char * node, const char * service) { struct addrinfo hints = { .ai_family = AF_UNSPEC, @@ -15,14 +15,9 @@ int main(int argc, char ** argv) struct addrinfo * result; struct addrinfo * it; - if (2 != argc) - { - return 4; - } - - if (0 != getaddrinfo(NULL, argv[1], &hints, &result)) + if (0 != getaddrinfo(node, service, &hints, &result)) { - return 1; // TODO: Handle errors properly + return -1; // TODO: Handle errors properly } int server; @@ -42,16 +37,28 @@ int main(int argc, char ** argv) if (it == NULL) { - return 2; // TODO: Handle errors properly + server = -1; // TODO: Handle errors properly } freeaddrinfo(result); - if (-1 == listen(server, 5)) + if (-1 == server || -1 == listen(server, 5)) + { + return -1; // TODO: Handle errors properly + } + + return server; +} + +int main(int argc, char ** argv) +{ + if (2 != argc) { - return 3; // TODO: Handle errors properly + return 4; } + int server = make_server(NULL, argv[1]); + int client; static const char * response = "HTTP/1.1 200 OK\r\n" |