home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / PKTDRVR / PDCLK207.ZIP / PDCLKSRC / PDCLKSET.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-10-09  |  33.3 KB  |  1,615 lines

  1.  
  2. PAGE  44,132
  3.  
  4. ; Copyright (C) 1991 by Jan.Engvald@ldc.lu.se, see file COPYING.
  5.  
  6. ;========================================================================
  7.         include pdclkset.doc
  8. ;========================================================================
  9.  
  10. ESCAPE        equ    27
  11. RFCC        equ    TBLBUILD+PINGCLIENT    ; RFC compliance needed
  12.  
  13. if TBLBUILD
  14. PROGSTR     equ    'pdtbuild'
  15. elseif PINGCLIENT
  16. PROGSTR     equ    'pdclkset'
  17. else
  18. PROGSTR     equ    'pdclksml'
  19. endif ; TBLBUILD
  20.  
  21. IDSTRING    equ    PROGSTR,PRGVERSION
  22.  
  23.  
  24.         include defs.asm
  25.  
  26. ;************************************************************************
  27. ;*        Start of segment (PSP data)                *
  28. ;************************************************************************
  29.  
  30.         .386        ; (to avoid masm expression overflow)
  31.   
  32. code_s        segment use16
  33.         assume    cs:code_s, ds:nothing, ss:code_s, es:nothing
  34.  
  35.         org    0
  36. CodeOrg     label    byte
  37. PspInt20    dw    ?
  38. PspTopMem    dw    ?
  39.  
  40.         org    5Ch            ; PSP can be reused for data from here
  41.  
  42.         org    80h            ; PSP command parameter area  
  43. phd_dioa    db    ?
  44.         db    ?            ; always a space
  45. phd_string    db    ?
  46.  
  47.  
  48. ;************************************************************************
  49. ;*        Start of segment (code)                 *
  50. ;************************************************************************
  51.  
  52.         .8086
  53.         org    100h
  54. StackEnd    equ    $            ; 80h-100h is interupt stack
  55. SaveSP        equ    $
  56. SaveSS        equ    SaveSP+2
  57.  
  58. start:        jmp    start1            ; jump over data area
  59.         nop
  60.  
  61. id_label    db    IDSTRING
  62.  
  63.   
  64. ;************************************************************************
  65. ;*                                    *
  66. ;*        Data area                        *
  67. ;*                                    *
  68. ;************************************************************************
  69.  
  70. NotEnoughMsg    db    LF, "Need to know at least IP nr, Offset and Timeserver$"
  71. OccupiedMsg    db    LF, "My IP nr is already in use by another host with hardware addr "
  72. OccupiedHw    db    "00:00:00:00:00:00$"
  73. MsgNoConect    db    LF, "No response from target host$"
  74. NoBotReplyMsg    db    LF, "No BOOTP reply$"
  75. NoGwyMsg    db    LF, "Need to know a gateway (or wrong mask)$"
  76. NoTimeServMsg    db    LF, "No reply from time server$"
  77.  
  78. usage_msg    db    LF
  79.   db  "Copyright (C) 1991 by Jan.Engvald@ldc.lu.se, see file COPYING.", CR, LF
  80.   db  IDSTRING, ' ', ??date, " usage to set the PC clock from an UDP/IP TIME server:", CR, LF, LF
  81.   db  PROGSTR," [o[ffset]=time]   (time is [-|+][<hours>h][<minutes>m][<seconds>[s]])", CR, LF, LF
  82.   db  "      [d[aylightsave]=PAC | USA | CUB | CHIL | BRZ | GBR |", CR, LF
  83.   db  "                      W_EU | M_EU | E_EU | LIBY | EGY | TURK | ISR |", CR, LF
  84.   db  "                      IRAN | PRC | ROK | AUS | TASM | NSW | LHI | NZE |", CR, LF
  85.   db  "                  FrTime,FrWeekDay,FrDayOfYear,ToTime,ToWday,ToDayOfYr,AddTime]", CR, LF, LF
  86.   db  "      [i[pnr]=n.n.n.n]  [t[imserver]=n.n.n.n[,n.n.n.n[,...]]]", CR, LF, LF
  87.   db  "      [m[ask]=n.n.n.n  g[ateway]=n.n.n.n[,n.n.n.n[,...]]]  [f[lags]=flagnr]", CR, LF, LF
  88.   db  "      [z[onename]= # | variable=normalname,dlsname]  [a[lter]=days,time]", CR, LF, LF
  89.   db  "      [p[ktintno]=hexnr]"
  90.  
  91. if PINGCLIENT or TBLBUILD
  92.   db  "  [e[cho]=name|n.n.n.n [,size,interval[,data,inc,min]]]", CR, LF, LF
  93.   db  "      [n[ameserver]=n.n.n.n[,n.n.n.n[,...]]]"
  94. endif ; PINGCLIENT or TBLBUILD
  95.  
  96.   db  "  [l[ongertimeout]=time]", CR, LF, LF
  97.   db  "Example: ",PROGSTR," o= -1h  d=M_EU  z=#   (my IP nr and timeserver(s) from BOOTP)", CR, LF
  98.   db  "         ",PROGSTR," offs= 6h dst= USA zonename= tz=CST,CDT   (sets TZ=CST or CDT)", CR, LF
  99.   db  "         ",PROGSTR," o=8h  d=PAC  ip=123.45.6.7  ts=123.45.6.8    (BOOTP not used)"
  100.  
  101. if PINGCLIENT
  102.   db  CR, LF, "         ",PROGSTR," pktdrv= 0x7c  echo= ping.lu.se      (ping client)"
  103. endif
  104.  
  105. if TBLBUILD
  106.   db  CR, LF, "         ",PROGSTR," flags= 2+4   (address table builder for LANwatch)"
  107. endif
  108.  
  109. crlf_msg    db    CR, LF, '$'
  110.  
  111. if DEBUG
  112. MsgErrDet    db    CR, LF, 7
  113.         db    " ax   dx   cx   si   ds   bx   di   es   bp "
  114.         db    " addr stack...", CR, LF
  115. MsgErrAdr    db    "0000/0000/0000/0000/0000/0000/0000/0000/0000"
  116.         db    " 0000 0000 0000 0000 0000 0000 0000"
  117. endif ; DEBUG
  118.  
  119. MsgTerm        db    CR, LF, "End of ", IDSTRING, ", error="
  120. MsgTermNr    db    255, ", HWaddr "
  121. MsgTermHw    db    "00:00:00:00:     , IP nr "
  122. MsgMyIp        db    "1.2.3.4        ", CR, LF
  123. MsgTermStop    db    "$", 7, Cr, LF
  124.         db    "Dst entries too old, update and reassemble PDCLKSET", CR, LF, '$'
  125.  
  126.         even
  127. Flagword    dw    0
  128. DONT_SETTIME    equ    1
  129. HAVE_MYIPNR    equ    2
  130. HAVE_TIMEOFFSET equ    4
  131. HAVE_TIMESERVER equ    8
  132.  
  133. HAVE_ENOUGH    equ    HAVE_MYIPNR + HAVE_TIMEOFFSET + HAVE_TIMESERVER
  134. EnoughWord    dw    HAVE_ENOUGH
  135.  
  136. ArgFlags    dw    0
  137. TERM_WAIT    equ    1    ; 0x0001
  138. NOT_SAFE    equ    1    ; 0x0001
  139. MAKE_TABLE    equ    2    ; 0x0002
  140. LANW_TABLE    equ    4    ; 0x0004
  141. TBL_PROBE    equ    8    ; 0x0008
  142. AVOID_HDWR    equ    16    ; 0x0010
  143. MICRO_100    equ    32    ; 0x0020
  144. UDP_DISCARD    equ    64    ; 0x0040
  145. QUIET_TERM    equ    128    ; 0x0080
  146. IP_15DIG    equ    256    ; 0x0100
  147. UPCALL_SEND    equ    512    ; 0x0200
  148. STOP_ON_ERR    equ    1024    ; 0x0400
  149.                                 ; 0x0800
  150. TR_GIANT        equ     4096    ; 0x1000
  151.                                 ; 0x2000
  152. NOT_ALL_MEM    equ    04000h
  153. TEMP_TEST    equ    08000h    ; 0x8000
  154.  
  155.  
  156. MAXTSERVS    equ    4
  157. ARPSLOTS    equ    8 + 4*TBLBUILD
  158. ROUTESLOTS    equ    5
  159. MAXDEFGWYS    equ    4 + 6*TBLBUILD
  160. MAXDEFNS    equ    3
  161.  
  162. ifdef SMALLBUFS
  163. NBUFSMALM    equ    24            ; at least so many small bufs
  164. else
  165. NBUFSMALM    equ    0            ; at least so many small bufs
  166. endif
  167.  
  168.  
  169. ;**********************************************************************
  170. ;*
  171. ;*        End of data area
  172. ;*
  173. ;**********************************************************************
  174.  
  175.         .8086    ; ensure no 386-only instructions
  176.  
  177. MULTIPROCESS    equ    1        ; (the interrupt process counts here)
  178.  
  179. PushfDI     macro
  180. if    MULTIPROCESS
  181.         pushf                ; save enable interrupt flag
  182.         cli                ; and disable interrupt
  183. endif ; MULTIPROCESS
  184.         endm
  185.  
  186. PopfEI        macro
  187. if    MULTIPROCESS
  188.         popf                ; restore enable interrupt flag
  189. endif ; MULTIPROCESS
  190.         endm                ; (probably enabling interrupt)
  191.  
  192.  
  193. if DEBUG ge 3
  194.  
  195. CHK_ES_EQ_DS    macro
  196.         call    ChkEsEqDs
  197.         endm
  198.  
  199. ChkEsEqDs    proc    near
  200.         push    ax
  201.         push    dx
  202.         mov    ax,es
  203.         mov    dx,ds
  204.         cmp    ax,dx
  205.         jne    ChkESeqErr
  206.  
  207.         pop    dx
  208.         pop    ax
  209.         ret
  210. ChkEsEqDs    endp
  211.  
  212.   ChkEsEqErr:
  213.         mov    al,'z'-'0'
  214.         call    Terminate
  215.  
  216. else
  217.  
  218.  
  219. CHK_ES_EQ_DS    macro
  220.         endm
  221.  
  222. endif ; DEBUG ge 3
  223.  
  224.  
  225. If DEBUG ge 2
  226. ; This debug routine destroys no registers and needs only 3 bytes at each
  227. ; place called. It will put on the screen a one-line summary of which events
  228. ; that have ever occured and then some lines with the last sequence of events.
  229.  
  230. MINEVENT        equ     'A'
  231. MAXEVENT        equ     'g'
  232. EVENTCOLOR      equ     3eh
  233. EVENTLINE       equ     8
  234. TRACECOLOR      equ     24h
  235.  
  236. ShowEvent    proc    near
  237. x        =    0
  238.                 rept    (MAXEVENT-MINEVENT+1)
  239.         push    ax
  240.         mov    al,x
  241.         jmp    ShowEventNum
  242. x        =    x+1
  243.         endm
  244.  
  245.   ShowEventNum:
  246.         pushf
  247.         push    di
  248.         push    es
  249.         mov    ah,EVENTCOLOR
  250.         mov    di,ax
  251.         shl    di,1
  252.                 add     al,MINEVENT
  253.         mov    es,cs:EventPar
  254.         cld
  255.         stosw
  256.  
  257.         mov    ah,TRACECOLOR
  258.         mov    es,cs:TracePar
  259.         cli
  260.         mov    di,cs:TraceInd
  261.         stosw
  262.                 and     di,03ffh                ; (3ff+1)/2 = 512 log entries
  263.         mov    cs:TraceInd,di
  264.         mov    al,01bh
  265.         not    ah
  266.         stosw
  267.  
  268.         pop    es
  269.         pop    di
  270.         popf
  271.         pop    ax
  272.         ret
  273. ShowEvent    endp
  274.  
  275.         even
  276. EventPar        dw      0b800h+(EVENTLINE-1)*10-2*EVENTCOLOR*16
  277. TracePar        dw      0b800h+EVENTLINE*10
  278. TraceInd        dw      0
  279.  
  280. SHOW_EVENT    macro    id
  281. if id gt MAXEVENT or id lt MINEVENT
  282.         .err
  283. endif
  284.                 call    ShowEvent+((id-MINEVENT)*(ShowEventNum-ShowEvent)/(MAXEVENT-MINEVENT+1))
  285.         endm
  286.  
  287. else
  288.  
  289. SHOW_EVENT    macro    num
  290.         endm
  291.  
  292. endif ; DEBUG ge 2
  293.  
  294.  
  295.  
  296.         assume ds:nothing
  297.  
  298.         include pktdr.asm
  299.  
  300.         include pkterr.asm
  301. if RFCC
  302.         include Movesb.asm
  303. endif ; RFCC
  304.  
  305. ;========================================================================
  306.          include bufs.asm
  307.  
  308. ;========================================================================
  309.          include arp.asm
  310.  
  311.  
  312. ;========================================================================
  313.          include ip.asm
  314.  
  315.  
  316. ;************************************************************************
  317. ;*        Something2Do
  318. ;*
  319. ;* Simulates a task scheduler.
  320. ;*
  321. ;*    Destroys:    flags
  322. ;************************************************************************
  323.  
  324. Something2Do    proc    near
  325.         push    ax
  326.         push    bx
  327.         push    cx
  328.         push    dx
  329.         push    si
  330.         push    di
  331.         push    bp
  332.         push    es
  333.         push    ds
  334.  
  335.         mov    ds,cs:Mysegm
  336.         assume    ds:code_s
  337.         cld
  338.  
  339.         call    Ageing            ; clear unused table slots
  340. if PINGCLIENT or TBLBUILD
  341.         call    EchoDisplay        ; show current values
  342. endif ; PIGCLIENT or TBLBUILD
  343.  
  344. if TBLBUILD
  345.         cmp    InSendAndW,0         ; avoid overload
  346.         jne    SomethingNxt5
  347.         cmp    sp,offset StackLow+13*16
  348.         jb    SomethingNxt5
  349.  
  350.         call    TblProbe        ; do tablebuilding things
  351.         mov    di,offset TblToDo
  352.         call    GetFromList
  353.         jz    SomethingNxt5
  354.         call    DoTable
  355.   SomethingNxt5:
  356. endif ; TBLBUILD
  357.  
  358. if RFCC
  359.         mov    di,offset IcmpToDo    ; ICMP or UDP replies to send?
  360.         call    GetFromList
  361.         jz    SomethingNxt4
  362.  
  363.         mov    di,[bx].dPtrIp
  364.         cmp    [di].iIpProt,UDP_PROT    ; UDP protocol?
  365.         je    Udp2Do
  366.  
  367.         call    SendIcmpPkt
  368.         jmp    short SomeIcmpDone
  369.   Udp2Do:
  370.         mov    [bx].dWaitEvent,0    ; don't wait for answer
  371.         call    SendUdpPkt
  372.   SomeIcmpDone:
  373.         call    BufRelease
  374.   SomethingNxt4:
  375. endif ; RFCC
  376.         mov    di,offset SendToDo    ; ARP replies to send?
  377.         call    GetFromList
  378.         jz    SomethingNxt2
  379.         call    SendAndWait
  380.         call    BufRelease
  381.   SomethingNxt2:
  382. if TBLBUILD or PINGCLIENT
  383.         mov    di,offset NameToDo    ; got nameserver replies?
  384.         call    GetFromList
  385.         jz    SomethingNxt6
  386.         call    DoNsInterp
  387.         call    BufRelease
  388.   SomethingNxt6:
  389. endif ; TBLBUILD or PINGCLIENT
  390.  
  391.         pop    ds
  392.         pop    es
  393.         pop    bp
  394.         pop    di
  395.         pop    si
  396.         pop    dx
  397.         pop    cx
  398.         pop    bx
  399.         pop    ax
  400.         ret
  401. Something2Do    endp
  402.  
  403.  
  404.  
  405. ;************************************************************************
  406. ;*        PrTerminate
  407. ;************************************************************************
  408.  
  409. PrTerminate:
  410.         push    cs
  411.         pop    ds
  412.         assume    ds:code_s
  413.         call    DosPr$            ; print error msg    
  414. Terminate:
  415. if DEBUG
  416.         or    cs:GenFlags,DBGSTOP    ; ignore upcalls
  417.         push    bp
  418.         push    es
  419.         push    di
  420.         push    bx
  421.         push    ds
  422.         push    si
  423.         push    cx
  424.         push    dx
  425.         push    ax
  426. endif ; DEBUG
  427.         push    cs
  428.         pop    ds
  429.         assume    ds:code_s
  430.  
  431.         push    ax
  432.  
  433.         cld
  434.         push    cs
  435.         pop    es
  436.         sti
  437.  
  438.         mov    bx,IpHandle        ; release ARP and IP handles
  439.         call    EndProtocol
  440.         mov    bx,ArpHandle
  441.         call    EndProtocol
  442. if PINGCLIENT
  443.         cmp    EchoTarget,0
  444.         jz    TermNoPing
  445.         call    RestoreTimer
  446.   TermNoPing:
  447. endif ; PINGCLIENT
  448.         pop    ax
  449.         push    ax
  450.         or    al,al            ; any errors?
  451.         jz    termnorm
  452.  
  453. if DEBUG
  454.         mov    PutNumBase,16
  455.         mov    PutMinDigits,4
  456.         mov    di,offset MsgErrAdr
  457.         mov    si,sp
  458.         sub    word ptr [si+20],3
  459.         lodsw                ; add si,2
  460.         mov    cx,16+256*(' ')
  461.         call    PutNumsF0        ; show regs
  462. endif ; DEBUG
  463.  
  464.         cmp    EnoughWord,HAVE_MYIPNR    ; clock errors?
  465.         je    termnorm
  466.  
  467.         mov    dx,offset MsgNotSet    ; display "clock not set"
  468.         call    DosPr$
  469.   termnorm:
  470.  
  471.         pop    ax
  472.         push    ax
  473.         add    al,'0'
  474.         mov    MsgTermNr,al        ; show error # in end line
  475.  
  476.         cmp    al,'0'
  477.         jne    showtermsg
  478.         test    ArgFlags,QUIET_TERM
  479.         jnz    termexit
  480.   showtermsg:
  481.         mov    si,offset MyHwAd
  482.         mov    di,offset MsgTermHw
  483.         call    PutHwNum        ; put my HW addr
  484.  
  485.         mov    si,offset MyIpNr
  486.         mov    di,offset MsgMyIp
  487.         call    PutIpNum        ; put my IP #
  488.  
  489.         mov    dx,offset MsgTerm    ; End of PDCLKSET msg
  490. if DEBUG
  491.         cmp    MsgTermNr,'0'
  492.         je    TermStdMsg
  493.         mov    dx,offset MsgErrDet
  494.   TermStdMsg:
  495. endif ; DEBUG
  496.         call    DosPr$
  497.   termexit:
  498.         pop    ax            ; error code
  499.         mov    ah,4ch
  500.         int    21h            ; terminate program
  501.  
  502.  
  503.  
  504.  
  505. ;************************************************************************
  506. ;************************************************************************
  507. ;*
  508. ;*        Input and Output routines
  509. ;*
  510. ;************************************************************************
  511. ;************************************************************************
  512.  
  513.  
  514. PutNumFiller    db    '0'
  515.         even
  516. PutNumBase    dw    10
  517. PutMinDigits    dw    2
  518. k10000        dw    10000
  519. GetNumBase    dw    10
  520.  
  521. IntTmpHwAd    dw    0, 0, 0, 0, 0, 0
  522. IntTmpIpNr    equ    IntTmpHwAd
  523.  
  524.  
  525.  
  526. ;************************************************************************
  527. ;*        DosPr$
  528. ;************************************************************************
  529.  
  530. DosPr$        proc    near
  531.         assume    ds:nothing
  532.         push    ax
  533.         mov    ah,9            ; print msg in ds:dx
  534.         int    21h
  535.         pop    ax
  536.         and    cs:GenFlags,not GOT_DSP_ROW
  537.         ret
  538. DosPr$        endp
  539.  
  540.  
  541.         assume    ds:code_s
  542.  
  543. ;************************************************************************
  544. ;*        SkipPastEq
  545. ;************************************************************************
  546.  
  547. SkipPastEq    proc    near
  548.         mov    cx,30            ; max name length
  549.   SkipLook4Eq:
  550.         cmp    al,'='            ; look for equal sign
  551.         je    SkipFoundEq
  552.  
  553.         lodsb
  554.         loop    SkipLook4Eq
  555.   SkipFoundEq:
  556.         call    skip_blanks        ; blanks may follow
  557.  
  558.         ret
  559. SkipPastEq    endp
  560.  
  561.  
  562.  
  563. ;************************************************************************
  564. ;*        NegDxAx
  565. ;************************************************************************
  566.  
  567. NegDxAx        proc    near
  568.         not    dx            ; take negative of number
  569.         not    ax
  570.         add    ax,1
  571.         adc    dx,0 
  572.         ret
  573. NegDxAx        endp
  574.  
  575.  
  576.  
  577. ;************************************************************************
  578. ;*        GetNums
  579. ;************************************************************************
  580.  
  581. GetNums     proc    near
  582.         assume    ds:nothing
  583.         mov    ch,','            ; comma separated numbers
  584.         jmp    short GetSkipBlanks
  585. GetNumsDot:
  586.         mov    ch,'.'            ; dot separated numbers
  587.   GetSkipBlanks:
  588.         push    bx
  589.         mov    bx,cx
  590.         call    skip_blanks
  591.   GetNextNum:
  592.         call    GetNum            ; get a number
  593.         stosw                ; store it in table
  594.         dec    bl            ; do we want more nums?
  595.         jz    GetNumsRet        ; - no, return
  596.  
  597.         lodsb                ; - yes
  598.         cmp    al,bh            ; is this a separator char?
  599.         je    GetNextNum        ; - yes
  600.   GetNumsRet:                    ; - no, return
  601.         pop    bx
  602.         ret
  603. GetNums     endp
  604.  
  605.  
  606.  
  607. ;************************************************************************
  608. ;*        GetNum
  609. ;************************************************************************
  610.  
  611. GetNum        proc    near
  612.         assume    ds:nothing
  613.         xor    dx,dx
  614.         lodsb
  615.         cmp    al,'-'            ; minus prefix?
  616.         pushf
  617.         je    GetNumSign
  618.         cmp    al,'+'            ; plus prefix?
  619.         jne    GetNoPrefix
  620.   GetNumSign:
  621.         lodsb                ; get a char
  622.   GetNoPrefix:
  623.         mov    cs:GetNumBase,10
  624.         cmp    al,'0'            ; hex leading '0x' ?
  625.         jne    GetNextDig
  626.         cmp    byte ptr [si],'X'
  627.         je    GetNextHex
  628.         cmp    byte ptr [si],'x'
  629.         jne    GetNextDig
  630.   GetNextHex:
  631.         inc    si
  632.         mov    cs:GetNumBase,16
  633.         lodsb
  634.   GetNextDig:
  635.         cmp    al,'0'            ; a digit?
  636.         jb    GetNumEnd
  637.         cmp    al,'9'
  638.         ja    GetTstHex
  639.  
  640.         sub    al,'0'            ; convert to integer
  641.         jmp    short GetNumConv
  642.   GetTstHex:
  643.         cmp    al,'A'
  644.         jb    GetNumEnd
  645.         cmp    al,'F'
  646.         ja    GetTstHex2
  647.         sub    al,'A'-10
  648.         jmp    short GetNumConv
  649.   GetTstHex2:
  650.         cmp    al,'a'
  651.         jb    GetNumEnd
  652.         cmp    al,'f'
  653.         ja    GetNumEnd
  654.         sub    al,'a'-10
  655.   GetNumConv:
  656.         cbw
  657.         add    ax,dx
  658.         mov    cx,ax
  659.         mul    cs:GetNumBase
  660.         mov    dx,ax
  661.         lodsb
  662.         jmp    short GetNextDig
  663.   GetNumEnd:
  664.         mov    dx,60*60
  665.         cmp    al,'h'            ; hours suffix?
  666.         je    GetNumScale
  667.  
  668.         mov    dx,60
  669.         cmp    al,'m'            ; minutes suffix?
  670.         je    GetNumScale
  671.  
  672.         mov    dx,1
  673.         cmp    al,'s'            ; seconds suffix?
  674.         je    GetNumScale
  675.  
  676.         dec    si            ; move back char ptr
  677.   GetNumScale:
  678.         mov    ax,cx            ; do suffix scaling
  679.         mul    dx
  680.  
  681.         cmp    byte ptr [si],'+'    ; composite number?
  682.         je    GetComposite
  683.         cmp    byte ptr [si],'-'
  684.         je    GetComposite
  685.         cmp    byte ptr [si],'0'
  686.         jb    GetSingle
  687.         cmp    byte ptr [si],'9'
  688.         ja    GetSingle
  689.   GetComposite:
  690.         push    di            ; save partial value
  691.         mov    cx,ax
  692.         push    cx
  693.         mov    di,dx
  694.         call    GetNum            ; get next part
  695.         pop    cx
  696.         add    ax,cx            ; add to previous part
  697.         adc    dx,di
  698.         pop    di
  699.   GetSingle:
  700.         popf                ; minus prefix?
  701.         jne    GetNumRet
  702.  
  703.         call    NegDxAx
  704.  GetNumRet:
  705.         cmp    ax,ax            ; ensure zero flag
  706.         ret
  707. GetNum        endp
  708.  
  709.  
  710.  
  711. ;************************************************************************
  712. ;*        GetIpNr
  713. ;************************************************************************
  714.  
  715. GetIpNr     proc    near
  716.         assume    ds:nothing
  717.         mov    cx,1
  718. GetIpNums:
  719.         push    cx            ; remember how many we wanted
  720.   GetIpCont:
  721.         push    cx            ; IP #'s left to read
  722.  
  723.         push    es
  724.         push    cs
  725.         pop    es
  726.         push    di
  727.         mov    cl,4
  728.         mov    di,offset IntTmpIpNr
  729.         call    GetNumsDot        ; read an IP #
  730.         pop    di
  731.         pop    es
  732.         jnz    GetIpNrErr
  733.  
  734.         mov    cx,4
  735.         push    ds
  736.         push    cs
  737.         pop    ds
  738.         push    si
  739.         mov    si,offset IntTmpIpNr
  740.   GetIpNrLoop:
  741.         lodsw                ; convert to bytes
  742.         stosb
  743.         loop    GetIpNrLoop
  744.  
  745.         pop    si
  746.         pop    ds
  747.         pop    cx            ; want more IP #'s?
  748.         loop    GetIpMore
  749.   GetIpNrRet:
  750.         pop    ax
  751.         sub    ax,cx            ; ax = IP #'s read
  752.         cmp    cx,cx            ; zero flag
  753.         ret
  754.  
  755.   GetIpMore:
  756.         lodsb
  757.         cmp    al,','            ; comma separator?
  758.         je    GetIpCont
  759.  
  760.         dec    si
  761.         jmp    short GetIpNrRet
  762.  
  763.   GetIpNrErr:
  764.         pop    cx
  765.         pop    cx
  766.         ret                ; non-zero return
  767. GetIpNr     endp
  768.  
  769.  
  770.  
  771. ;************************************************************************
  772. ;*        PutIpNum (4 bytes from DS:SI to decimal at ES:DI)
  773. ;************************************************************************
  774.  
  775. PutIpNum    proc    near
  776.         assume    ds:nothing
  777.         push    di
  778.         push    es
  779.         push    cs
  780.         pop    es
  781.         mov    cx,4
  782.         mov    di,offset IntTmpIpNr
  783.         xor    ah,ah
  784.   PutIpLoop:
  785.         lodsb                ; convert IP #
  786.         stosw                ;  into integers
  787.         loop    PutIpLoop
  788.         pop    es
  789.         pop    di
  790.  
  791.         push    ds
  792.         push    cs
  793.         pop    ds
  794.         assume    ds:code_s
  795.         mov    si,offset IntTmpIpNr
  796.         mov    ch,'.'
  797.         mov    cl,4
  798.         mov    PutMinDigits,1
  799.         test    ArgFlags,IP_15DIG
  800.         jz    PutIpNoZero
  801.         mov    PutMinDigits,3
  802.   PutIpNoZero:
  803.         call    PutNumsF0         ; put IP #
  804.         pop    ds
  805.         ret
  806. PutIpNum    endp
  807.  
  808.  
  809.  
  810. ;************************************************************************
  811. ;*        PutHwNum
  812. ;************************************************************************
  813.  
  814. PutHwNum    proc    near
  815.         assume    ds:nothing
  816.         push    di
  817.         push    cs
  818.         pop    es
  819.         mov    cx,6
  820.         mov    di,offset IntTmpHwAd
  821.         xor    ah,ah
  822.   PutHwLoop:
  823.         lodsb                ; convert HW #
  824.         stosw                ;  into integers
  825.         loop    PutHwLoop
  826.         pop    di
  827.  
  828.         push    si
  829.         push    ds
  830.         push    cs
  831.         pop    ds
  832.         assume    ds:code_s
  833.         mov    si,offset IntTmpHwAd
  834.         mov    ch,'-'            ; separator char
  835.         test    ArgFlags,LANW_TABLE
  836.         jz    PutHwDash
  837.         mov    ch,7fh            ;   except for LANwatch table
  838.   PutHwDash:
  839.         mov    cl,6
  840.         mov    PutNumBase,16
  841.         call    PutNumsD2F0         ; put HW #
  842.         mov    PutNumBase,10
  843.         pop    ds
  844.         pop    si
  845.         ret
  846. PutHwNum    endp
  847.  
  848.  
  849.  
  850. ;************************************************************************
  851. ;*        PutNums
  852. ;************************************************************************
  853.  
  854.         assume    ds:code_s
  855.  
  856. PutNumsD2F0    proc    near
  857.         mov    PutMinDigits,2
  858.  
  859. PutNumsF0:    mov    PutNumFiller,'0'
  860.  
  861. PutNums:
  862.   NextNum:
  863.         lodsw                ; get integer from table
  864.         call    PutNum            ; convert to decimal
  865.         dec    cl            ; any more #'s?
  866.         jz    PutNumsRet
  867.  
  868.         cmp    ch,7fh            ; no separator char?
  869.         je    NextNum
  870.  
  871.         mov    al,ch
  872.         stosb                ; put separator char
  873.         jmp    short NextNum
  874.   PutNumsRet:
  875.         ret
  876. PutNumsD2F0    endp
  877.  
  878.  
  879.  
  880. ;************************************************************************
  881. ;*        PutNum and PutBigNum
  882. ;************************************************************************
  883.  
  884.         assume    ds:nothing
  885.  
  886. PutNumD4Fb    proc    near
  887.         mov    cs:PutMinDigits,4
  888. PutNumFb:
  889.         mov    cs:PutNumFiller,' '
  890. PutNum:
  891.         xor    dx,dx
  892. PutBigNum:
  893.         push    ds
  894.         push    cs
  895.         pop    ds
  896.         assume    ds:code_s
  897.         push    bx
  898.         push    cx
  899.         xor    cx,cx            ; extract significant digits
  900.         mov    bx,dx
  901.         cmp    PutNumBase,10
  902.         jne    NextDig
  903.         div    k10000
  904.         mov    bx,ax
  905.         mov    ax,dx
  906.   NextDig:
  907.         xor    dx,dx
  908.         div    PutNumBase
  909.         add    dx,'0'
  910.         cmp    dx,'9'
  911.         jle    PutNotHex
  912.  
  913.         add    dx,'a'-'9'-1
  914.   PutNotHex:
  915.         push    dx
  916.         inc    cx
  917.         or    ax,ax
  918.         jnz    NextDig
  919.  
  920.         or    bx,bx
  921.         jz    PutFiller
  922.  
  923.         mov    al,'0'
  924.   PutZeroNext:
  925.         cmp    cx,4
  926.         jae    PutZeroNumbr
  927.  
  928.         push    ax
  929.         inc    cx
  930.         jmp    short PutZeroNext
  931.   PutZeroNumbr:
  932.  
  933.         mov    ax,bx
  934.   NextDig2:
  935.         xor    dx,dx
  936.         div    PutNumBase
  937.         add    dx,'0'
  938.         push    dx
  939.         inc    cx
  940.         or    ax,ax
  941.         jnz    NextDig2
  942.   PutFiller:
  943.         mov    al,PutNumFiller
  944.   PutFillNext:
  945.         cmp    cx,PutMinDigits     ; want more digits?
  946.         jae    PutDigNumbr
  947.  
  948.         push    ax
  949.         inc    cx
  950.         jmp    short PutFillNext
  951.   PutDigNumbr:
  952.         mov    dx,cx            ; save DX = # of digits
  953.   PutDigs:
  954.         pop    ax
  955.         stosb                ; put the digits
  956.         loop    PutDigs
  957.  
  958.         pop    cx
  959.         pop    bx
  960.         pop    ds
  961.         ret
  962. PutNumD4Fb    endp
  963.  
  964.  
  965.  
  966. ;************************************************************************
  967. ;*        PutBigNums
  968. ;************************************************************************
  969.  
  970.         assume    ds:code_s
  971.  
  972. PutBigNums    proc    near
  973.   PutBigNext:
  974.         lodsw
  975.         mov    dx,ax
  976.         lodsw
  977.  
  978.         call    PutBigNum
  979.         loop    PutBigNext
  980.  
  981.         ret
  982. PutBigNums    endp
  983.  
  984.  
  985.  
  986. ;************************************************************************
  987. ;*        SkipBlk
  988. ;************************************************************************
  989.  
  990.         include skipblk.asm
  991.  
  992. ;************************************************************************
  993. ;*        ChrOut
  994. ;************************************************************************
  995.  
  996.         include chrout.asm
  997.  
  998.  
  999.  
  1000.  
  1001. ;************************************************************************
  1002. ;************************************************************************
  1003. ;*                                    *
  1004. ;*        Program begins                        *
  1005. ;*                                    *
  1006. ;************************************************************************
  1007. ;************************************************************************
  1008.  
  1009.         assume    ds:code_s
  1010.  
  1011.  
  1012. start1:
  1013.         call    DoArgs            ; decode arguments
  1014.         call    BufInit         ; initialize buffers
  1015.         call    FindPktint        ; find the packet driver
  1016.         call    InitProtocols         ; initialize ARP/IP protocols
  1017.  
  1018.         mov    ax,ArgFlags
  1019.         and    ax,TERM_WAIT+MAKE_TABLE ; if we build tables
  1020. if PINGCLIENT
  1021.         or    ax,EchoTarget        ;   or do pinging
  1022. endif ; PINGCLIENT
  1023.         jz    MustHave
  1024.  
  1025.         mov    EnoughWord,HAVE_MYIPNR    ;   time things not needed
  1026.   MustHave:
  1027.         mov    dx,Flagword
  1028.         and    dx,EnoughWord
  1029.         cmp    dx,EnoughWord        ; do we have needed info?
  1030.         jne    UseBootp
  1031.  
  1032.         call    ValidateIpNr        ; - yes. IP # occupied?
  1033.         jmp    short SkipBootp
  1034.   UseBootp:
  1035.         call    DoBootpPkt        ; - no, ask a bootp server
  1036.         call    InterpBootp
  1037.   SkipBootp:
  1038.         mov    dx,Flagword
  1039.         and    dx,EnoughWord
  1040.         cmp    dx,EnoughWord        ; do we NOW have needed info?
  1041.         je    DoTime
  1042.  
  1043.         mov    dx,offset NotEnoughMsg
  1044.         mov    al,07            ; error code 7
  1045.         call    PrTerminate
  1046.   DoTime:
  1047.         call    MakeMynet        ; process mask and IP #
  1048.  
  1049.         cmp    EnoughWord,HAVE_MYIPNR
  1050.         je    DidntGetIt
  1051.  
  1052.         call    GetTime         ; ask the time server
  1053.         jnz    DidntGetIt
  1054.         call    SetTime         ; set the PC clock
  1055.         call    SetZone         ; set zone environment name
  1056.   DidntGetIt:
  1057. if TBLBUILD
  1058.         call    TableInit
  1059. endif ; TBLBUILD
  1060.  
  1061. if PINGCLIENT
  1062.         call    EchoAwhile        ; do some ping?
  1063. endif ; PINGCLIENT
  1064.         call    DelayTermin        ; keep it running some more?
  1065.         mov    al,00            ; error code 0
  1066.   SkipTime:
  1067.         call    Terminate
  1068.  
  1069. ;************************************************************************
  1070. ;************************************************************************
  1071. ;*        End of program                        *
  1072. ;************************************************************************
  1073. ;************************************************************************
  1074.  
  1075.  
  1076.  
  1077. ;************************************************************************
  1078. ;*        DoArgs
  1079. ;************************************************************************
  1080.  
  1081.  
  1082. ArgTabEnt    struc
  1083. ArgTabNam    db    'a'            ; first char of arg name
  1084. ArgTabAdr    dw    0            ; arg name handler
  1085. ArgTabEnt    ends
  1086. ARGTABLEN    equ    SIZE ArgTabEnt
  1087.  
  1088. ArgTab        ArgTabEnt    <'a', offset ArgAlter>
  1089.         ArgTabEnt    <'d', offset ArgDls>
  1090. if PINGCLIENT
  1091.         ArgTabEnt    <'e', offset ArgEcho>
  1092. endif ; PINGCLIENT
  1093.         ArgTabEnt    <'f', offset ArgFlag>
  1094.         ArgTabEnt    <'g', offset ArgGwy>
  1095.         ArgTabEnt    <'i', offset ArgIpnr>
  1096.         ArgTabEnt    <'l', offset ArgLongTimeout>
  1097.         ArgTabEnt    <'m', offset ArgMask>
  1098. if TBLBUILD or PINGCLIENT
  1099.         ArgTabEnt    <'n', offset ArgNameserv>
  1100. endif ; TBLBUILD or PINGCLIENT
  1101.         ArgTabEnt    <'o', offset ArgOffset>
  1102.         ArgTabEnt    <'p', offset ArgPktIntNo>
  1103.         ArgTabEnt    <'t', offset ArgTimeserv>
  1104. if PINGCLIENT
  1105.         ArgTabEnt    <'u', offset ArgUdpecho>
  1106. endif ; PINGCLIENT
  1107.         ArgTabEnt    <'z', offset ArgZoneNam>
  1108. ArgTabEnd    equ    $
  1109.  
  1110. DoArgs        proc    near
  1111.         cld
  1112.         mov    si,offset phd_dioa
  1113.         lodsb
  1114.         xor    ah,ah
  1115.         mov    bp,ax
  1116.         add    bp,si            ; end of args
  1117.  
  1118.         push    si            ; substitute : and ; to = and ,
  1119.   DoArgSubst:
  1120.         lodsb
  1121.         cmp    al,':'
  1122.         jne    DoArgChkComma
  1123.         mov    byte ptr [si-1],'='
  1124.   DoArgChkComma:
  1125.         cmp    al,';'
  1126.         jne    DoArgChkE
  1127.         mov    byte ptr [si-1],','
  1128.   DoArgChkE:
  1129.         cmp    si,bp
  1130.         jb    DoArgSubst
  1131.         pop    si
  1132.  
  1133.         call    skip_blanks
  1134.         cmp    al,CR            ; no args?
  1135.         je    ArgError        ; - yes, display usage msg
  1136.  
  1137.   NextArg:
  1138.         call    skip_blanks
  1139.         cmp    si,bp
  1140.         ja    ArgError
  1141.  
  1142.         or    al,020h         ; conv to lower case
  1143.  
  1144.         cmp    al,'b'            ; bootp only, no args
  1145.         je    DoArgRet
  1146.  
  1147.         cmp    al,CR+020h        ; end
  1148.         je    DoArgRet
  1149.  
  1150.         mov    bx,offset ArgTab-ARGTABLEN
  1151.   ArgFindLoop:
  1152.         add    bx,ARGTABLEN
  1153.         cmp    bx,offset ArgTabEnd
  1154.         jae    ArgError
  1155.         cmp    al,[bx]         ; first char of arg name
  1156.         jne    ArgFindLoop
  1157.  
  1158.         call    SkipPastEq        ; skip rest of name
  1159.         inc    bx
  1160.         call    [bx]            ; process arg
  1161.         jz    NextArg         ; look for next arg
  1162.  
  1163.   ArgError:
  1164.         mov    dx,offset usage_msg
  1165.   error:
  1166.         call    DosPr$            ; display usage message
  1167.         mov    ax,4c01h        ; error code 1
  1168.         int    21h            ; terminate program
  1169.   DoArgRet:
  1170.         xor    ax,ax
  1171.         mov    word ptr StackLow,ax
  1172. if DEBUG
  1173.         mov    word ptr phd_dioa,ax
  1174. endif ; DEBUG
  1175.         ret
  1176. DoArgs        endp
  1177.  
  1178.  
  1179.  
  1180.   ArgAlter:
  1181.         or    word ptr Flagword,DONT_SETTIME    ; alter time
  1182.         mov    di,offset AlterTime
  1183.         mov    cl,2
  1184.         call    GetNums
  1185.         mov    AlterTime+4,dx
  1186.         ret
  1187.  
  1188.   ArgDls:
  1189.         cmp    al,'9'            ; daylight saving algorithm
  1190.         jbe    ArgGetAlgPar
  1191.         lodsw
  1192.         mov    dx,ax
  1193.         lodsw
  1194.         mov    di,offset AlgTab-AlgEntryLen
  1195.         cmp    ah,CR
  1196.         jne    ArgNextDls
  1197.         mov    ah,' '
  1198.         dec    si
  1199.   ArgNextDls:
  1200.         add    di,AlgEntryLen
  1201.         cmp    di,offset AlgTabEnd-1
  1202.         ja    ArgDlsRet
  1203.         cmp    dx,[di]
  1204.         jne    ArgNextDls
  1205.         cmp    ax,[di+2]
  1206.         jne    ArgNextDls            
  1207.         mov    AlgPtr,di
  1208.         ret
  1209.   ArgGetAlgPar:
  1210.         mov    di,offset AlgTab
  1211.         mov    AlgPtr,di
  1212.         add    di,4
  1213.         mov    cl,5
  1214.         call    GetNums
  1215.   ArgDlsRet:
  1216.         ret
  1217.  
  1218. if PINGCLIENT
  1219. k10        dw    10
  1220.   ArgUdpEcho:
  1221.         or    GenFlags,UDP_ECHO
  1222.   ArgEcho:
  1223.         cmp    al,'A'
  1224.         jae    ArgEchoName
  1225.  
  1226.         mov    di,offset EchoTarget    ; echo to a target (ping)
  1227.         call    GetIpNr
  1228.         jnz    ArgEchoRet            
  1229.   ArgEchoMore:
  1230.         cmp    byte ptr [si],','
  1231.         jne    ArgGoodRet
  1232.  
  1233.         inc    si
  1234.         mov    cl,1
  1235.         call    GetNums
  1236.  
  1237.         cmp    byte ptr [si],'.'
  1238.         jne    ArgEchoMore
  1239.         inc    si
  1240.         mul    k10
  1241.         push    ax
  1242.         call    GetNum
  1243.         pop    dx
  1244.         add    ax,dx
  1245.         mov    [di-2],ax
  1246.         or    ArgFlags,MICRO_100
  1247.         jmp    short ArgEchoMore
  1248.   ArgEchoRet:
  1249.         ret
  1250.  
  1251.   ArgEchoName:
  1252.         mov    byte ptr EchoTarget,127 ; marker to do dns lookup
  1253.         mov    bx,offset EchoNameBuf
  1254.         lea    di,[bx+1]
  1255.         xor    cx,cx
  1256.   ArgEchoLoop:
  1257.         lodsb
  1258.         cmp     al,' '
  1259.         je    ArgEchoNamEnd
  1260.         cmp    al,CR
  1261.         je    ArgEchoNamEnd
  1262.         cmp    si,bp
  1263.         ja    ArgEchoRet
  1264.         cmp    al,','
  1265.         je    ArgEchoNamEnd
  1266.         cmp    al,'.'
  1267.         jne    ArgEchoNamChar
  1268.         mov    [bx],cl         ; prepend length to string
  1269.         mov    cx,-1
  1270.         mov    bx,di
  1271.   ArgEchoNamChar:
  1272.         stosb
  1273.         inc    cx
  1274.         jmp    short ArgEchoLoop
  1275.  
  1276.   ArgEchoNamEnd:
  1277.         mov    [bx],cl         ; prepend length to string
  1278.         xor    ax,ax
  1279.         stosb
  1280.         inc    ah
  1281.         stosw                ; store type and class
  1282.         stosw
  1283.         dec    si
  1284.         mov    di,offset EchoTarget+4
  1285.         jmp    short ArgEchoMore
  1286. endif ; PINGCLIENT
  1287.  
  1288.   ArgFlag:
  1289.         call    GetNum
  1290.         or    ArgFlags,ax        ; set arg flags
  1291.   ArgGoodRet:
  1292.         xor    ax,ax
  1293.         ret
  1294.  
  1295.   ArgGwy:
  1296.         mov    di,offset DefGwys    ; default gateways
  1297.         mov    cx,MAXDEFGWYS
  1298.         call    GetIpNums
  1299.         mov    DefGwyNum,ax
  1300.         ret
  1301.  
  1302.   ArgIpnr:
  1303.         or    Flagword,HAVE_MYIPNR    ; my ip nr
  1304.         mov    di,offset MyIpNr
  1305.         call    GetIpNr
  1306.         ret
  1307.  
  1308.   ArgLongTimeout:
  1309.         call    GetNum            ; longer timeout
  1310.         mul    m18
  1311.         mov    LongerTimOut,ax
  1312.         jmp    short ArgGoodRet
  1313.  
  1314.   ArgMask:
  1315.         mov    di,offset MyMask    ; net mask
  1316.         call    GetIpNr
  1317.         ret
  1318.  
  1319. if TBLBUILD or PINGCLIENT
  1320.   ArgNameserv:
  1321.         mov    di,offset DefNS     ; default nameservers
  1322.         mov    cx,MAXDEFNS
  1323.         call    GetIpNums
  1324.         mov    DefNSnum,ax
  1325.         ret
  1326. endif ; TBLBUILD or PINGCLIENT
  1327.  
  1328.   ArgOffset:
  1329.         or    Flagword,HAVE_TIMEOFFSET
  1330.         call    GetNum            ; time offset
  1331.         xchg    ah,al
  1332.         xchg    dh,dl
  1333.         mov    tzoffset,dx
  1334.         mov    tzoffset+2,ax
  1335.         ret
  1336.  
  1337.   ArgPktIntno:
  1338.         call    GetNum            ; packet int number
  1339.         mov    word ptr packet_int_no,ax
  1340.         ret
  1341.  
  1342.   ArgTimeserv:
  1343.         or    Flagword,HAVE_TIMESERVER    ; time server
  1344.         mov    di,offset TimeServIpNr
  1345.         mov    cx,MAXTSERVS
  1346.         call    GetIpNums
  1347.         mov    TservNum,ax
  1348.         ret
  1349.  
  1350.   ArgZoneNam:
  1351.         or    GenFlags,ARGZONE    ; set zone env variable
  1352.         cmp    al,'#'
  1353.         jne    ArgZonePar
  1354.         inc    si
  1355.         jmp    short ArgGoodRet
  1356.   ArgZonePar:
  1357.         or    GenFlags,ARGZONESPEC
  1358.         mov    dl,05fh         ; convert to upper case for name
  1359.         mov    di,offset ZoneString
  1360.         mov    cx,di
  1361.         add    cx,ZONESPACE-2
  1362.   ArgZoneCopyNext:
  1363.         lodsb                ; get next arg char
  1364.         cmp     al,' '                  ; end of field?
  1365.         je    ArgZoneCopyRet
  1366.         cmp    al,CR
  1367.         je    ArgZoneCopyRet
  1368.         cmp    si,bp            ; beyond argument string?
  1369.         ja    ArgZoneCopyErr
  1370.         cmp    di,cx            ; too long name?
  1371.         jae    ArgZoneCopyErr
  1372.         cmp    al,'='            ; start of value part?
  1373.         jne    ArgZoneCopy2
  1374.         mov    dl,0ffh         ; any case allowed for 1st value
  1375.         mov    bx,di
  1376.         sub    bx,offset ZoneString-1
  1377.         mov    ZoneVarLen,bx        ; save env name length
  1378.   ArgZoneCopy2:
  1379.         cmp    al,','            ; second value part?
  1380.         jne    ArgZoneCopy3
  1381.  
  1382.         and    dl,07fh         ; any case allowed for 2nd value
  1383.         xor    ax,ax
  1384.         stosw                ; end of string marker
  1385.         mov    al,'$'            ; char for print stop 
  1386.         stosb
  1387.         mov    bx,di
  1388.         sub    bx,offset ZoneString
  1389.         mov    ZoneDstInd,bx        ; remember where 2nd value starts
  1390.         jmp    short ArgZoneCopyNext
  1391.   ArgZoneCopy3:
  1392.         and    al,dl            ; possibly convert to upper case
  1393.         stosb
  1394.         jmp    short ArgZoneCopyNext
  1395.   ArgZoneCopyRet:
  1396.         dec    si
  1397.         cmp    dl,07fh         ; seen two value parts?
  1398.         jne    ArgZoneCopyErr
  1399.         xor    ax,ax
  1400.         stosb                ; end of string marker
  1401.         ret
  1402.  
  1403.   ArgZoneCopyErr:
  1404.         inc    si            ; nonzero ret
  1405.         ret
  1406.  
  1407.  
  1408.  
  1409. ;************************************************************************
  1410. ;*        GetTime
  1411. ;*
  1412. ;* This code first does one turn to query the timeservers to see if any
  1413. ;* one responds within half a second. If none has responded it will do a
  1414. ;* second turn giving each server 2 seconds to respond. As soon as a time
  1415. ;* reply from any server arrives, it stops.
  1416. ;************************************************************************
  1417.  
  1418. GetTime     proc    near
  1419.         assume    ds:code_s
  1420.         push    es
  1421.         push    ds
  1422.         call    BufAlloc
  1423.         assume    ds:nothing
  1424.         call    MakeSendDescr
  1425.         mov    [di].uUdpDst,2500h    ; 37 = time port
  1426.         mov    [di].uUdpSrc,4321    ; my port
  1427.         mov    [bx].dTickTimeout,10    ; 10/18 second
  1428.         mov    [bx].dWaitEvent,GOT_TIMEREPLY
  1429.         mov    [bx].dTimOut2Msg,offset NoTimeServMsg ; timeout msg
  1430.         mov    [bx].dTick2Timeout,2*18
  1431.         mov    dx,offset TservNum
  1432.         mov    [bx].dPktlen,UDPHDRLEN
  1433.         call    SendUdpFind        ; send time requset
  1434.         call    BufRelease
  1435.         pop    ds
  1436.         assume    ds:code_s
  1437.         pop    es
  1438.         ret
  1439. GetTime     endp
  1440.  
  1441.  
  1442. ;========================================================================
  1443.         include settime.asm
  1444.  
  1445.  
  1446.  
  1447. ;************************************************************************
  1448. ;*        DelayTermin
  1449. ;************************************************************************
  1450.  
  1451.         assume    ds:code_s
  1452.  
  1453. DelayTermin    proc    near
  1454. if RFCC
  1455.         test    ArgFlags,TERM_WAIT+MAKE_TABLE ; want delayed termination?
  1456.         jnz    DelayLoop
  1457.         ret
  1458.   
  1459.   DelayLoop:
  1460.         call    SomeThing2Do        ; ARP or ICMP reply to do
  1461. if PINGCLIENT
  1462.         test    GenFlags,PING_DELAY
  1463.         jnz    DelayLoop
  1464. endif ; PINGCLIENT
  1465.         call    AnyKey
  1466.         jz    DelayLoop        ; second key stops receive
  1467.   DelayCrLf:
  1468. if PINGCLIENT
  1469.         cmp    al,ESCAPE        ; want error size distribution?
  1470.         je    DelayNotPing
  1471.  
  1472.                 mov     cx,(GIANTTR-HWHDRLEN-20)/20
  1473.         mov    si,offset EchoSizeVec+2
  1474.         mov    word ptr FileBuf,LF*256+CR
  1475.         mov    ax,21
  1476.   PingNextRow:
  1477.         push    cx
  1478.         push    ax
  1479.         mov    di,offset FileBuf+2
  1480.         call    PutNumD4Fb
  1481.         mov    PutMinDigits,2
  1482.         mov    al,':'
  1483.         stosb
  1484.         xor    bx,bx
  1485.         mov    cx,20
  1486.   PingNextCol:
  1487.         push    cx
  1488.         mov     al,' '
  1489.         stosb
  1490.         lodsw
  1491.         add    bx,ax
  1492.         call    PutNum
  1493.         pop    cx
  1494.         loop    PingNextCol
  1495.  
  1496.         or    bx,bx
  1497.         jz    PingNoRow
  1498.         mov    byte ptr [di],'$'
  1499.         mov    dx,offset FileBuf
  1500.         call    DosPr$
  1501.         dec    PingRowCnt
  1502.         jnz    PingNoRow
  1503.         mov    PingRowCnt,22
  1504.   PingDispPause:
  1505.         call    AnyKey
  1506.         jz    PingDispPause
  1507.         cmp    al,ESCAPE
  1508.         jne    PingNoRow
  1509.         pop    ax
  1510.         pop    cx
  1511.         jmp    short DelayNotPing
  1512.   PingNoRow:
  1513.         pop    ax
  1514.         add    ax,20
  1515.         pop    cx
  1516.         loop    PingnextRow
  1517.   DelayNotPing:
  1518. endif ; PINGCLIENT
  1519.         mov    dx,offset CrLf_Msg
  1520.         call    DosPr$
  1521. if TBLBUILD
  1522.         call    TableWr         ; write HW and IP tbl files
  1523. endif ; TBLBUILD
  1524.  
  1525. endif ; RFCC
  1526.         ret
  1527. DelayTermin    endp
  1528.  
  1529.  
  1530.  
  1531. ;************************************************************************
  1532. ;*        AnyKey
  1533. ;************************************************************************
  1534.  
  1535. AnyKey        proc    near
  1536. if PINGCLIENT
  1537.         test    ArgFlags,AVOID_HDWR
  1538.         jnz    AnyKeyDos
  1539.  
  1540.         push    es    ; simulates int 21h, ah=06, dl=ff, but faster
  1541.         push    bx
  1542.         mov    ax,040h
  1543.         mov    es,ax
  1544.         mov    bx,es:[01ch]
  1545.         mov    es:[01ah],bx        ; set head to tail
  1546.         cmp    bx,es:[080h]
  1547.         ja    AnyKeyPtrOK
  1548.         mov    bx,es:[082h]
  1549.   AnyKeyPtrOK:
  1550.         mov    ax,es:[bx-2]        ; last char typed
  1551.  
  1552.         cmp    OldkeyPtr,0
  1553.         jne    AnyKeyInited
  1554.         mov    OldKeyPtr,bx
  1555.   AnyKeyInited:
  1556.         cmp    bx,OldKeyPtr        ; any key pressed?
  1557.         mov    OldkeyPtr,bx
  1558.         pop    bx
  1559.         pop    es
  1560.         ret
  1561.  
  1562. OldKeyPtr    dw    0
  1563. endif ; PINGCLIENT
  1564.  
  1565.   AnyKeyDos:
  1566.         mov    ah,06h
  1567.         mov    dl,0ffh
  1568.         int    21h            ; any key pressed?
  1569.         ret
  1570. AnyKey        endp
  1571.  
  1572.  
  1573.  
  1574. if PINGCLIENT
  1575. ;========================================================================
  1576.          include ping.asm
  1577. endif ; PINGCLIENT
  1578.  
  1579.  
  1580.  
  1581. if TBLBUILD
  1582. ;========================================================================
  1583.         include tblbuild.asm
  1584. endif ; TBLBUILD
  1585.  
  1586. ;************************************************************************
  1587. ;*        Receive buffers                     *
  1588. ;************************************************************************
  1589.  
  1590.         even
  1591. EchoNameBuf    equ    $
  1592.  
  1593. EchoSizeVec    equ    EchoNameBuf+80
  1594. EchoSizeEnd     equ     EchoSizeVec+2*(GIANTTR-HWHDRLEN)
  1595.  
  1596. BlockAdj    =    (EchoSizeEnd-CodeOrg) and 0ffh
  1597. FileBuf     equ    EchoSizeEnd+256-BlockAdj
  1598.  
  1599. BufStart    equ    FileBuf+128        ; buffer pool space
  1600.  
  1601. BufStartSml    equ    BufStart + NBUFS*BUFSIZE
  1602. ; BufEnd        equ    BufStartSml + NBUFSMALL*BUFSIZESML
  1603.  
  1604.         org    0fed0h            ; from here to ffff is
  1605. StackLow    equ    $            ; non interrupt stack space
  1606.  
  1607. code_s        ends
  1608.         end    start
  1609.  
  1610. ;************************************************************************
  1611. ;*                                    *
  1612. ;*        This is the end                     *
  1613. ;*                                    *
  1614. ;************************************************************************
  1615.