mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-28 12:30:58 +00:00
misc todo's and related fixes
This commit is contained in:
1 parent
bfdc14ce0a
commit
3c11521446
6 files changed
+37
-10
No files matched your search
+11
-3
@@ -94,6 +94,13 @@ size_t mg_l2_eth_trailer(struct mg_tcpip_if *ifp, size_t len, uint8_t *cur) {
|
||||
struct mg_l2addr *mg_l2_eth_mapip(enum mg_l2addrtype addrtype,
|
||||
struct mg_addr *addr);
|
||||
|
||||
// Read an unaligned little-endian value from byte pointer p into a native integer.
|
||||
// Safe on architectures that forbid unaligned access (e.g. Cortex-M0).
|
||||
#define MG_LOAD_LE32(p) \
|
||||
((uint32_t) (((uint32_t) MG_U8P(p)[3] << 24U) | \
|
||||
((uint32_t) MG_U8P(p)[2] << 16U) | \
|
||||
((uint32_t) MG_U8P(p)[1] << 8U) | MG_U8P(p)[0]))
|
||||
|
||||
bool mg_l2_eth_rx(struct mg_tcpip_if *ifp, enum mg_l2proto *proto,
|
||||
struct mg_str *pay, struct mg_str *raw) {
|
||||
struct eth *eth = (struct eth *) raw->buf;
|
||||
@@ -119,10 +126,11 @@ bool mg_l2_eth_rx(struct mg_tcpip_if *ifp, enum mg_l2proto *proto,
|
||||
sizeof(eth->dst)) != 0)
|
||||
return false; // TODO(): add multicast addresses
|
||||
if (ifp->enable_fcs_check && len > hdrlen + 4) {
|
||||
uint32_t crc;
|
||||
len -= 4; // TODO(scaprile): check on bigendian
|
||||
uint32_t crc, crc_rx;
|
||||
len -= 4;
|
||||
crc = mg_crc32(0, (const char *) raw->buf, len);
|
||||
if (memcmp((void *) ((size_t) raw->buf + len), &crc, sizeof(crc)))
|
||||
crc_rx = MG_LOAD_LE32(raw->buf + len);
|
||||
if (crc_rx != crc)
|
||||
return false;
|
||||
}
|
||||
pay->buf = ((char *) eth) + hdrlen;
|
||||
|
||||
Reference in new issue
Block a user