mirror of
https://github.com/A2osX/A2osX.git
synced 2024-08-27 22:29:18 +00:00
306 lines
5.4 KiB
Plaintext
306 lines
5.4 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
DNS.CLEAR ldx #K.DNSCACHE.SIZE*S.DNSCACHE
|
||
.1 stz DNS.CACHE-1,x
|
||
dex
|
||
bne .1
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* DNS.QUERY
|
||
* In:
|
||
* PULLW = hostname PTR to PSTR
|
||
* PULLW = PTR to IP to fill with cached data
|
||
* Out:
|
||
* CC: hit: IP filled with address
|
||
* CS: missed
|
||
*--------------------------------------
|
||
DNS.QUERY >PULLW ZPPtrDNS Get host string
|
||
>PULLW ZPPtrIP Get IP address to fill
|
||
|
||
DNS.QUERY.I jsr HST.PSTR2DNS.I
|
||
ldx #0
|
||
|
||
.1 lda DNS.CACHE,x
|
||
beq .6 empty DNS cache entry?
|
||
|
||
phx
|
||
lda DNS.CACHE+S.DNSCACHE.hNAME,x
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPPtrDNS
|
||
plx
|
||
|
||
ldy #0
|
||
|
||
.2 lda DNSHostname,y
|
||
bne .21
|
||
lda (ZPPtrDNS),y
|
||
beq .22
|
||
|
||
.21 cmp (ZPPtrDNS),y
|
||
bne .6
|
||
iny
|
||
bne .2
|
||
|
||
.22 lda DNS.CACHE,x get back status...
|
||
bpl .4 Pending...
|
||
|
||
ldy #0
|
||
.3 lda DNS.CACHE+S.DNSCACHE.RDATA,x
|
||
sta (ZPPtrIP),y
|
||
inx
|
||
iny
|
||
cpy #4
|
||
bne .3
|
||
clc
|
||
rts
|
||
|
||
.4 sec
|
||
rts
|
||
|
||
.6 txa
|
||
clc
|
||
adc #S.DNSCACHE
|
||
tax
|
||
cmp #K.DNSCACHE.SIZE*S.DNSCACHE
|
||
bne .1
|
||
*--------------------------------------
|
||
DNS.REQUEST ldx #0
|
||
ldy #12
|
||
|
||
.1 lda DNSHostname,x
|
||
sta DNS.MSG,y
|
||
beq .2
|
||
inx
|
||
iny
|
||
bne .1
|
||
|
||
.2 iny
|
||
lda /S.DNS.QTYPE.A
|
||
sta DNS.MSG,y
|
||
iny
|
||
lda #S.DNS.QTYPE.A
|
||
sta DNS.MSG,y
|
||
|
||
iny
|
||
lda /S.DNS.QCLASS.IN
|
||
sta DNS.MSG,y
|
||
iny
|
||
lda #S.DNS.QCLASS.IN
|
||
sta DNS.MSG,y
|
||
|
||
iny
|
||
tya
|
||
sta DNS.MSG.LEN
|
||
lda #0
|
||
sta DNS.MSG.LEN+1
|
||
|
||
lda hDNSSocket1
|
||
beq .9
|
||
|
||
>LDYA A2osX.RANDOM16
|
||
>STYA DNS.MSG
|
||
|
||
>PUSHW DNS.MSG.LEN
|
||
>PUSHW L.DNS.MSG
|
||
>PUSHB hDNSSocket1
|
||
jsr SKT.SEND
|
||
|
||
lda hDNSSocket2
|
||
beq .9
|
||
|
||
>LDYA A2osX.RANDOM16
|
||
>STYA DNS.MSG+S.DNS.ID
|
||
|
||
>PUSHW DNS.MSG.LEN
|
||
>PUSHW L.DNS.MSG
|
||
>PUSHB hDNSSocket2
|
||
jsr SKT.SEND
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
* DNS.ADD
|
||
* In:
|
||
* PULLW = hostname PSTR to Add
|
||
* PULLW = PTR to IP
|
||
*--------------------------------------
|
||
DNS.ADD >PULLW ZPPtrDNS Get host string
|
||
>PULLW ZPPtrIP Get host IP address
|
||
|
||
jsr HST.PSTR2DNS.I
|
||
|
||
lda #$80
|
||
sta DNSHostTTL+3
|
||
stz DNSHostTTL+2
|
||
stz DNSHostTTL+1
|
||
stz DNSHostTTL
|
||
|
||
lda #S.DNSCACHE.STATUS.RESOLVED
|
||
bra DNS.ADD.I
|
||
|
||
DNS.ADD.PENDING.I
|
||
lda #S.DNSCACHE.STATUS.PENDING
|
||
|
||
DNS.ADD.I sta Status
|
||
ldx #0
|
||
|
||
.1 lda DNS.CACHE,x
|
||
beq DNS.ADD.ENTRY free ?
|
||
|
||
lda DNS.CACHE+S.DNSCACHE.hNAME,x
|
||
phx
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPPtrDNS
|
||
plx
|
||
|
||
ldy #0
|
||
|
||
.2 lda DNSHostname,y
|
||
cmp (ZPPtrDNS),y
|
||
bne .4
|
||
|
||
and #$FF End Of String?
|
||
beq DNS.UPD.ENTRY
|
||
|
||
iny
|
||
bne .2
|
||
|
||
.4 txa
|
||
clc
|
||
adc #S.DNSCACHE
|
||
tax
|
||
cmp #K.DNSCACHE.SIZE*S.DNSCACHE
|
||
bne .1
|
||
|
||
lda DNS.CACHE+S.DNSCACHE.hNAME discard oldest entry hNAME
|
||
>SYSCALL SYS.FreeMemA
|
||
|
||
ldx #K.DNSCACHE.SIZE*S.DNSCACHE-S.DNSCACHE
|
||
|
||
.6 lda DNS.CACHE+S.DNSCACHE-1,x
|
||
sta DNS.CACHE-1,x
|
||
dex
|
||
bne .6
|
||
|
||
ldx #K.DNSCACHE.SIZE*S.DNSCACHE-S.DNSCACHE
|
||
|
||
DNS.ADD.ENTRY phx
|
||
|
||
ldy DNSHostnameLen
|
||
iny add 1 for Ending 00
|
||
lda #0
|
||
>PUSHYA push PSTR len
|
||
>PUSHBI 0 no option
|
||
>SYSCALL SYS.GetMem
|
||
bcc .10
|
||
plx
|
||
rts
|
||
|
||
.10 >STYA ZPPtrDNS
|
||
txa
|
||
plx
|
||
sta DNS.CACHE+S.DNSCACHE.hNAME,x
|
||
|
||
ldy #0
|
||
.1 lda DNSHostname,y
|
||
sta (ZPPtrDNS),y
|
||
iny
|
||
cpy DNSHostnameLen
|
||
bne .1
|
||
|
||
lda #0
|
||
sta (ZPPtrDNS),y
|
||
|
||
DNS.UPD.ENTRY lda Status
|
||
sta DNS.CACHE+S.DNSCACHE.STATUS,x
|
||
bmi .1 pending?
|
||
|
||
* lda DNSMessageID
|
||
* sta DNS.CACHE+S.DNSCACHE.ID,x
|
||
* lda DNSMessageID+1
|
||
* sta DNS.CACHE+S.DNSCACHE.ID+1,x
|
||
|
||
bra .9
|
||
|
||
.1 lda DNSHostTTL
|
||
sta DNS.CACHE+S.DNSCACHE.TTL,x
|
||
lda DNSHostTTL+1
|
||
sta DNS.CACHE+S.DNSCACHE.TTL+1,x
|
||
lda DNSHostTTL+2
|
||
sta DNS.CACHE+S.DNSCACHE.TTL+2,x
|
||
lda DNSHostTTL+3
|
||
sta DNS.CACHE+S.DNSCACHE.TTL+3,x
|
||
|
||
ldy #0
|
||
.2 lda (ZPPtrIP),y
|
||
sta DNS.CACHE+S.DNSCACHE.RDATA,x
|
||
inx
|
||
iny
|
||
cpy #4
|
||
bne .2
|
||
|
||
clc
|
||
rts
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
DNS.GETCACHE >LDYA L.DNS.CACHE
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
DNS.SKTPOLL lda hDNSSocket1
|
||
beq .8
|
||
jsr SKT.RCVDA
|
||
bcs .8
|
||
|
||
bra *
|
||
|
||
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
ldy #S.DNS.F+1
|
||
lda (ZPFrameBase1),y
|
||
and /S.DNS.F.QR
|
||
beq .9
|
||
|
||
ldy #S.DNS.ANCOUNT+1
|
||
lda (ZPFrameBase1),y
|
||
beq .9
|
||
|
||
ldy #S.DNS.QDCOUNT+1
|
||
lda (ZPFrameBase1),y
|
||
tax
|
||
beq .3 no QUERY to skip
|
||
|
||
ldy #S.DNS Read query
|
||
|
||
.1 lda (ZPFrameBase1),y
|
||
beq .2
|
||
iny
|
||
bne .1
|
||
.2 tya
|
||
clc
|
||
adc #4 Skip QTYPE & QCLASS
|
||
tay
|
||
dex skip another QUERY ?
|
||
bne .1
|
||
|
||
.3 iny skip high byte of offset
|
||
iny skip lo byte of offset
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE LIB/LIBTCPIP.S.DNS
|
||
LOAD LIB/LIBTCPIP.S
|
||
ASM
|