diff options
author | dzwdz | 2022-08-23 17:58:42 +0200 |
---|---|---|
committer | dzwdz | 2022-08-23 17:58:42 +0200 |
commit | 03c5dd9462492e291c6a49b88e1cd9ab34d86b6f (patch) | |
tree | 8c8d8e73c8c07b83f5aede18d83671369d0f7589 /src/user/app/netstack/udp.c | |
parent | fcdadf5df39e1d72f9ac79fa384fc6b98be0b1aa (diff) |
user/netstack: TCP listen and close
Diffstat (limited to 'src/user/app/netstack/udp.c')
-rw-r--r-- | src/user/app/netstack/udp.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/user/app/netstack/udp.c b/src/user/app/netstack/udp.c index 46d09de..3d560ae 100644 --- a/src/user/app/netstack/udp.c +++ b/src/user/app/netstack/udp.c @@ -17,14 +17,15 @@ struct udp_conn { void (*on_conn)(struct udp_conn *, void *); /* if non-NULL - listening, if NULL - estabilished */ void (*on_recv)(const void *, size_t, void *); void *carg; - struct udp_conn *next, **prev; + struct udp_conn *next, **link; }; -struct udp_conn *conns; +static struct udp_conn *conns; static void conns_append(struct udp_conn *c) { c->next = conns; - if (c->next) *(c->next->prev) = c; - c->prev = &conns; - *c->prev = c; + if (c->next) + c->next->link = &c->next; + c->link = &conns; + *c->link = c; } void udp_listen( uint16_t port, @@ -79,8 +80,8 @@ void udpc_send(struct udp_conn *c, const void *buf, size_t len) { free(pkt); } void udpc_close(struct udp_conn *c) { - if (c->next) c->next->prev = c->prev; - *(c->prev) = c->next; + if (c->next) c->next->link = c->link; + *(c->link) = c->next; free(c); } @@ -98,10 +99,10 @@ void udp_parse(const uint8_t *buf, size_t len, struct ipv4 ip) { memcpy(&iter->rmac, ip.e.src, sizeof(mac_t)); iter->rip = ip.src; } - if (iter->rip == ip.src - && iter->rport == srcport - && iter->lport == dstport - && iter->on_recv) + if (iter->rip == ip.src && + iter->rport == srcport && + iter->lport == dstport && + iter->on_recv) { active = true; iter->on_recv(buf + Payload, len - Payload, iter->carg); |