Subversion Repositories Kolibri OS

Rev

Rev 2364 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;
  2. ; Netstat for KolibriOS v0.2
  3. ;
  4. ; 0.1 - 22 sept 2009 - initial release
  5. ; 0.2 - 9 july 2012 - converted to new sysfunc numbers
  6. ;
  7. ; hidnplayr@gmail.com
  8. ;
  9.  
  10. format binary as ""
  11.  
  12. use32
  13.  
  14.     org     0x0
  15.  
  16.     db     'MENUET01'        ; 8 byte id
  17.     dd     0x01              ; header version
  18.     dd     START             ; start of code
  19.     dd     I_END             ; size of image
  20.     dd     (I_END+0x100)     ; memory for app
  21.     dd     (I_END+0x100)     ; esp
  22.     dd     I_PARAM , 0x0     ; I_Param , I_Icon
  23.  
  24. __DEBUG__ equ 1
  25. __DEBUG_LEVEL__ equ 1
  26.  
  27. include '..\macros.inc'
  28. include '..\debug-fdo.inc'
  29. include '..\network.inc'
  30.  
  31. START:                                 ; start of execution
  32.     ; TODO: check Parameters
  33.  
  34.     DEBUGF  1, 'Netstat application loaded!\n'
  35.  
  36.   redraw:
  37.     mcall   12, 1
  38.  
  39.     mcall   0, 100 shl 16 + 520, 100 shl 16 + 240, 0x34bcbcbc , , name
  40.  
  41.     mov     edx, 101
  42.     mov     esi, 0x00aaaaff
  43.     mov     edi, 0x00aaffff
  44.  
  45.     cmp     dl, [mode]
  46.     cmove   esi, edi
  47.     mcall   8, 25 shl 16 + 65, 25 shl 16 + 20
  48.  
  49.   .morebuttons:
  50.     inc     edx
  51.     add     ebx, 75 shl 16
  52.     mov     esi, 0x00aaaaff
  53.  
  54.     cmp     dl, [mode]
  55.     cmove   esi, edi
  56.     mcall
  57.  
  58.     cmp     edx, 105
  59.     jle     .morebuttons
  60.  
  61.     mcall   4, 28 shl 16 + 31, 0x80000000, modes
  62.  
  63.     cmp     [mode], 101
  64.     jne     .no_eth
  65.  
  66.     mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
  67.     add     ebx, 18
  68.     mov     edx, str_packets_rx
  69.     mcall
  70.     add     ebx, 18
  71.     mov     edx, str_bytes_tx
  72.     mcall
  73.     add     ebx, 18
  74.     mov     edx, str_bytes_rx
  75.     mcall
  76.     add     ebx, 18
  77.     mov     edx, str_MAC
  78.     mcall
  79.     add     ebx, 18
  80.     mov     edx, str_queue_in
  81.     mcall
  82.     add     ebx, 18
  83.     mov     edx, str_queue_out
  84.     mcall
  85.  
  86.     mov     ebx, API_ETH + 4
  87.     mov     bh, [device]
  88.     mcall   76
  89.     push    eax
  90.     push    bx
  91.  
  92.     mov     edx, 135 shl 16 + 75 + 4*18
  93.     call    draw_mac
  94.     jmp     end_of_draw
  95.  
  96.  .no_eth:
  97.  
  98.     cmp     [mode], 102
  99.     jne     .no_ip
  100.  
  101.     mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
  102.     add     ebx, 18
  103.     mov     edx, str_packets_rx
  104.     mcall
  105.     add     ebx, 18
  106.     mov     edx, str_ip
  107.     mcall
  108.     add     ebx, 18
  109.     mov     edx, str_dns
  110.     mcall
  111.     add     ebx, 18
  112.     mov     edx, str_subnet
  113.     mcall
  114.     add     ebx, 18
  115.     mov     edx, str_gateway
  116.     mcall
  117.  
  118.  
  119.     mov     ebx, API_IPv4 + 8
  120.     mov     bh, [device]
  121.     mcall   76
  122.     push    eax
  123.  
  124.     dec     bl
  125.     dec     bl
  126.     mcall   76
  127.     push    eax
  128.  
  129.     dec     bl
  130.     dec     bl
  131.     mcall   76
  132.     push    eax
  133.  
  134.     dec     bl
  135.     dec     bl
  136.     mcall   76
  137.     push    eax
  138.  
  139.     mov     edx, 135 shl 16 + 75 + 2*18
  140.     call    draw_ip
  141.  
  142.     add     edx, 18
  143.     call    draw_ip
  144.  
  145.     add     edx, 18
  146.     call    draw_ip
  147.  
  148.     add     edx, 18
  149.     call    draw_ip
  150.  
  151.     jmp     end_of_draw
  152.  
  153.  .no_ip:
  154.  
  155.     cmp     [mode], 103
  156.     jne     .no_arp
  157.  
  158.     mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
  159.     add     ebx, 18
  160.     mov     edx, str_packets_rx
  161.     mcall
  162.     add     ebx, 18
  163.     mov     edx, str_arp
  164.     mcall
  165.  
  166.     jmp     end_of_draw
  167.  
  168.  .no_arp:
  169.  
  170.     mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
  171.     add     ebx, 18
  172.     mov     edx, str_packets_rx
  173.     mcall
  174.  
  175.  end_of_draw:
  176.  
  177.     mcall   12, 2
  178.  
  179.     jmp     draw_stats
  180.  
  181.   mainloop:
  182.  
  183.     mcall   23,500                  ; wait for event with timeout    (0,5 s)
  184.  
  185.     cmp     eax, 1
  186.     je      redraw
  187.     cmp     eax, 2
  188.     je      key
  189.     cmp     eax, 3
  190.     je      button
  191.  
  192.  
  193.  
  194.  
  195. ;-------------------------------
  196. ;
  197. ;------------------------------
  198.  
  199.   draw_stats:
  200.  
  201.     cmp     [mode], 101
  202.     jne     not_101
  203.  
  204.     mov     ebx, API_ETH
  205.     mov     bh, [device]
  206.    @@:
  207.     push    ebx
  208.     mcall   76
  209.     pop     ebx
  210.     push    eax
  211.     inc     bl
  212.     cmp     bl, 3
  213.     jle     @r
  214.  
  215.     inc     bl   ;5
  216.     inc     bl   ;6
  217.  
  218.    @@:
  219.     push    ebx
  220.     mcall   76
  221.     pop     ebx
  222.     push    eax
  223.     inc     bl
  224.     cmp     bl, 7
  225.     jle     @r
  226.  
  227.     mov     eax, 47
  228.     mov     ebx, 0x000a0000
  229.     mov     esi, 0x40000000
  230.     mov     edi, 0x00bcbcbc
  231.     mov     edx, 135 shl 16 + 75 + 6*18
  232.     pop     ecx
  233.     mcall
  234.     sub     edx, 18
  235.     pop     ecx
  236.     mcall
  237.     sub     edx, 2*18
  238.     pop     ecx
  239.     mcall
  240.     sub     edx, 18
  241.     pop     ecx
  242.     mcall
  243.     sub     edx, 18
  244.     pop     ecx
  245.     mcall
  246.     sub     edx, 18
  247.     pop     ecx
  248.     mcall
  249.  
  250.     jmp     mainloop
  251.  
  252.  
  253.  not_101:
  254.  
  255.     cmp     [mode], 102
  256.     jne     not_102
  257.  
  258.     mov     ebx, API_IPv4
  259.     mov     bh, [device]
  260.     push    ebx
  261.     mcall   76
  262.     pop     ebx
  263.     push    eax
  264.     inc     bl
  265.     push    ebx
  266.     mcall   76
  267.     pop     ebx
  268.     push    eax
  269.     inc     bl
  270.  
  271.     mov     eax, 47
  272.     mov     ebx, 0x000a0000
  273.     mov     esi, 0x40000000
  274.     mov     edi, 0x00bcbcbc
  275.     mov     edx, 135 shl 16 + 75 + 18
  276.     pop     ecx
  277.     mcall
  278.     sub     edx, 18
  279.     pop     ecx
  280.     mcall
  281.  
  282.     jmp     mainloop
  283.  
  284.  
  285.  not_102:
  286.  
  287.     cmp     [mode], 103
  288.     jne     not_103
  289.  
  290.     mov     ebx, API_ARP
  291.     mov     bh, [device]
  292.     push    ebx
  293.     mcall   76
  294.     pop     ebx
  295.     push    eax
  296.     inc     bl
  297.     push    ebx
  298.     mcall   76
  299.     pop     ebx
  300.     push    eax
  301.     inc     bl
  302.     push    ebx
  303.     mcall   76
  304.     pop     ebx
  305.     push    eax
  306.     inc     bl
  307.  
  308.     mov     eax, 47
  309.     mov     ebx, 0x000a0000
  310.     mov     esi, 0x40000000
  311.     mov     edi, 0x00bcbcbc
  312.     mov     edx, 135 shl 16 + 75 + 2*18
  313.     pop     ecx
  314.     mcall
  315.     sub     edx, 18
  316.     pop     ecx
  317.     mcall
  318.     sub     edx, 18
  319.     pop     ecx
  320.     mcall
  321.  
  322.     jmp     mainloop
  323.  
  324. not_103:
  325.  
  326.     cmp     [mode], 104
  327.     jne     not_104
  328.  
  329.     mov     ebx, API_ICMP
  330.     mov     bh, [device]
  331.     push    ebx
  332.     mcall   76
  333.     pop     ebx
  334.     push    eax
  335.     inc     bl
  336.     push    ebx
  337.     mcall   76
  338.     pop     ebx
  339.     push    eax
  340.     inc     bl
  341.  
  342.     mov     eax, 47
  343.     mov     ebx, 0x000a0000
  344.     mov     esi, 0x40000000
  345.     mov     edi, 0x00bcbcbc
  346.     mov     edx, 135 shl 16 + 75 + 18
  347.     pop     ecx
  348.     mcall
  349.     sub     edx, 18
  350.     pop     ecx
  351.     mcall
  352.  
  353.     jmp     mainloop
  354.  
  355. not_104:
  356.  
  357.     cmp     [mode], 105
  358.     jne     not_105
  359.  
  360.     mov     ebx, API_UDP
  361.     mov     bh, [device]
  362.     push    ebx
  363.     mcall   76
  364.     pop     ebx
  365.     push    eax
  366.     inc     bl
  367.     push    ebx
  368.     mcall   76
  369.     pop     ebx
  370.     push    eax
  371.     inc     bl
  372.  
  373.     mov     eax, 47
  374.     mov     ebx, 0x000a0000
  375.     mov     esi, 0x40000000
  376.     mov     edi, 0x00bcbcbc
  377.     mov     edx, 135 shl 16 + 75 + 18
  378.     pop     ecx
  379.     mcall
  380.     sub     edx, 18
  381.     pop     ecx
  382.     mcall
  383.  
  384.     jmp     mainloop
  385.  
  386. not_105:
  387.  
  388.     cmp     [mode], 106
  389.     jne     not_106
  390.  
  391.     mov     ebx, API_TCP
  392.     mov     bh, [device]
  393.     push    ebx
  394.     mcall   76
  395.     pop     ebx
  396.     push    eax
  397.     inc     bl
  398.     push    ebx
  399.     mcall   76
  400.     pop     ebx
  401.     push    eax
  402.     inc     bl
  403.  
  404.     mov     eax, 47
  405.     mov     ebx, 0x000a0000
  406.     mov     esi, 0x40000000
  407.     mov     edi, 0x00bcbcbc
  408.     mov     edx, 135 shl 16 + 75 + 18
  409.     pop     ecx
  410.     mcall
  411.     sub     edx, 18
  412.     pop     ecx
  413.     mcall
  414.  
  415.     jmp     mainloop
  416.  
  417. not_106:
  418.  
  419.     jmp     mainloop
  420.  
  421.   key:
  422.     mcall   2
  423.     jmp     mainloop
  424.  
  425.  
  426.   button:                         ; button
  427.     mcall   17                    ; get id
  428.     cmp     ah, 1
  429.     je      exit
  430.     mov     [mode], ah
  431.     jmp     redraw
  432.  
  433.   exit:
  434.     mcall   -1
  435.  
  436.  
  437.  
  438. draw_mac:
  439.  
  440.         mov     eax, 47
  441.         mov     ebx, 0x00020100
  442.         mov     esi, 0x40000000
  443.         mov     edi, 0x00bcbcbc
  444.  
  445.         mov     cl, [esp+4]
  446.         mcall
  447.  
  448.         mov     cl, [esp+4+1]
  449.         add     edx, 15 shl 16
  450.         mcall
  451.  
  452.         mov     cl, [esp+4+2]
  453.         add     edx, 15 shl 16
  454.         mcall
  455.  
  456.         mov     cl, [esp+4+3]
  457.         add     edx, 15 shl 16
  458.         mcall
  459.  
  460.         mov     cl, [esp+4+4]
  461.         add     edx, 15 shl 16
  462.         mcall
  463.  
  464.         mov     cl, [esp+4+5]
  465.         add     edx, 15 shl 16
  466.         mcall
  467.  
  468.         sub     edx, 5*15 shl 16
  469.  
  470.         ret     6
  471.  
  472.  
  473. draw_ip:
  474.  
  475.         mov     eax, 47
  476.         mov     ebx, 0x00030000
  477.         mov     esi, 0x40000000
  478.         mov     edi, 0x00bcbcbc
  479.  
  480.         xor     ecx, ecx
  481.  
  482.         mov     cl, [esp+4]
  483.         mcall
  484.  
  485.         mov     cl, [esp+4+1]
  486.         add     edx, 30 shl 16
  487.         mcall
  488.  
  489.         mov     cl, [esp+4+2]
  490.         add     edx, 30 shl 16
  491.         mcall
  492.  
  493.         mov     cl, [esp+4+3]
  494.         add     edx, 30 shl 16
  495.         mcall
  496.  
  497.         sub     edx, 3*30 shl 16
  498.         ret     4
  499.  
  500.  
  501. ; DATA AREA
  502.  
  503. name    db 'Netstat', 0
  504. mode    db 101
  505. device  db 0
  506. modes   db 'Ethernet        IPv4        ARP         ICMP         UDP         TCP', 0
  507.  
  508. str_packets_tx db 'Packets sent:', 0
  509. str_packets_rx db 'Packets received:', 0
  510. str_bytes_tx   db 'Bytes sent:', 0
  511. str_bytes_rx   db 'Bytes received:', 0
  512. str_MAC        db 'MAC address:', 0
  513. str_queue_in   db 'IN-queue size:', 0
  514. str_queue_out  db 'OUT-queue size:', 0
  515. str_ip         db 'IP address:', 0
  516. str_dns        db 'DNS address:', 0
  517. str_subnet     db 'Subnet mask:', 0
  518. str_gateway    db 'Standard gateway:', 0
  519. str_arp        db 'ARP entrys:', 0
  520.  
  521. include_debug_strings    ; ALWAYS present in data section
  522.  
  523. I_PARAM rb 1024
  524.  
  525. I_END:
  526.  
  527.  
  528.