summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2014-02-07 22:28:03 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2014-02-10 09:02:20 +0100
commit47eb6b50bbcd5dad9718afd5f495a83e37944217 (patch)
treeff4868255490cd657863b3ad48374154e1b9b345 /include
parent4f2f9150b748f278a02c7874e9fc3fd026082581 (diff)
downloadbarebox-47eb6b50bbcd5dad9718afd5f495a83e37944217.tar.gz
barebox-47eb6b50bbcd5dad9718afd5f495a83e37944217.tar.xz
net: net_read_uint32: assert that only 32 bit are read
On some architectures (e.g. alpha, amd64, arm64, ia64, s390x, mips64) sizeof(ulong) is 8 which made net_read_uint32 actually read too much and even returned the wrong value on big endian machines. (Note the second issue isn't that critical though, because the only architecture from the list above that uses big endian byte order is s390x ...) Also change the argument to void * because the pointer is not necessarily properly aligned. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/net.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/include/net.h b/include/net.h
index a4cfec7123..8388e2f12e 100644
--- a/include/net.h
+++ b/include/net.h
@@ -269,11 +269,11 @@ static inline IPaddr_t net_read_ip(void *from)
}
/* return uint32 *in network byteorder* */
-static inline uint32_t net_read_uint32(uint32_t *from)
+static inline uint32_t net_read_uint32(void *from)
{
- ulong l;
- memcpy((void*)&l, (void*)from, sizeof(l));
- return l;
+ uint32_t tmp;
+ memcpy(&tmp, from, sizeof(tmp));
+ return tmp;
}
/* write IP *in network byteorder* */