diff --git a/fiche.c b/fiche.c index c0bbe8d..7fad059 100644 --- a/fiche.c +++ b/fiche.c @@ -26,6 +26,8 @@ Use netcat to push text - example: ------------------------------------------------------------------------------- */ +#define _GNU_SOURCE + #include "fiche.h" #include @@ -46,7 +48,7 @@ Use netcat to push text - example: #include #include #include -#include +#include /****************************************************************************** @@ -495,7 +497,7 @@ static void dispatch_connection(int socket, Fiche_Settings *settings) { } // Set timeout for accepted socket - const struct timeval timeout = { 5, 0 }; + const struct timeval timeout = { 0, 500 }; if ( setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) != 0 ) { print_error("Couldn't set a timeout!"); @@ -655,11 +657,12 @@ static void *handle_connection(void *args) { // Create an url (additional byte for slash and one for new line) const size_t len = strlen(c->settings->domain) + strlen(slug) + 3; - char url[len]; - snprintf(url, len, "%s%s%s%s", c->settings->domain, "/", slug, "\n"); + char *url; + asprintf(&url, "%s%s%s%s", c->settings->domain, "/", slug, "\n"); // Send the response - write(c->socket, url, len); + write(c->socket, url, len - 1); + free(url); } print_status("Received %d bytes, saved to: %s.", r, slug);