From 26a2ccb8368a9968b6ec16068ad68dd0edb40641 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 17 Jul 2026 12:54:43 +0200 Subject: net: UDP sockets in the kernel + a DNS resolver (real hostname lookups) Adds UDP to the kernel socket layer on top of the ICMP core: - net_sum() (raw folded sum) split out of net_cksum() so a UDP pseudo-header (src/dst IP + proto + length) can seed the segment checksum. - udp_send: builds IP+UDP with the pseudo-header checksum; NET_BIND sets the local/source port; net_connect sets the peer. - udp_in: demuxes inbound UDP by destination port to the bound socket (net_find_udp), delivers the payload + source addr. Also fixes a real recv bug: net_pump clobbers BC/DE/HL, so the old recv timeout counted in registers and was effectively random. recv now counts in WRAM. New `nslookup HOST` (PROG_NSLOOKUP=28, bank 30): builds a DNS A query and parses the answer (with 0xC0 name-compression) entirely in userland over a UDP socket - the kernel never sees DNS, just UDP. Verified through the bridge NAT: /# nslookup example.com -> example.com -> 172.66.147.243 This gives us name resolution for the TCP/HTTP demo next. --- src/programs.asm | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/programs.asm') diff --git a/src/programs.asm b/src/programs.asm index 854b2d2..9ae7f58 100644 --- a/src/programs.asm +++ b/src/programs.asm @@ -124,6 +124,9 @@ ProgNetd: SECTION "prog_ping", ROMX[$4000], BANK[29] ProgPing: INCBIN "c/ping.bin" +SECTION "prog_nslookup", ROMX[$4000], BANK[30] +ProgNslookup: + INCBIN "c/nslookup.bin" ; ----------------------------------------------------------------------------- ; PROG_SH (bank 3) - the shell, now written in C (c/sh.c): parses >/ program id, searched by sys_lookup. @@ -284,4 +289,6 @@ NameTable:: db PROG_NETD db "ping", 0 db PROG_PING + db "nslookup", 0 + db PROG_NSLOOKUP db 0 -- cgit v1.3.1-sl0p