summaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/net.c b/src/net.c
index b5edc07..4d41d6f 100644
--- a/src/net.c
+++ b/src/net.c
@@ -9,6 +9,7 @@
#include <poll.h>
#include <errno.h>
#include <netdb.h>
+#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -20,7 +21,7 @@ void invalid_pkt(peer *from, str pkt)
{
// TODO: maybe inform peer about failure? not sure
// FIXME: hexdumping a gazillon bytes to stderr might be an issue
- fprintf(stderr, "invalid pkt from %*s: ", PSTR(*from->name));
+ fprintf(stderr, "invalid pkt from %.*s: ", PSTR(*from->name));
for (size_t i = 0; i < pkt.len; i++)
fprintf(stderr, "%02x%c", (uint8_t) pkt.data[i], i+1 == pkt.len ? '\n' : ' ');
}
@@ -103,13 +104,16 @@ void peer_free(peer *p)
static void next_in(peer *p, bool header, size_t len)
{
+ p->in.promised = len;
p->in.header = header;
p->in.len = 0;
- p->in.buffer = malloc(p->in.promised = len);
}
+
static bool peer_in_ready(peer *p)
{
+ assert(p->in.promised > p->in.len);
+
errno = 0;
ssize_t got = read(p->socket, p->in.buffer + p->in.len, p->in.promised - p->in.len);
if (got <= 0) {