home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / packetdrivers.tar.gz / pd.tar / src / pktwatch.asm < prev    next >
Assembly Source File  |  1995-06-25  |  6KB  |  339 lines

  1. version    equ    0
  2.  
  3. ;History:335,1
  4.  
  5. ;  Copyright 1990-1992, Russell Nelson, Crynwr Software
  6.  
  7. ;   This program is free software; you can redistribute it and/or modify
  8. ;   it under the terms of the GNU General Public License as published by
  9. ;   the Free Software Foundation, version 1.
  10. ;
  11. ;   This program is distributed in the hope that it will be useful,
  12. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;   GNU General Public License for more details.
  15. ;
  16. ;   You should have received a copy of the GNU General Public License
  17. ;   along with this program; if not, write to the Free Software
  18. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     include    defs.asm
  21.  
  22. code    segment word public
  23.     assume    cs:code, ds:code
  24.  
  25.     org    80h
  26. phd_dioa    label    byte
  27.  
  28.     org    100h
  29. start:
  30.     jmp    start_1
  31.  
  32. copyleft_msg    label    byte
  33.  db "Packet watcher version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990-92, Russell Nelson.",CR,LF
  34.  db "This program is free software; see the file COPYING for details.",CR,LF
  35.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  36. crlf_msg    db    CR,LF,'$'
  37.  
  38. their_isr    dd    ?
  39. entry_point    db    ?,?,?,?
  40. handle        dw    ?
  41.  
  42. int_pkt:
  43.     push    ds
  44.     push    es
  45.     pushf
  46.     cli
  47.     call    their_isr
  48.     pop    es
  49.     pop    ds
  50.     ret
  51.  
  52. no_sig_msg    db    "No packet driver at that address",'$'
  53. usage_msg    db    "usage: pktwatch <packet_int_no>",'$'
  54.  
  55. cursor_size    dw    ?        ;save the cursor size here.
  56. cursor_locn    dw    ?        ;save the cursor location here.
  57.  
  58. address_switch    db    0
  59. ether_addr    db    EADDR_LEN dup(-1)
  60.  
  61. usage_error:
  62.     mov    dx,offset usage_msg
  63. error:
  64.     mov    ah,9
  65.     int    21h
  66.     int    20h
  67.  
  68. start_1:
  69.     mov    si,offset phd_dioa+1
  70.     cmp    byte ptr [si],CR    ;end of line?
  71.     je    usage_error
  72.  
  73.     mov    di,offset entry_point
  74.     call    get_number
  75.  
  76. another_switch:
  77.     call    skip_blanks
  78.     cmp    al,'-'            ;did they specify a switch?
  79.     je    have_switch
  80.     jmp    not_switch
  81. have_switch:
  82.     cmp    byte ptr [si+1],'a'    ;did they specify '-a'?
  83.     je    got_addr_switch
  84.     jmp    usage_error        ;no, must be an error.
  85. got_addr_switch:
  86.  
  87.     add    si,2
  88.  
  89.     mov    di,offset ether_addr
  90.     movseg    es,ds
  91.     call    get_eaddr
  92.  
  93.     mov    address_switch,1
  94.     jmp    another_switch
  95. not_switch:
  96.     call    skip_blanks
  97.     cmp    al,CR
  98.     jne    usage_error
  99.  
  100.     call    verify_packet_int
  101.     jc    error
  102.     mov    dx,offset no_sig_msg
  103.     jne    error
  104.  
  105.     mov    their_isr.offs,bx
  106.     mov    their_isr.segm,es
  107.  
  108. ;save the current screen.
  109.     push    ds
  110.     mov    ax,0b800h
  111.     mov    ds,ax
  112.     xor    si,si
  113.     movseg    es,cs
  114.     mov    di,offset screen_buffer
  115.     mov    cx,25*80
  116.     rep    movsw
  117.     pop    ds
  118.  
  119.     mov    ah,3            ;get the current cursor position.
  120.     mov    bh,0
  121.     int    10h
  122.     mov    cursor_size,cx
  123.     mov    cursor_locn,dx
  124.  
  125.     mov    ah,1            ;disable the hardware cursor.
  126.     mov    cx,2000h
  127.     int    10h
  128.  
  129.     mov    ax,1ffh            ;driver_info
  130.     call    int_pkt
  131.     call    fatal_error
  132.  
  133.     mov    ah,2            ;access all packets.
  134.     mov    al,ch            ;their class from driver_info().
  135.     mov    bx,dx            ;their type from driver_info().
  136.     mov    dl,cl            ;their number from driver_info().
  137.     mov    cx,0            ;type length of zero.
  138.     movseg    es,cs
  139.     mov    di,offset our_recv
  140.     call    int_pkt
  141.     call    fatal_error
  142.     mov    handle,ax
  143.  
  144.     mov    ah,20            ;set receive mode.
  145.     mov    bx,handle
  146.     mov    cx,6            ;receive all packets.
  147.     call    int_pkt
  148.     call    fatal_error
  149.  
  150.     mov    ah,0fh            ;get the video mode.
  151.     int    10h
  152.     mov    ah,0            ;set the video mode (clear the screen).
  153.     int    10h
  154.  
  155. wait_for_key:
  156.     mov    ah,1            ;check for any key.
  157.     int    16h
  158.     je    wait_for_key        ;no key -- keep waiting.
  159.  
  160.     mov    ah,0            ;fetch the key.
  161.     int    16h
  162.  
  163. all_done:
  164.  
  165.     mov    ah,20            ;set receive mode.
  166.     mov    bx,handle
  167.     mov    cx,3            ;receive ours + broadcasts.
  168.     call    int_pkt
  169.     call    fatal_error
  170.  
  171.     mov    ah,3
  172.     mov    bx,handle
  173.     call    int_pkt
  174.     call    fatal_error
  175.  
  176.     mov    ax,0b800h
  177.     mov    es,ax
  178.     xor    di,di
  179.     mov    si,offset screen_buffer
  180.     mov    cx,25*80
  181.     rep    movsw
  182.  
  183.     mov    ah,1
  184.     mov    cx,cursor_size
  185.     int    10h
  186.  
  187.     mov    ah,2
  188.     mov    bh,0
  189.     mov    dx,cursor_locn
  190.     int    10h
  191.  
  192.     mov    dx,offset copyleft_msg
  193.     mov    ah,9
  194.     int    21h
  195.  
  196.     int    20h
  197.  
  198.  
  199. our_recv:
  200.     or    ax,ax            ;first or second call?
  201.     jne    our_recv_1        ;second -- bump the packet flag.
  202.     movseg    es,cs
  203.     mov    di,offset our_buffer
  204.     retf
  205. our_recv_1:
  206.     push    ax
  207.     push    bx
  208.     push    cx
  209.     push    dx
  210.     push    si
  211.     push    di
  212.     push    bp
  213.     push    ds
  214.     push    es
  215.  
  216.     cld
  217.  
  218.     mov    ax,cs
  219.     mov    ds,ax
  220.     mov    es,ax
  221.  
  222.     cmp    address_switch,0    ;are we looking for an address?
  223.     je    our_recv_save        ;no.
  224.  
  225.     cmp    word ptr [si][0],-1    ;always receive broadcasts.
  226.     jne    our_recv_2
  227.     cmp    word ptr [si][2],-1
  228.     jne    our_recv_2
  229.     cmp    word ptr [si][4],-1
  230.     je    our_recv_save
  231. our_recv_2:
  232.  
  233.     mov    di,offset ether_addr    ;is the destination our address?
  234.     mov    cx,EADDR_LEN/2
  235.     repe    cmpsw
  236.     je    our_recv_save        ;yes, display it.
  237.  
  238.     add    si,cx            ;move to source address.
  239.     mov    di,offset ether_addr    ;is the source our address?
  240.     mov    cx,EADDR_LEN/2
  241.     rep    cmpsw
  242.     jne    our_recv_exit        ;no, skip it.
  243.  
  244. our_recv_save:
  245.     call    receive
  246. our_recv_exit:
  247.  
  248.     pop    es
  249.     pop    ds
  250.     pop    bp
  251.     pop    di
  252.     pop    si
  253.     pop    dx
  254.     pop    cx
  255.     pop    bx
  256.     pop    ax
  257.     retf
  258.  
  259. receive_ptr    dw    0
  260.  
  261. receive:
  262.     mov    si,offset our_buffer    ;get the "to" address.
  263.     mov    ax,0b800h
  264.     mov    es,ax
  265.     mov    di,receive_ptr
  266.     mov    bx,[si][EADDR_LEN][EADDR_LEN]
  267.     xchg    bh,bl
  268.     mov    ah,20h            ;IP
  269.     cmp    bx,800h
  270.     je    receive_2
  271.     mov    ah,30h            ;ARP
  272.     cmp    bx,806h
  273.     je    receive_2
  274.     mov    ah,40h            ;Novell
  275.     cmp    bx,8137h
  276.     je    receive_2
  277.     mov    ah,50h            ;all IEEE 802.3
  278.     cmp    bx,1500
  279.     jbe    receive_2
  280.     mov    ah,70h
  281. receive_2:
  282.     lodsb
  283.  
  284.     mov    bl,al
  285.     shr    al,1
  286.     shr    al,1
  287.     shr    al,1
  288.     shr    al,1
  289.  
  290.     and    al,0fh
  291.     add    al,90h            ;binary digit to ascii hex digit.
  292.     daa
  293.     adc    al,40h
  294.     daa
  295.     stosw
  296.  
  297.     mov    al,bl
  298.     and    al,0fh
  299.     add    al,90h            ;binary digit to ascii hex digit.
  300.     daa
  301.     adc    al,40h
  302.     daa
  303.     stosw
  304.  
  305.     cmp    si,offset our_buffer+40    ;can only dump first 40 bytes.
  306.     loopne    receive_2
  307.  
  308.     add    receive_ptr,2*80
  309.  
  310.     cmp    receive_ptr,25*2*80
  311.     jb    receive_1
  312.     mov    receive_ptr,0
  313. receive_1:
  314.     mov    di,receive_ptr
  315.     mov    cx,80
  316.     mov    ax,0
  317.     rep    stosw
  318.  
  319.     ret
  320.  
  321.  
  322.  
  323.     include    pkterr.asm
  324.     include    getnum.asm
  325.     include    getdig.asm
  326.     include    skipblk.asm
  327.     include    chrout.asm
  328.     include    verifypi.asm
  329.     include    getea.asm
  330.  
  331.     align    4
  332. our_buffer    label    byte
  333.  
  334. screen_buffer    equ    our_buffer + GIANT + 2
  335.  
  336. code    ends
  337.  
  338.     end    start
  339.