Category : Network Files
Archive   : PDCLK145.ZIP
Filename : TBLBUILD.ASM

 
Output of file : TBLBUILD.ASM contained in archive : PDCLK145.ZIP
;========================================================================

; Copyright (C) 1991 by [email protected], see file COPYING.

InAdrArpa db 7,"in-addr",4,"arpa",0
Qtype dw 0c00h
Qclass dw 0100h
InAdrArpaLen equ $-InAdrArpa

k16 dw 16
TblSize dw 16
TblSizeLast dw 16*16
TblActive dw 0
TblActLast dw 0
TblWrNext dw 0
TblIpProbe dw 130+256*235, 56+256*0
TblProbeNext dw 0
TblProbIntvl dw 9

TmpTbl dw 0, 0, 0, 0, 0, 0, 0

SegmData equ $
SegIpHwTbl dw 0
SegHwIpTbl dw 0
SegmNamTbl dw 0
SegmNamTbl2 dw 0
TableSegs equ ($-SegmData)/2

Handle dw -1
if DEBUG
NameHwTbl db "hwtbl.tmp", 0
NameIpTbl db "iptbl.tmp", 0
else
NameHwTbl db "hwtbl.txt", 0
NameIpTbl db "iptbl.txt", 0
endif ; DEBUG

MsgTblSize db "Wrote 0 table entries, "
MsgTblAct db "0 active this run.", CR, LF, '$'


;************************************************************************
;* FindIn16Table
;*
;* Input: DS:SI = address of search string key (saved)
;* AX = string length (saved)
;* ES = table segment (saved)
;* BX = table size in bytes
;* Output: ES:BX = table slot address of entry less or equal to key
;* Zero flag if equal to key
;* Destroys: BX, flags
;*
;* Before use, the table must be filled with all ones, except slot 0 which
;* must be filled with zeros. Slot 0 may never be changed.
;************************************************************************

FindIn16Table proc near
push cx
push dx
push di
push bp
mov bp,si
mov cx,bx
xor bx,bx
mov dx,8000h ; find proper 2**x size
FindLenLoop:
cmp dx,cx
jb FindHalfChk ; start binary search
shr dx,1
jmp short FindLenLoop

FindLess:
sub bx,dx
FindGreater:
shr dx,1 ; divide step by two
FindHalfChk:
cmp dx,16 ; step < slot size?
jb FindDone
add bx,dx ; position halfway

mov di,bx
mov si,bp
mov cx,ax
repe cmpsb ; compare strings
ja FindGreater
jb FindLess
FindDone:
mov si,bp
pop bp
pop di
pop dx
pop cx
ret
FindIn16Table endp



;************************************************************************
;* GetHexNums
;************************************************************************

GetHexNums proc near
GetHexNum:
xor dx,dx
GetHexDig:
lodsb
cmp al,'0'
jb GetHexEnd
cmp al,'9'
ja GetHexTst
sub al,'0'
jmp short GetHexConv
GetHexTst:
cmp al,'a'
jb GetHexEnd
cmp al,'f'
ja GetHexEnd
sub al,'a'-10
GetHexConv:
cbw
add ax,dx
mov cx,ax
mul k16
mov dx,ax
jmp short GetHexDig
GetHexEnd:
cmp al,'-'
mov ax,cx
stosb
je GetHexNum
ret
GetHexNums endp



;************************************************************************
;* Ins16ByteSlot
;************************************************************************

Ins16ByteSlot proc near
mov cx,TblSize
push es
pop ds
sub cx,bx
mov si,bx
sub si,2
add si,cx
mov di,si
add di,16
std
shr cx,1
rep movsw
cld
push cs
pop ds
ret
Ins16ByteSlot endp



;************************************************************************
;* FindHostInTbls
;************************************************************************

FindHostInTbls proc near
push dx
push ax

mov es,SegHwIpTbl
mov bx,TblSize
mov ax,10
mov si,bp
call FindIn16Table
jz InitHwMatch

add bx,16
call Ins16byteSlot
mov si,bp
mov cx,10/2
mov di,bx
rep movsw

