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

  1. version    equ    1
  2.  
  3. ;  Copyright, 1989-1992, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     org    80h
  24. phd_dioa    label    byte
  25.  
  26.     org    100h
  27. start:
  28.     jmp    start_1
  29.  
  30. copyleft_msg    label    byte
  31.  db "Packet statistics version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  32.  db "This program is free software; see the file COPYING for details.",CR,LF
  33.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  34. crlf_msg    db    CR,LF,'$'
  35.  
  36. their_isr    dd    ?
  37. entry_point    db    60h,0,0,0
  38. packet_int_end    db    7fh,0,0,0
  39. their_ds    dw    ?
  40.  
  41. handle        dw    ?
  42.  
  43. bogus_type    db    0,0        ;totally bogus type code.
  44.  
  45. signature    db    'PKT DRVR',0
  46. signature_len    equ    $-signature
  47. usage_msg    db    "usage: pktstat <packet_int_no> [<packet_int_no_end>]",'$'
  48.  
  49. stat_names    db    "    pkt_in    pkt_out    byt_in    byt_out    err_in    err_out    pk_drop",CR,LF,'$'
  50. printed_names    db    0        ;haven't printed the names yet.
  51.  
  52. statistics_list    label    dword
  53. packets_in    dw    ?,?
  54. packets_out    dw    ?,?
  55. bytes_in    dw    ?,?
  56. bytes_out    dw    ?,?
  57. errors_in    dw    ?,?
  58. errors_out    dw    ?,?
  59. packets_dropped    dw    ?,?        ;dropped due to no type handler.
  60. statistics_count    equ    $ - statistics_list
  61.  
  62. check_packet_no:
  63.     or    word ptr [di+2],0
  64.     jne    usage_error
  65.     cmp    word ptr [di],60h
  66.     jb    usage_error
  67.     cmp    word ptr [di],7fh
  68.     ja    usage_error
  69.     ret
  70.  
  71.  
  72. usage_error:
  73.     mov    dx,offset usage_msg
  74. error:
  75.     mov    ah,9
  76.     int    21h
  77.     int    20h
  78.  
  79. start_1:
  80.     cld
  81.  
  82.     mov    dx,offset copyleft_msg
  83.     mov    ah,9
  84.     int    21h
  85.  
  86.     mov    si,offset phd_dioa+1
  87.  
  88.     mov    di,offset entry_point
  89.     call    get_number
  90.     jc    start_2            ;if they entered a number, change the default.
  91.     mov    word ptr packet_int_end+0,cx
  92.     mov    word ptr packet_int_end+2,bx
  93. start_2:
  94.     call    check_packet_no
  95.  
  96.     mov    di,offset packet_int_end
  97.     call    get_number
  98.  
  99.     call    check_packet_no
  100.  
  101.     call    skip_blanks
  102.     cmp    al,CR
  103.     jne    usage_error
  104.  
  105.     mov    al,entry_point    ;make sure they're in the right order.
  106.     cmp    al,packet_int_end
  107.     ja    usage_error
  108.  
  109. chk_loop:
  110.     call    chk_int
  111.     mov    al,entry_point
  112.     cmp    al,packet_int_end
  113.     jz    all_done
  114.     inc    entry_point        ; increment
  115.     jmp    chk_loop
  116. all_done:
  117.     mov    al,0
  118.     mov    ah,04ch
  119.     int    21h            ; exit with errorlevel 0
  120.  
  121. chk_int:
  122. ;check entry_point for a packet driver.  If there's one there, print
  123. ;the statistics and return nc.  If not, return cy.
  124.     mov    ah,35h            ;get their packet interrupt.
  125.     mov    al,entry_point
  126.     int    21h
  127.     mov    their_isr.offs,bx
  128.     mov    their_isr.segm,es
  129.  
  130.     lea    di,3[bx]
  131.     mov    si,offset signature
  132.     mov    cx,signature_len
  133.     repe    cmpsb
  134.     je    have_signature
  135.     stc
  136.     ret
  137. have_signature:
  138.  
  139.     mov    ax,1ffh            ;driver_info
  140.     call    int_pkt
  141.     call    fatal_error
  142.  
  143.     mov    ah,2            ;access_type
  144.     mov    al,ch            ;their class from driver_info().
  145.     mov    bx,dx            ;their type from driver_info().
  146.     mov    dl,cl            ;their number from driver_info().
  147.     mov    cx,2            ;use a type length of 2.
  148.     mov    si,offset bogus_type
  149.     movseg    es,cs
  150.     mov    di,offset our_recv
  151.     call    int_pkt
  152.     call    fatal_error
  153.     mov    handle,ax
  154.  
  155.     mov    ah,24            ;get the statistics
  156.     mov    bx,handle
  157.     call    int_pkt
  158.     jc    bad
  159.     mov    ds,their_ds
  160.     assume    ds:nothing
  161. ;ds:si now points to the statistics list.
  162.     mov    cx,statistics_count/2
  163.     mov    ax,cs
  164.     mov    es,ax
  165.     mov    di,offset statistics_list
  166.     rep    movsw
  167.     mov    ds,ax            ;restore ds to cs.
  168.  
  169.     cmp    printed_names,0        ;have we printed the names yet?
  170.     jne    did_print_names
  171.  
  172.     inc    printed_names
  173.     mov    dx,offset stat_names
  174.     mov    ah,9
  175.     int    21h
  176. did_print_names:
  177.  
  178.     mov    al,entry_point    ;print the packet interrupt number.
  179.     call    byteout
  180.     mov    al,'I'-40h        ;tab over.
  181.     call    chrout
  182.  
  183.     mov    bx,offset statistics_list
  184.     mov    cx,statistics_count/4
  185. print_stats:
  186.     mov    ax,[bx]
  187.     mov    dx,[bx+2]
  188.     push    bx
  189.     push    cx
  190.     call    decout
  191.     pop    cx
  192.     pop    bx
  193.     add    bx,4
  194.     mov    al,'I'-40h        ;tab over.
  195.     call    chrout
  196.     loop    print_stats
  197.  
  198.     mov    dx,offset crlf_msg
  199.     mov    ah,9
  200.     int    21h
  201.  
  202.     mov    ah,3            ;release_type
  203.     mov    bx,handle
  204.     call    int_pkt
  205.     call    fatal_error
  206.  
  207.     clc
  208.     ret
  209.  
  210.  
  211. bad:
  212.     movseg    ds,cs
  213.     call    print_error
  214.  
  215.     mov    ah,3            ;release_type
  216.     mov    bx,handle
  217.     call    int_pkt
  218.     call    fatal_error
  219.  
  220.     int    20h
  221.  
  222.  
  223. our_recv:
  224.     or    ax,ax            ;first or second call?
  225.     jne    our_recv_1        ;second -- we ignore the packet
  226.     movseg    es,cs
  227.     mov    di,offset our_buffer
  228. our_recv_1:
  229.     retf
  230.  
  231.  
  232. int_pkt:
  233.     push    ds
  234.     push    es
  235.     pushf
  236.     cli
  237.     call    their_isr
  238.     mov    cs:their_ds,ds
  239.     pop    es
  240.     pop    ds
  241.     ret
  242.  
  243.     include    printea.asm
  244.  
  245.     assume    ds:code
  246.  
  247.     include    pkterr.asm
  248.     include    getnum.asm
  249.     include    skipblk.asm
  250.     include    getdig.asm
  251.     include    decout.asm
  252.     include    digout.asm
  253.     include    chrout.asm
  254.  
  255.     align    4
  256. our_buffer    label    byte
  257.  
  258. code    ends
  259.  
  260.     end    start
  261.