Subversion Repositories Kolibri OS

Rev

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

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