tFix initial offset when reading data - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit acf33003428d73d519a5eacafcbb855c2eb6e3c2
(DIR) parent af81ef0e03792a5408783394c1d9bc29dcc0ff0b
(HTM) Author: z3bra <willy at mailoo dot org>
Date: Mon, 2 Jul 2018 18:17:00 +0200
Fix initial offset when reading data
Diffstat:
M libeech.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
---
(DIR) diff --git a/libeech.c b/libeech.c
t@@ -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 {
t@@ -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)