From ce7ae5df490411d1bbd781684655398f641788a1 Mon Sep 17 00:00:00 2001 From: dschmenk Date: Fri, 30 Oct 2015 14:37:59 -0700 Subject: [PATCH] Prepare for DNS resolution --- src/libsrc/dhcp.pla | 16 +++++++++++---- src/libsrc/etherip.pla | 4 ++-- src/libsrc/inet.pla | 45 +++++++++++++++++++++++++++++++----------- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/libsrc/dhcp.pla b/src/libsrc/dhcp.pla index cb7a336..6932c68 100644 --- a/src/libsrc/dhcp.pla +++ b/src/libsrc/dhcp.pla @@ -26,7 +26,7 @@ struc t_inet word setInterfaceIP word getInterfaceHA word setDNS - word getDNS + word resolveIP end // // Needed to init subnet @@ -78,6 +78,7 @@ byte[4] ones = $FF, $FF, $FF, $FF // // Default static net IP addresses // +byte localdns = 0,0,0,0 byte localgw = 192,168,123,1 byte localip = 192,168,123,10 byte localnet = 255,255,255,0 @@ -101,9 +102,9 @@ byte[128] = 0 // BOOT FILE NAME byte[4] = $63,$82,$53,$63 // MAGIC byte optsDHCP = 53,1,1 // DISCOVER byte = 12, "AppleII" -byte = 55,4 ,1,28,3,42 +byte = 55,4 ,1,3,6,42 byte = 255 -byte optsREQ = 53,1,3 // REQUEST +byte optsREQ = 53,1,3 // REQUEST byte = 50,4,0,0,0,0 // IP requested byte = 54,4,0,0,0,0 // DHCP server byte = 255 @@ -113,6 +114,7 @@ byte = 255 byte offerstr = "DHCP server offering IP address " byte ackstr = "DHCP acknowledge\n" byte boundstr = "Apple II bound to:\n" +byte dnsstr = "DNS: " def putln return putc($0D) end @@ -179,7 +181,7 @@ def parseopts(opts, match) return -1 end def recvDHCP(remip, remport, pkt, len, param) - word optofst, maskopts, gwopts + word optofst, maskopts, gwopts, dnsopts //putip(remip);putc(':');puti(remport);putln //dumpdhcp(pkt) @@ -212,6 +214,10 @@ def recvDHCP(remip, remport, pkt, len, param) if gwopts >= 0 memcpy(@localgw, @pkt->dhcp_opts.[gwopts], IP4ADR_SIZE) fin + dnsopts = parseopts(@pkt->dhcp_opts, 6) + 2 + if dnsopts >= 0 + memcpy(@localdns, @pkt->dhcp_opts.[dnsopts], IP4ADR_SIZE) + fin break otherwise dumpdhcp(pkt) @@ -249,5 +255,7 @@ loop iNet:closeUDP(portDHCP) iNet:setInterfaceIP(@localip, @localnet, @localgw) puts(@boundstr);putip(@localip);putc('/');putip(@localnet);putln +iNet:setDNS(@localdns) +puts(@dnsstr);putip(@localdns);putln done diff --git a/src/libsrc/etherip.pla b/src/libsrc/etherip.pla index ffb6e4f..4fa4d78 100644 --- a/src/libsrc/etherip.pla +++ b/src/libsrc/etherip.pla @@ -29,7 +29,7 @@ struc t_inet word setInterfaceIP word getInterfaceHA word setDNS - word getDNS + word resolveIP end // // Predefine service routine @@ -577,7 +577,7 @@ def getEtherHA(ha) end // -// Fill in Net class +// Fill in iNet class // iNet:serviceIP = @etherServiceIP iNet:openUDP = @etherOpenUDP diff --git a/src/libsrc/inet.pla b/src/libsrc/inet.pla index d0e1d6a..e87cb78 100644 --- a/src/libsrc/inet.pla +++ b/src/libsrc/inet.pla @@ -25,7 +25,7 @@ struc t_inet word setInterfaceIP word getInterfaceHA word setDNS - word getDNS + word resolveIP end // // External interface to net class. Must be first. @@ -39,10 +39,6 @@ byte = "UTHERNET" byte = "" word driver = @netDrivers // -// DHCP module to load -// -byte dhcp = "DHCP" -// // DNS address // byte[4] dns @@ -64,7 +60,7 @@ export def iNetInit // // Get an IP address // - modexec(@dhcp) + modexec("DHCP") return @iNet end @@ -72,12 +68,39 @@ def iNetSetDNS(ipptr) return memcpy(@dns, ipptr, 4) end -def iNetGetDNS(ipptr) - return memcpy(ipptr, @dns, 4) +def parseIP(ipstr, ipaddr) + byte i + word endstr + + endstr = ipstr + ^ipstr + for i = 0 to 3 + ipstr = ipstr + 1 + while ^ipstr >= '0' and ^ipstr <= '9' and ipstr <= endstr + ipaddr->[i] = ipaddr->[i] * 10 + ^ipstr - '0' + ipstr = ipstr + 1 + loop + if ^ipstr <> '.' and ipstr < endstr + return 0 + fin + next + return i == 3 end -iNet:initIP = @iNetInit -iNet:setDNS = @iNetSetDNS -iNet:getDNS = @iNetGetDNS +def iNetResolve(namestr, ipaddr) + ipaddr=>0 = 0 + ipaddr=>2 = 0 + if not parseIP(namestr, ipaddr) + // + // Query Domain Name Server for address + // + fin + return 1 +end + +// +// Fill iNet +iNet:initIP = @iNetInit +iNet:setDNS = @iNetSetDNS +iNet:resolveIP = @iNetResolve done