Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions fiche.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Use netcat to push text - example:
-------------------------------------------------------------------------------
*/

#define _GNU_SOURCE

#include "fiche.h"

#include <stdio.h>
Expand All @@ -46,7 +48,7 @@ Use netcat to push text - example:
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <netinet/tcp.h>


/******************************************************************************
Expand Down Expand Up @@ -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!");
Expand Down Expand Up @@ -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);
Expand Down