1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-02-09 19:31:13 +00:00

Prepare for DNS resolution

This commit is contained in:
dschmenk 2015-10-30 14:37:59 -07:00
parent 531f286c5a
commit ce7ae5df49
3 changed files with 48 additions and 17 deletions

View File

@ -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

View File

@ -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

View File

@ -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