mov ax,TblSize
stosw
InitHwMatch:
mov es,SegIpHwTbl
mov bx,TblSize
mov ax,10
mov si,bp
sub si,4
call FindIn16Table
jz InitIpMatch

add bx,16
call Ins16byteSlot
mov si,bp
sub si,4
mov cx,10/2
mov di,bx
rep movsw

mov ax,TblSize
stosw
mov ax,' '
stosw
InitIpMatch:
pop ax
pop dx
ret
FindHostInTbls endp



;************************************************************************
;* TableInit
;************************************************************************

TableInit proc near
test Argflags,MAKE_TABLE
jnz TableInit2
ret
TableInit2:
mov bx,(TableSegs-1)*2
mov dx,cs
add dx,1000h
mov ax,' ' ; NamTbl2 must be blanked
TableFF:
mov word ptr SegmData[bx],dx
mov es,dx
add dx,1000h
cmp dx,PspTopMem ; end of free memory?
jbe TableFits

mov al,'M'-'0'
call terminate
TableFits:
mov cx,08000h ; prefill all 64 kb
xor di,di
rep stosw

sub bx,2
mov ax,0ffffh ; IpHwTbl prefill
jns TableFF

xor ax,ax ; zerofill first slot
mov es,SegIpHwTbl
mov cx,16/2
xor di,di
rep stosw

mov es,SegHwIpTbl
mov cx,16/2
xor di,di
rep stosw

push cs
pop es

mov dx,offset NameHwTbl
mov ax,3d02h
int 21h
jc TabInitHw

mov bx,ax
mov ah,3eh
int 21h
jmp TabTstIp
TabInitHw:
mov dx,offset NameHwTbl
xor cx,cx
mov ah,3ch
int 21h
jc TabOpenErr
TabTstIP:
mov dx,offset NameIpTbl
mov ax,3d02h
int 21h
mov Handle,ax
jnc TabRdNext

mov dx,offset NameIpTbl
xor cx,cx
mov ah,3ch
int 21h
jc TabOpenErr
jmp TabRdClOK
TabOpenErr:
mov al,'O'-'0'
call terminate

TabRdNext:
push cs
pop es
mov bx,Handle
mov cx,72
mov dx,offset FileBuf
mov ah,3fh
int 21h
jc TabRdErr

or ax,ax
jz TabRdEof

mov si,offset FileBuf
cmp byte ptr [si],'Z'-040h
je TabRdEof
mov di,offset TmpTbl
mov bp,di
call GetIpNr
jnz TabRdErr

mov si,offset FileBuf+53
call GetHexNums
cmp byte ptr [si],LF
jne TabRdErr

mov si,bp
movsw
movsw

add bp,4
call FindHostInTbls
je InitDup

mov si,offset FileBuf+16
mov di,TblSize
call NamePut
add TblSize,16
InitDup:
push cs
pop es
mov byte ptr FileBuf+72,'$'

mov dx,offset FileBuf
mov ah,9
int 21h
jmp TabRdNext

TabRdErr:
mov al,'R'-'0'
call terminate

TabRdEof:
mov bx,Handle
mov ah,3eh
int 21h
jnc TabRdClOK

mov al,'C'-'0'
call terminate
TabRdClOK:
if DEBUG eq 0
call ProbeIpInit
endif ; not DEBUG
call CurrentTicks
mov TblProbeNext,cx
mov TblWrNext,cx
cmp EchoTarget,0
jnz TableInitRet
or GenFlags,TBL_READY
TableInitRet:
ret
TableInit endp



ProbeIpInit proc near
mov dx,MyNet
mov ax,Mynet+2
mov TblIpProbe,dx
inc ah
mov TblIpProbe+2,ax
ret
ProbeIpInit endp



;************************************************************************
;* TblProbe
;************************************************************************

MsgNeedMask db "Need to know network mask", CR, LF, '$'

TblProbe proc near
cmp InSendAndW,0
jnz TblProbeRet

test GenFlags,TBL_READY
jz TblProbeRet

call CurrentTicks
mov ax,cx
sub ax,TblProbIntvl ; 2 - 9 probes a second
sub ax,TblProbeNext
js TblProbeRet

