A2osX/BIN/RPCDUMP.S.txt
2023-11-12 14:20:15 +01:00

262 lines
5.4 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF bin/rpcdump
*--------------------------------------
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/eth.i
.INB inc/libtcpip.i
.INB inc/net.tcpip.i
*--------------------------------------
TIMEOUT.MAX .EQ 40 40*100ms = 4 sec.
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPIPCfgPtr .BS 2
ZPFrameBase .BS 2
ZS.END .ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA #S.PS.F.EVENT
.DA #0
.DA CS.END-CS.START Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
.DA #16 SS
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
L.Socket .DA Socket
L.Socket.Dst.Addr .DA Socket.Dst.Addr
L.RPC.Request .DA RPC.Request
L.MSG.USAGE .DA MSG.USAGE
L.MSG.UNKNOWN .DA MSG.UNKNOWN
L.MSG.TIMEOUT .DA MSG.TIMEOUT
L.MSG.DUMP0 .DA MSG.DUMP0
L.MSG.DUMP1 .DA MSG.DUMP1
.DA 0
*--------------------------------------
CS.INIT ldy #S.PS.ARGC
lda (pPS),y
beq .99
>LDYA L.LIBTCPIP
>SYSCALL LoadLib
sta hLIBTCPIP
>LIBCALL hLIBTCPIP,LIBTCPIP.GETCFG is TCPIP loaded ?
bcs .99
>STYA ZPIPCfgPtr
lda (ZPIPCfgPtr) Configured ?
bpl .99
ldx #3
ldy #S.IPCFG.IP+3
.1 lda (ZPIPCfgPtr),y
sta Socket.Src.Addr,x
dey
dex
bpl .1
clc
rts
.99 >LDYA L.MSG.USAGE
>SYSCALL PutS
lda #E.SYN
sec
rts
*--------------------------------------
CS.RUN jsr Init.TimeOut
.1 >PUSHW L.Socket.Dst.Addr
lda #1
>SYSCALL ArgV
>PUSHYA
>LIBCALL hLIBTCPIP,LIBTCPIP.HST.GetByName
bcc .2
>SLEEP
jsr Wait.TimeOut
bcc .1
lda #1
>SYSCALL ArgV
>PUSHYA
>PUSHBI 2
>LDYA L.MSG.UNKNOWN
>SYSCALL PrintF
sec
rts
.2 >PUSHW L.Socket
>LIBCALL hLIBTCPIP,LIBTCPIP.Socket
bcs .91
>STA.G hSocket
ldx #3
.21 lda A2osX.T16,x
sta RPC.Request,x
dex
bpl .21
.3 >PUSHWI RPC.Request.End-RPC.Request
>PUSHW L.RPC.Request
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Send
bcc .4
>SLEEP
jsr Wait.TimeOut
bcc .3
.91 bra .99
.4 jsr Init.TimeOut
.5 >LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Recv
bcc .6
>SLEEP
jsr Wait.TimeOut
bcc .5
bra .99
.6 ldy #hFrame
sta (pData),y
>SYSCALL GetMemPtr
>STYA ZPFrameBase
jsr DumpRPCFrame
ldy #hFrame
lda (pData),y
>SYSCALL FreeMem
lda #0
sec
rts
.99 lda #1
>SYSCALL ArgV
>PUSHYA
>PUSHBI 2
>LDYA L.MSG.TIMEOUT
>SYSCALL PrintF
sec
rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
ldy #TimeOut
lda (pData),y
beq .9
dec
sta (pData),y
.9 sec do not discard TIMER event
rts
*--------------------------------------
CS.QUIT ldy #hSocket
lda (pData),y
beq .1
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
.1 lda hLIBTCPIP
beq .8
>SYSCALL UnloadLib
.8 clc
rts
*--------------------------------------
Init.TimeOut ldy #TimeOut
lda #TIMEOUT.MAX
sta (pData),y
rts
*--------------------------------------
Wait.TimeOut sec
ldy #TimeOut
lda (pData),y
beq .9
clc
.9 rts
*--------------------------------------
DumpRPCFrame lda #S.UDP+24
clc
adc ZPFrameBase
sta ZPFrameBase
lda /S.UDP+24
adc ZPFrameBase+1
sta ZPFrameBase+1
>LDYA L.MSG.DUMP0
>SYSCALL PutS
.1 ldy #3
lda (ZPFrameBase),y Value follows?
beq .9
ldy #18 port
>PUSHB (ZPFrameBase),y
iny
>PUSHB (ZPFrameBase),y
ldy #15 proto
>PUSHB (ZPFrameBase),y
ldy #11 version
>PUSHB (ZPFrameBase),y
ldy #4 program
.7 >PUSHB (ZPFrameBase),y
iny
cpy #8
bne .7
>PUSHBI 8
>LDYA L.MSG.DUMP1
>SYSCALL PrintF
lda #20
clc
adc ZPFrameBase
sta ZPFrameBase
bcc .1
inc ZPFrameBase+1
bra .1
.9 rts
*--------------------------------------
CS.END
LIBTCPIP .AZ "libtcpip"
hLIBTCPIP .BS 1
MSG.USAGE .AZ "Usage : RPCDUMP <ip|host>"
MSG.UNKNOWN .AZ "%s: Unknown host\r\n"
MSG.TIMEOUT .AZ "No response from %s\r\n"
MSG.DUMP0 .AZ "Program Ver Proto:Port"
MSG.DUMP1 .AZ "%10L %2d %2d:%D\r\n"
*--------------------------------------
Socket .DA #S.SOCKET.T.DGRAM
.BS 3
Socket.Src.Addr .BS 4
Socket.Src.Port .DA 0 Dynamic
Socket.Dst.Addr .BS 4
Socket.Dst.Port .DA UDP.PORT.PMAP
*--------------------------------------
RPC.Request .BS 4 XID
.HS 00000000 0=CALL
.HS 00000002 RPCVERS
.HS 000186A0 PROG=portmapper
.HS 00000002 VERS
.HS 00000004 PMAPPROC_DUMP
.HS 00000000 CRED
.HS 00000000
.HS 00000000 VERF
.HS 00000000
RPC.Request.End .EQ *
*--------------------------------------
.DUMMY
.OR 0
DS.START
hSocket .BS 1
hFrame .BS 1
TimeOut .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE usr/src/bin/rpcdump.s
ASM