summaryrefslogtreecommitdiff
path: root/src/cmd/netstack
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/netstack')
-rw-r--r--src/cmd/netstack/udp.c11
-rw-r--r--src/cmd/netstack/util.h12
2 files changed, 19 insertions, 4 deletions
diff --git a/src/cmd/netstack/udp.c b/src/cmd/netstack/udp.c
index 285af41..3b53b47 100644
--- a/src/cmd/netstack/udp.c
+++ b/src/cmd/netstack/udp.c
@@ -55,10 +55,13 @@ struct udp_conn *udpc_new(
c->lport = u.src ? u.src : 50000; // TODO randomize source ports
c->rport = u.dst;
if (arpcache_get(c->rip, &c->rmac) < 0) {
- // TODO make arp request, wait for reply
- warnx("IP not in ARP cache, unimplemented");
- free(c);
- return NULL;
+ // TODO wait for ARP reply
+ arp_request(c->rip);
+ if (arpcache_get(state.gateway, &c->rmac) < 0) {
+ warnx("neither target nor gateway not in ARP cache, dropping");
+ free(c);
+ return NULL;
+ }
}
c->on_recv = on_recv;
c->carg = carg;
diff --git a/src/cmd/netstack/util.h b/src/cmd/netstack/util.h
index c1032a2..1cd22fb 100644
--- a/src/cmd/netstack/util.h
+++ b/src/cmd/netstack/util.h
@@ -40,3 +40,15 @@ static inline uint32_t nget32(const void *vbuf) {
| (b[2] << 8)
| (b[3] << 0);
}
+
+static inline uint64_t nget64(const void *vbuf) {
+ const uint8_t *b = vbuf;
+ return ((uint64_t)b[0] << 56)
+ | ((uint64_t)b[1] << 48)
+ | ((uint64_t)b[2] << 40)
+ | ((uint64_t)b[3] << 32)
+ | ((uint64_t)b[4] << 24)
+ | ((uint64_t)b[5] << 16)
+ | ((uint64_t)b[6] << 8)
+ | ((uint64_t)b[7] << 0);
+}