summaryrefslogtreecommitdiff
path: root/src/user/app/ethdump/ipv4.c
diff options
context:
space:
mode:
authordzwdz2022-08-21 14:02:55 +0200
committerdzwdz2022-08-21 14:02:55 +0200
commitb372b0c3c86b1744c1620515a7bbe894a390feae (patch)
tree37359b310e46b866c3cacf0cb910a1f50c8f7465 /src/user/app/ethdump/ipv4.c
parentc1133dc8c7a62dc36e2592e112f34f410dfe84f2 (diff)
user/ethdump: replace most of the _start/_finish pairs with _send
Diffstat (limited to 'src/user/app/ethdump/ipv4.c')
-rw-r--r--src/user/app/ethdump/ipv4.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/user/app/ethdump/ipv4.c b/src/user/app/ethdump/ipv4.c
index 93dd98a..fda0c0c 100644
--- a/src/user/app/ethdump/ipv4.c
+++ b/src/user/app/ethdump/ipv4.c
@@ -183,15 +183,17 @@ void ipv4_parse(const uint8_t *buf, size_t len, struct ethernet ether) {
}
}
-// TODO just have a single *_send function, this is getting ridiculous
-uint8_t *ipv4_start(size_t len, struct ipv4 ip) {
+void ipv4_send(const void *payload, size_t len, struct ipv4 ip) {
+ size_t hdrlen = 20;
+
ip.e.type = ET_IPv4;
if (!ip.src) ip.src = state.ip;
if (!ip.e.dst && ip.dst == 0xFFFFFFFF)
ip.e.dst = &MAC_BROADCAST;
- size_t hdrlen = 20;
- uint8_t *pkt = ether_start(len + hdrlen, ip.e);
+ // TODO output fragmentation
+
+ uint8_t *pkt = ether_start(hdrlen + len, ip.e);
pkt[Version] = 0x40;
pkt[HdrLen] |= hdrlen / 4;
nput16(pkt + TotalLen, len + hdrlen);
@@ -199,12 +201,7 @@ uint8_t *ipv4_start(size_t len, struct ipv4 ip) {
pkt[Proto] = ip.proto;
nput32(pkt + SrcIP, ip.src);
nput32(pkt + DstIP, ip.dst);
-
nput16(pkt + Checksum, ip_checksum(pkt, hdrlen));
-
- return pkt + hdrlen;
-}
-void ipv4_finish(uint8_t *pkt) {
- // TODO output fragmentation
- ether_finish(pkt - 20);
+ memcpy(pkt + hdrlen, payload, len);
+ ether_finish(pkt);
}