diff options
Diffstat (limited to 'src/user/app/ethdump/icmp.c')
-rw-r--r-- | src/user/app/ethdump/icmp.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/user/app/ethdump/icmp.c b/src/user/app/ethdump/icmp.c index 94f718e..e23ab01 100644 --- a/src/user/app/ethdump/icmp.c +++ b/src/user/app/ethdump/icmp.c @@ -13,25 +13,21 @@ void icmp_parse(const uint8_t *buf, size_t len, struct ipv4 ip) { uint8_t type = buf[Type]; if (type == 8 && ip.dst == state.ip) { /* echo reply */ - uint8_t *pkt = icmp_start(len - Payload, (struct icmp){ + icmp_send(buf + Payload, len - Payload, (struct icmp){ .type = 0, .ip.dst = ip.src, .ip.e.dst = ip.e.src, }); - memcpy(pkt, buf + Payload, len - Payload); - icmp_finish(pkt, len - Payload); } } -uint8_t *icmp_start(size_t len, struct icmp i) { +void icmp_send(const void *payload, size_t len, struct icmp i) { i.ip.proto = 1; - uint8_t *pkt = ipv4_start(Payload + len, i.ip); + uint8_t *pkt = malloc(Payload + len); pkt[Type] = i.type; pkt[Code] = i.code; - return pkt + Payload; -} -void icmp_finish(uint8_t *pkt, size_t len) { - pkt -= Payload; + memcpy(pkt + Payload, payload, len); nput16(pkt + Checksum, ip_checksum(pkt, Payload + len)); - ipv4_finish(pkt); + ipv4_send(pkt, Payload + len, i.ip); + free(pkt); } |