libeech

BitTorrent library
git clone git://z3bra.org/libeech.git
Log | Files | Refs | README | LICENSE

commit acf33003428d73d519a5eacafcbb855c2eb6e3c2
parent af81ef0e03792a5408783394c1d9bc29dcc0ff0b
Author: z3bra <willy at mailoo dot org>
Date:   Mon Jul  2 18:17:00 +0200

Fix initial offset when reading data

Diffstat:
libeech.c | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libeech.c b/libeech.c @@ -18,8 +18,8 @@ #include "util.h" #include "libeech.h" -/* return a 4 byte array as a 32 bit integer */ -#define U32(s) ((uint32_t)(((s)[0]&0xff)<<24|((s)[1]&0xff)<<16|((s)[2]&0xff)<<8|((s)[3]&0xff))) +/* Cast a 4 byte array as a 32 bit integer */ +#define U32(s) (((uint32_t *)(s))[0]) /* Associate message types with their numerical value */ enum { @@ -400,12 +400,12 @@ pwprecv(struct peer *p) } /* expected message length */ - l = U32(p->rxbuf) + 4; + l = ntohl(U32(p->rxbuf)) + 4; if (l > MSGSIZ || l < 5) return -1; - while ((r = recv(p->fd, p->rxbuf, l - p->rxbufsz, 0)) > 0) + while ((r = recv(p->fd, p->rxbuf + p->rxbufsz, l - p->rxbufsz, 0)) > 0) p->rxbufsz += r; if (r < 0 && errno != EAGAIN)