mov TblProbeNext,cx

mov ax,cx

sub ax,TblWrNext
js TblWrLater

add cx,182*20 ; limit write to once in 200 s
mov TblWrNext,cx

mov ax,TblSize
mov dx,TblActive
cmp dx,TblActLast
ja TblProbeWr

cmp ax,TblSizeLast
jbe TblWrLater
TblProbeWr:
mov TblActLast,dx
mov TblSizeLast,ax
call TableWr
TblWrLater:
test ArgFlags,TBL_PROBE
jnz TblDoProbe
TblProbeRet:
ret

TblDoProbe:
cmp MyMask,0
jne TblProbeChkIntvl
mov dx,offset MsgNeedMask
mov ah,9
int 21h
mov al,'P'-'0'
call Terminate
TblProbeChkIntvl:
cmp TblProbIntvl,2
jbe TblProbMin
dec TblProbIntvl
TblProbMin:

mov dx,TblIpProbe
mov ax,TblIpProbe+2
cmp ax,ArpTabIp2+2 ; end of subnet numbers?
jne TblProbeMore
cmp dx,ArpTabIp1+2
jne TblProbeMore
call ProbeIpInit
TblProbeMore:
call BufAlloc
mov [bx].dTimOutMsg,0 ; we don't require an answer
mov [bx].dTickTimeout,0 ; don't wait
call SendArpReq ; send arp
call BufRelease

add ah,1 ; increment IP #
adc al,0
adc dh,0
adc dl,0
mov TblIpProbe,dx
mov TblIpProbe+2,ax
ret
TblProbe endp



;************************************************************************
;* DoTable
;************************************************************************

DoTable proc near
cmp TblSize,0fff0h
jb $+5
jmp TableRetRel

mov di,[bx].dPtrPhys
mov si,[di]
mov dx,[di+2]
mov ax,[di+4]
call ArpFindHw
mov [bx].dIdxHwDst,di

mov di,[bx].dPtrIp
mov cx,[di].iArpOp
add di,iArpMyHwAd
mov bp,di
add di,Hlen
mov dx,[di]
mov ax,[di+2]
mov [bp-4],dx
mov [bp-4+2],ax
push bx

cmp cx,0200h ; ignore arp REPLIES from hosts
jne DoTabUpdate ; already known (probably a
cmp [bx].dIdxHwDst,ARPMYIDX ; proxy arp gateway)
jne DoTabUpdate

push ax
mov es,SegHwIpTbl
mov si,bp
mov ax,10
mov bx,TblSize
call FindIn16Table ; this Hw+IP addr already known?
pop ax
je DoTabUpdate

push ax
mov si,bp
mov ax,Hlen
mov bx,TblSize
call FindIn16Table ; this Hw addr already known?
pop ax
je TableAnswered
DoTabUpdate:
call FindHostInTbls
jne TableAdd

cmp byte ptr es:[bx+12],' '
je TableNew

cmp byte ptr es:[bx+12],'s'
jb TablePending
dec TblActive
TableNew:
mov byte ptr es:[bx+12],'p'
inc TblActive
jmp short TableAsk
TablePending:
cmp byte ptr es:[bx+12],'p'
jb TableAnswered

inc byte ptr es:[bx+12]
TableAnswered:
push cs
pop es
pop bx
jmp TableRetRel

TableAdd:
mov byte ptr es:[bx+12],'p'
inc TblActive
push dx
push ax
push bx
mov si,bp
add si,Hlen
mov di,TblSize
mov es,SegmNamTbl
call PutIpNum
call BlankUntil16
add TblSize,16
pop bx
pop ax
pop dx
TableAsk:
mov TblProbIntvl,9 ; probe twice a second
mov es,SegIpHwTbl
mov cx,es:[bx+10]
push cx ; save name tbl idx

push cs
pop es

xor ch,ch
mov cl,dh
xor dh,dh
push dx
push cx
mov cl,ah
xor ah,ah
push ax
push cx

mov di,offset FileBuf
mov bl,4
mov PutMinDigits,1
TableNumLoop:
mov si,di
inc di
pop ax
call PutNum
mov [si],dl
dec bl
jnz TableNumLoop

