From a48fbe86f23cd5ab6d5d925a6141039b3b449ce3 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 27 May 2015 10:48:05 +0200 Subject: [PATCH] minissdpd/testminissdpd.c: improve large buffer support update 122617e5a627e9b06b26764c3dc72bc11acb0b52 --- minissdpd/Changelog.txt | 3 +++ minissdpd/testminissdpd.c | 54 ++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/minissdpd/Changelog.txt b/minissdpd/Changelog.txt index b183806..01b1d6f 100644 --- a/minissdpd/Changelog.txt +++ b/minissdpd/Changelog.txt @@ -1,5 +1,8 @@ $Id: Changelog.txt,v 1.39 2014/12/05 13:42:59 nanard Exp $ +2015/05/27: + support larger buffer size (useful for type 3 requests) + VERSION 1.3: 2014/12/05: diff --git a/minissdpd/testminissdpd.c b/minissdpd/testminissdpd.c index 605bea6..559aa98 100644 --- a/minissdpd/testminissdpd.c +++ b/minissdpd/testminissdpd.c @@ -5,7 +5,6 @@ * copyright (c) 2005-2015 Thomas Bernard * This software is subjet to the conditions detailed in the * provided LICENCE file. */ -#include "config.h" #include #include @@ -94,14 +93,14 @@ main(int argc, char * * argv) char overflow[] = { 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; int s; int i; - unsigned char buf[RESPONSE_BUFFER_SIZE]; - unsigned char chunk[4096]; + void * tmp; + unsigned char * resp = NULL; + size_t respsize = 0; + unsigned char buf[4096]; ssize_t n; - int total = 0; + int total = 0; const char * sockpath = "/var/run/minissdpd.sock"; - printf("Response buffer size %d bytes\n", (int)RESPONSE_BUFFER_SIZE); - for(i=0; i 0) { - memcpy(buf + total, chunk, n); - total += n; - } - break; - } + printf("Number of devices %d\n", (int)buf[0]); + while(n > 0) { + tmp = realloc(resp, respsize + n); + if(tmp == NULL) { + fprintf(stderr, "memory allocation error\n"); + break; + } + resp = tmp; + respsize += n; + if (n > 0) { + memcpy(resp + total, buf, n); + total += n; + } + if (n < (ssize_t)sizeof(buf)) { + break; + } - memcpy(buf + total, chunk, n); - total += n; - n = read(s, chunk, sizeof(chunk)); - printf("response received %d bytes\n", (int)n); - } - printresponse(buf, total); + n = read(s, buf, sizeof(buf)); + printf("response received %d bytes\n", (int)n); + } + if(resp != NULL) { + printresponse(resp, total); + free(resp); + resp = NULL; + } if(n == 0) { close(s); s = connect_unix_socket(sockpath);