diff options
author | dzwdz | 2022-08-21 14:02:55 +0200 |
---|---|---|
committer | dzwdz | 2022-08-21 14:02:55 +0200 |
commit | b372b0c3c86b1744c1620515a7bbe894a390feae (patch) | |
tree | 37359b310e46b866c3cacf0cb910a1f50c8f7465 /src/user/app/ethdump/udp.c | |
parent | c1133dc8c7a62dc36e2592e112f34f410dfe84f2 (diff) |
user/ethdump: replace most of the _start/_finish pairs with _send
Diffstat (limited to 'src/user/app/ethdump/udp.c')
-rw-r--r-- | src/user/app/ethdump/udp.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/user/app/ethdump/udp.c b/src/user/app/ethdump/udp.c index 328f12b..8129a48 100644 --- a/src/user/app/ethdump/udp.c +++ b/src/user/app/ethdump/udp.c @@ -44,18 +44,19 @@ void udpc_close(struct udp_conn *c) { free(c); } void udpc_send(struct udp_conn *c, const void *buf, size_t len) { - uint8_t *pkt = ipv4_start(Payload + len, (struct ipv4){ - .proto = 0x11, - .src = c->lip, - .dst = c->rip, - .e.dst = c->rmac, - }); + uint8_t *pkt = malloc(Payload + len); nput16(pkt + SrcPort, c->lport); nput16(pkt + DstPort, c->rport); nput16(pkt + Length, Payload + len); nput16(pkt + Checksum, 0); memcpy(pkt + Payload, buf, len); - ipv4_finish(pkt); + ipv4_send(pkt, Payload + len, (struct ipv4){ + .proto = 0x11, + .src = c->lip, + .dst = c->rip, + .e.dst = c->rmac, + }); + free(pkt); } @@ -83,13 +84,15 @@ void udp_parse(const uint8_t *buf, size_t len, struct ipv4 ip) { } if (!active) { - uint8_t *pkt = icmp_start(4 + ip.hlen + 8, (struct icmp){ + uint8_t *pkt = malloc(4 + ip.hlen + 8); + nput32(pkt, 0); + memcpy(pkt + 4, ip.header, ip.hlen + 8); + icmp_send(pkt, 4 + ip.hlen + 8, (struct icmp){ .type = 3, /* destination unreachable */ .code = 3, /* port unreachable */ .ip.dst = ip.src, .ip.e.dst = ip.e.src, }); - memcpy(pkt + 4, ip.header, ip.hlen + 8); - icmp_finish(pkt, 4 + ip.hlen + 8); + free(pkt); } } |