mov si,offset InAdrArpa
mov cx,InAdrArpaLen
rep movsb

mov dx,1234h ; tblbuild udp src port
pop ax ; NsId
mov si,offset FileBuf ; Ns question string
call NsResolve ; ask name for this #
pop bx
TableRetRel:
call BufRelease
TableRet:
ret
DoTable endp



;************************************************************************
;* BlankUntil16 byte boundry
;************************************************************************

BlankUntil16 proc near
mov al,' '
BlankMore:
test di,0fh
jz BlankRet
stosb
jmp short BlankMore
BlankRet:
ret
BlankUntil16 endp



;************************************************************************
;* NamePut from DS:SI to TblName[DI]
;************************************************************************

NamePut proc near
mov es,SegmNamTbl
mov cx,16
NamePutLoop:
lodsb
cmp al,CR
je NamePutEnd
stosb
loop NamePutLoop

sub di,16
mov es,SegmNamTbl2
mov cx,16
NamePutLoop2:
lodsb
cmp al,CR
je NamePutEnd2
stosb
loop NamePutLoop2

NamePutEnd2:
call BlankUntil16
jmp short NamePutRet

NamePutEnd:
call BlankUntil16

mov es,SegmNamTbl2
sub di,16
stosb
jmp short NamePutEnd2
NamePutRet:
push cs
pop es
ret
NamePut endp



;************************************************************************
;* ThisIpFirst
;* Input: DI = length prepended IP list
;* BX = IP description buffer pointer
;* Output: Moves source IP # to front of IP list
;************************************************************************

ThisIpFirst proc near
mov si,[bx].dPtrIp
mov dx,[si].iIpSrc
mov ax,[si].iIpSrc+2
mov cl,-1
mov ch,[di] ; list length
ThisIpNext2:
inc di
inc di
ThisIpNext4:
inc cl
cmp cl,ch ; more entries in list?
jae ThisIpRet

xchg ax,dx
scasw ; first IP word match?
xchg ax,dx
jne ThisIpNext2

scasw ; second IP word match?
jne ThisIpNext4

dec di
lea si,[di-4]
std
xor ch,ch
shl cx,1
rep movsw ; move entries downlist
cld
inc si
mov [si],dx ; insert src IP in front
mov [si+2],ax
ThisIpRet:
ret
ThisIpFirst endp


;************************************************************************
;* DoName
;************************************************************************

DoName proc near
test GenFlags,TBL_READY
jnz NameInited

ret
NameInited:
lea si,[di].uNsQuest
mov bp,[di].uNsId
lea di,[di].uNsNscount
mov dx,si
inc dx

BS equ 'H'-040h
call NameDecode
mov word ptr [si],' '
mov word ptr [si+2],BS+256*BS
add si,4

push dx
push si
mov si,dx
call GetIpNr
pop si
pop dx

mov di,[bx].dPtrUdp
cmp [di].uNsAncount,0100h
je NameHaveAns
push dx
jmp short NameNoAnswer
NameHaveAns:
mov di,si
call NameDecode
jnz NameDcCompr
mov dx,di
inc dx
NameDcCompr:
TAB equ 'I'-040h
push dx
mov word ptr [si],TAB+256*'N'
mov word ptr [si+2],'ma'
mov word ptr [si+4],'0e'
mov word ptr [si+6],'00'
mov word ptr [si+8],'=0'
lea di,[si+5]
add si,10
mov ax,bp
mov cl,4
shr ax,cl
mov PutMinDigits,4
call PutNum
mov PutMinDigits,2

mov di,si
call NameDecode
NameNoAnswer:
mov word ptr [si],' '+256*CR
mov word ptr [si+2],LF+256*'$'

