summaryrefslogtreecommitdiffstats
path: root/src/daemon/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/net.c')
-rw-r--r--src/daemon/net.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/daemon/net.c b/src/daemon/net.c
index 3b4f022..9180344 100644
--- a/src/daemon/net.c
+++ b/src/daemon/net.c
@@ -94,9 +94,9 @@ int net_init(const unsigned short int port)
state[i].lastreply.tv_sec -= 5;
state[i].nd = i + 1;
state[i].port = port;
- state[i].data = malloc(dgsize);
- memset(state[i].data, 0, dgsize);
- state[i].bufsize = dgsize;
+ state[i].data = malloc(MTU);
+ memset(state[i].data, 0, MTU);
+ state[i].bufsize = MTU;
state[i].status = NONEWDATA;
pthread_mutex_init(&state[i].datamutex, NULL);
@@ -136,16 +136,25 @@ int net_close(int nd)
return ret;
}
-int net_getlastdata(int nd, char * const data)
+int net_getlastdata(int nd, char ** const data)
{
int ret;
if (nd > count || nd < 1 || state[--nd].available) {
ret = ERROR;
} else if (!(ret = state[nd].status)) {
- memcpy(data, state[nd].data, dgsize);
+ if (!data) {
+ ret = ERROR;
+ goto out;
+ } else if (!(*data)) {
+ *data = malloc(MTU);
+ }
+
+ memset(*data, 0, MTU);
+ memcpy(*data, state[nd].data, MTU);
}
+out:
return ret;
}