Subversion Repositories Kolibri OS

Rev

Rev 2853 | Blame | Last modification | View Log | Download | RSS feed

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