mov si,[bx].dPtrUdp
mov ax,[si].uNsNScount
mov dx,[si].uNsNscount+2
xchg ah,al
xchg dh,dl
mov [si].uNsNScount,dx
mov [si].uNsNScount+2,ax
lea si,[si].uNsNScount
push bx
mov bx,TblSize
mov es,SegIpHwTbl
push ax
mov ax,4
call FindIn16Table
pop ax
mov si,bx
pop bx
je NameFound
NameNotFound:
pop dx
mov ah,9
int 21h
mov al,'A'-'0'
call Terminate
NameFound:
mov cx,si
NameFindNxtHi:
cmp bp,es:[si+10]
je NameFoundThis
add si,16
cmp dx,es:[si]
jne NameFindLower
cmp ax,es:[si+2]
je NameFindNxtHi
NameFindLower:
mov si,cx
NameFindNxtLo:
sub si,16
cmp bp,es:[si+10]
je NameFoundThis
cmp dx,es:[si]
jne NameNotFound
cmp ax,es:[si+2]
jne NameNotFound
jmp short NameFindNxtLo
NameFoundThis:
mov bp,[bx].dPtrUdp
mov dx,[bp].uNsAncount
mov ax,[bp].uNsOpwd
and ah,0fh
cmp ah,1 ; format error?
jne NameFmtOK

mov al,'F'-'0'
call terminate
NameFmtOK:
mov byte ptr es:[si+12],'t' ; try again next time

cmp ah,2 ; temporary server problem?
je NameSkipUpd

test al,4 ; authorititive answer?
jz NameTryLater

mov byte ptr es:[si+12],'0' ; we ask no more about this #
NameTryLater:
or ah,ah ; any other error?
jnz NameSkipUpd

cmp dx,0100h ; any answer?
jne NameSkipUpd

mov byte ptr es:[si+12],'N' ; we ask no more about this #
test al,4 ; authorititive answer?
jz NameNotAuth

mov byte ptr es:[si+12],'A' ; we ask no more about this #
NameNotAuth:
mov si,es:[si+10]
xchg si,di
inc si
call NamePut
NameSkipUpd:
push cs
pop es
pop dx
mov ah,9
int 21h

or Events,GOT_NSREPLY
mov di,offset DefNsNum
call ThisIpFirst ; stick to this nameserver
NameRet:
ret
DoName endp



;************************************************************************
;* TabMarkGw
;************************************************************************

TabMarkGw proc near
mov bx,TblSize
mov ds,SegIpHwTbl
TabMarkLoop:
mov si,bx
mov dx,[si]
mov ax,[si+2]
mov cx,cs:DefGwyNum
mov si,offset DefGwys
jcxz TabGwyDone
TabGwyLoop:
cmp ax,cs:[si+2]
jne TabGwyNext
cmp dx,cs:[si]
jne TabGwyNext
mov byte ptr [bx+13],'+'
jmp short TabGwyDone
TabGwyNext:
add si,4
loop TabGwyLoop
TabGwyDone:
sub bx,16
jns TabMarkLoop

mov bx,cs:TblSize
TabDupLoop:
mov si,bx
TabMarkHwLoop:
sub si,16
js TabDupNext

mov ax,[si+4+4]
cmp ax,[bx+4+4]
jne TabMarkHwLoop
mov ax,[si+4+2]
cmp ax,[bx+4+2]
jne TabMarkHwLoop
mov ax,[si+4]
cmp ax,[bx+4]
jne TabMarkHwLoop

cmp byte ptr [si+13],'+'
je TabMarkHwDup

mov byte ptr [si+13],'>'
cmp byte ptr [bx+13],'>'
je TabMarkHwDup

cmp byte ptr [bx+13],'+'
je TabMarkHwLoop

mov byte ptr [bx+13],'='
jmp short TabMarkHwLoop

TabMarkHwDup:
cmp byte ptr [bx+13],'+'
je TabMarkHwLoop

mov byte ptr [bx+13],'>'
jmp short TabMarkHwLoop
TabDupNext:
sub bx,16
jns TabDupLoop

push cs
pop ds
ret
TabMarkGw endp


;************************************************************************
;* TabOpen
;************************************************************************

TabOpen proc near
mov ax,3d02h
int 21h
mov Handle,ax
jnc TabOpenRet
mov al,'B'-'0'
call terminate
TabOpenRet:
ret
TabOpen endp



;************************************************************************
;* TabPutHw
;************************************************************************

TabPutHw proc near
mov ds,cs:SegIpHwTbl
lea si,[bx+4]
call PutHwNum

mov ds,cs:SegIpHwTbl
cmp byte ptr [bx+13],'>'
clc
jne TabPutHwRet

stc

TabPutHwRet:
push cs
pop ds
ret
TabPutHw endp



;************************************************************************
;* TabPutName
;************************************************************************

TabPutName proc near
push bx
mov ds,cs:SegIpHwTbl
mov bx,[bx+10]
mov cx,8
mov ds,cs:SegmNamTbl
mov si,bx
mov dl,[si]
rep movsw
mov cx,8
mov ds,cs:SegmNamTbl2
mov si,bx
rep movsw
mov ax,'# '
stosw

pop bx
push bx
mov ds,cs:SegIpHwTbl
mov si,bx
mov ah,[si+12]
cmp ah,' '
je TabPutNotActive
;*test inc cs:TblActive
TabPutNotActive:
cmp dl,'0'
jb TabPutKnown
cmp dl,'9'
ja TabPutKnown
mov al,'-'
TabPutKnown:
mov dx,[si]
mov cx,[si+2]
cmp dx,[si+16]
jne TabPutNeN
cmp cx,[si+16+2]
jne TabPutNeN
mov al,'='
TabPutNeN:
cmp dx,[si-16]
jne TabPutNeP
cmp cx,[si-16+2]
jne TabPutNeP
mov al,'<'
TabPutNeP:
stosw
mov al,[bx+13]
stosb
pop bx
ret
TabPutName endp



;************************************************************************
;* TabPutIp
;************************************************************************

TabPutIp proc near
mov ds,cs:SegIpHwTbl
mov si,bx
call PutIpNum
ret
TabPutIp endp



;************************************************************************
;* TabWrLine
;************************************************************************

TabWrLine proc near
push bx
mov cx,di
mov dx,offset FileBuf
sub cx,dx
mov bx,Handle
mov ah,40h
int 21h
jnc TabWrOK
TabWrErr:
mov al,'W'-'0'
call terminate
TabWrOK:
pop bx
ret
TabWrLine endp



;************************************************************************
;* TabClose
;************************************************************************

TabClose proc near
mov byte ptr FileBuf,'Z'-40h
mov dx,offset FileBuf
mov cx,1
mov bx,Handle
mov ah,40h
int 21h
jc TabWrErr

mov bx,Handle
mov ah,3eh
int 21h
jnc TabHwClOK

mov al,'C'-'0'
call terminate
TabHwClOK:
ret
TabClose endp



;************************************************************************
;* TableWr
;************************************************************************

TableWr proc near
cmp TblSize,16
ja TableExist
ret

TableExist:
push bx

call TabMarkGw

mov dx,offset NameIpTbl
call TabOpen
mov bx,16
TabIpNext:
mov di,offset FileBuf

call TabPutIp

call BlankUntil16

call TabPutName

push cs:ArgFlags
and cs:ArgFlags, not LANW_TABLE
call TabPutHw
pop ArgFlags

mov ax,CR+256*LF
stosw

call TabWrLine

add bx,16
cmp bx,TblSize
jb TabIpNext

call TabClose

mov dx,offset NameHwTbl
call TabOpen
mov bx,16
;*test mov TblActive,0
TabHwNext:
mov di,offset FileBuf
call TabPutHw
pushf

mov al,' '
stosb
call TabPutName

call TabPutIp

push cs
pop ds
mov ax,CR+256*LF
stosw

popf
;*test jc TabPutHwSkip

call TabWrLine
TabPutHwSkip:
add bx,16
cmp bx,TblSize
jb TabHwNext

call TabClose

pop bx

mov di,offset MsgTblSize+6
mov ax,TblSize
mov cl,4
shr ax,cl
dec ax
call PutNum
mov di,offset MsgTblAct
mov ax,TblActive
call PutNum
mov dx,offset MsgTblSize
mov ah,9
int 21h

ret
TableWr endp

;========================================================================



  3 Responses to “Category : Network Files
Archive   : PDCLK145.ZIP
Filename : TBLBUILD.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/