Subversion Repositories Kolibri OS

Rev

Rev 2864 | Go to most recent revision | 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.         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.         add     ebx, 18
  166.         mov     edx, str_conflicts
  167.         mcall
  168.  
  169.         jmp     end_of_draw
  170.  
  171.  .no_arp:
  172.  
  173.         mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
  174.         add     ebx, 18
  175.         mov     edx, str_packets_rx
  176.         mcall
  177.  
  178.  
  179.  
  180. end_of_draw:
  181.         mcall   12, 2
  182.  
  183. draw_stats:
  184.  
  185.         cmp     [mode], 101
  186.         jne     not_101
  187.  
  188.         mov     ebx, API_ETH
  189.         mov     bh, [device]
  190.   @@:
  191.         push    ebx
  192.         mcall   76
  193.         pop     ebx
  194.         push    eax
  195.         inc     bl
  196.         cmp     bl, 3
  197.         jbe     @r
  198.  
  199.         inc     bl   ;5
  200.         inc     bl   ;6
  201.  
  202.   @@:
  203.         push    ebx
  204.         mcall   76
  205.         pop     ebx
  206.  
  207.         push    eax
  208.         inc     bl
  209.         cmp     bl, 7
  210.         jbe     @r
  211.  
  212.         mov     ebx, 0x000a0000
  213.         pop     ecx
  214.         mov     edx, 135 shl 16 + 75 + 6*18
  215.         mov     esi, 0x40000000
  216.         mov     edi, 0x00bcbcbc
  217.         mcall   47
  218.  
  219.         sub     edx, 18
  220.         pop     ecx
  221.         mcall
  222.  
  223.         sub     edx, 2*18
  224.         pop     ecx
  225.         mcall
  226.  
  227.         sub     edx, 18
  228.         pop     ecx
  229.         mcall
  230.  
  231.         sub     edx, 18
  232.         pop     ecx
  233.         mcall
  234.  
  235.         sub     edx, 18
  236.         pop     ecx
  237.         mcall
  238.  
  239.         jmp     mainloop
  240.  
  241.  
  242. not_101:
  243.  
  244.         cmp     [mode], 102
  245.         jne     not_102
  246.  
  247.         mov     ebx, API_IPv4
  248.         mov     bh, [device]
  249.         push    ebx
  250.         mcall   76
  251.         pop     ebx
  252.         push    eax
  253.  
  254.         inc     bl
  255.         push    ebx
  256.         mcall   76
  257.         pop     ebx
  258.         push    eax
  259.  
  260.  
  261.         mov     ebx, 0x000a0000
  262.         pop     ecx
  263.         mov     edx, 135 shl 16 + 75 + 18
  264.         mov     esi, 0x40000000
  265.         mov     edi, 0x00bcbcbc
  266.         mcall   47
  267.  
  268.         sub     edx, 18
  269.         pop     ecx
  270.         mcall
  271.  
  272.         jmp     mainloop
  273.  
  274.  
  275. not_102:
  276.  
  277.         cmp     [mode], 103
  278.         jne     not_103
  279.  
  280.         mov     ebx, API_ARP
  281.         mov     bh, [device]
  282.         push    ebx
  283.         mcall   76
  284.         pop     ebx
  285.         push    eax
  286.  
  287.         inc     bl
  288.         push    ebx
  289.         mcall   76
  290.         pop     ebx
  291.         push    eax
  292.  
  293.         inc     bl
  294.         push    ebx
  295.         mcall   76
  296.         pop     ebx
  297.         push    eax
  298.  
  299.         mov     bl, 7
  300.         push    ebx
  301.         mcall   76
  302.         pop     ebx
  303.         push    eax
  304.  
  305.         mov     ebx, 0x000a0000
  306.         pop     ecx
  307.         mov     edx, 135 shl 16 + 75 + 3*18
  308.         mov     esi, 0x40000000
  309.         mov     edi, 0x00bcbcbc
  310.         mcall   47
  311.  
  312.         sub     edx, 18
  313.         pop     ecx
  314.         mcall
  315.  
  316.         sub     edx, 18
  317.         pop     ecx
  318.         mcall
  319.  
  320.         sub     edx, 18
  321.         pop     ecx
  322.         mcall
  323.  
  324.         jmp     mainloop
  325.  
  326. not_103:
  327.  
  328.         cmp     [mode], 104
  329.         jne     not_104
  330.  
  331.         mov     ebx, API_ICMP
  332.         mov     bh, [device]
  333.         push    ebx
  334.         mcall   76
  335.         pop     ebx
  336.         push    eax
  337.  
  338.         inc     bl
  339.         push    ebx
  340.         mcall   76
  341.         pop     ebx
  342.         push    eax
  343.  
  344.         mov     ebx, 0x000a0000
  345.         pop     ecx
  346.         mov     edx, 135 shl 16 + 75 + 18
  347.         mov     esi, 0x40000000
  348.         mov     edi, 0x00bcbcbc
  349.         mcall   47
  350.  
  351.         sub     edx, 18
  352.         pop     ecx
  353.         mcall
  354.  
  355.         jmp     mainloop
  356.  
  357. not_104:
  358.  
  359.         cmp     [mode], 105
  360.         jne     not_105
  361.  
  362.         mov     ebx, API_UDP
  363.         mov     bh, [device]
  364.         push    ebx
  365.         mcall   76
  366.         pop     ebx
  367.         push    eax
  368.  
  369.         inc     bl
  370.         push    ebx
  371.         mcall   76
  372.         pop     ebx
  373.         push    eax
  374.  
  375.         mov     ebx, 0x000a0000
  376.         pop     ecx
  377.         mov     edx, 135 shl 16 + 75 + 18
  378.         mov     esi, 0x40000000
  379.         mov     edi, 0x00bcbcbc
  380.         mcall   47
  381.  
  382.         sub     edx, 18
  383.         pop     ecx
  384.         mcall
  385.  
  386.         jmp     mainloop
  387.  
  388. not_105:
  389.  
  390.         cmp     [mode], 106
  391.         jne     not_106
  392.  
  393.         mov     ebx, API_TCP
  394.         mov     bh, [device]
  395.         push    ebx
  396.         mcall   76
  397.         pop     ebx
  398.         push    eax
  399.  
  400.         inc     bl
  401.         push    ebx
  402.         mcall   76
  403.         pop     ebx
  404.         push    eax
  405.  
  406.         mov     ebx, 0x000a0000
  407.         pop     ecx
  408.         mov     edx, 135 shl 16 + 75 + 18
  409.         mov     esi, 0x40000000
  410.         mov     edi, 0x00bcbcbc
  411.         mcall   47
  412.  
  413.         sub     edx, 18
  414.         pop     ecx
  415.         mcall
  416.  
  417.         jmp     mainloop
  418.  
  419. not_106:
  420.  
  421. mainloop:
  422.  
  423.         mcall   23, 50          ; wait for event with timeout    (0,5 s)
  424.  
  425.         cmp     eax, 1
  426.         je      redraw
  427.         cmp     eax, 3
  428.         je      button
  429.  
  430.         jmp     draw_stats
  431.  
  432. button:                         ; button
  433.         mcall   17              ; get id
  434.         cmp     ah, 1
  435.         je      exit
  436.         cmp     ah, 0
  437.         je      .interface
  438.         mov     [mode], ah
  439.         jmp     redraw
  440.  
  441.   .interface:
  442.         shr     eax, 16
  443.         mov     [device], al
  444.         jmp     redraw
  445.  
  446. exit:
  447.         mcall   -1
  448.  
  449.  
  450.  
  451. draw_mac:
  452.  
  453.         mov     eax, 47
  454.         mov     ebx, 0x00020100
  455.         mov     esi, 0x40000000
  456.         mov     edi, 0x00bcbcbc
  457.  
  458.         mov     cl, [esp+4]
  459.         mcall
  460.  
  461.         mov     cl, [esp+4+1]
  462.         add     edx, 15 shl 16
  463.         mcall
  464.  
  465.         mov     cl, [esp+4+2]
  466.         add     edx, 15 shl 16
  467.         mcall
  468.  
  469.         mov     cl, [esp+4+3]
  470.         add     edx, 15 shl 16
  471.         mcall
  472.  
  473.         mov     cl, [esp+4+4]
  474.         add     edx, 15 shl 16
  475.         mcall
  476.  
  477.         mov     cl, [esp+4+5]
  478.         add     edx, 15 shl 16
  479.         mcall
  480.  
  481.         sub     edx, 5*15 shl 16
  482.  
  483.         ret     6
  484.  
  485.  
  486. draw_ip:
  487.  
  488.         mov     eax, 47
  489.         mov     ebx, 0x00030000
  490.         mov     esi, 0x40000000
  491.         mov     edi, 0x00bcbcbc
  492.  
  493.         xor     ecx, ecx
  494.  
  495.         mov     cl, [esp+4]
  496.         mcall
  497.  
  498.         mov     cl, [esp+4+1]
  499.         add     edx, 30 shl 16
  500.         mcall
  501.  
  502.         mov     cl, [esp+4+2]
  503.         add     edx, 30 shl 16
  504.         mcall
  505.  
  506.         mov     cl, [esp+4+3]
  507.         add     edx, 30 shl 16
  508.         mcall
  509.  
  510.         sub     edx, 3*30 shl 16
  511.         ret     4
  512.  
  513.  
  514. draw_interfaces:
  515.  
  516.         mov     [.btnpos], 8 shl 16 + 20
  517.         mov     [.txtpos], 490 shl 16 + 15
  518.  
  519.         mcall   74, -1          ; get number of active network devices
  520.         mov     ecx, eax
  521.  
  522.         xor     ebx, ebx        ; get device type
  523.   .loop:
  524.         mcall   74
  525.         cmp     eax, 1          ; ethernet?
  526.         je      .hit
  527.         inc     bh
  528.         jb      .loop           ; tried all 256?
  529.         ret
  530.  
  531.  
  532.   .hit:
  533.         push    ecx ebx
  534.         movzx   edx, bh
  535.         shl     edx, 8
  536.         mov     esi, 0x00aaaaff
  537.         cmp     bh, [device]
  538.         cmove   esi, 0x00aaffff
  539.         mcall   8, 485 shl 16 + 100, [.btnpos]
  540.         mov     ebx, [esp]
  541.         inc     bl
  542.         mov     ecx, namebuf
  543.         mov     edx, namebuf
  544.         mcall   74              ; get device name
  545.         cmp     eax, -1
  546.         jne     @f
  547.         mov     edx, str_unknown
  548.        @@:
  549.         mcall   4, [.txtpos], 0x80000000   ; print the name
  550.         pop     ebx ecx
  551.  
  552.         inc     bh
  553.  
  554.         add     [.btnpos], 25 shl 16
  555.         add     [.txtpos], 25
  556.  
  557.         dec     ecx
  558.         jnz     .loop
  559.  
  560.         ret
  561.  
  562.   .btnpos       dd ?
  563.   .txtpos       dd ?
  564.  
  565.  
  566.  
  567.  
  568. ; DATA AREA
  569.  
  570. name            db 'Netstat', 0
  571. mode            db 101
  572. device          db 0
  573. modes           db 'Ethernet        IPv4        ARP         ICMP         UDP         TCP', 0
  574.  
  575. str_packets_tx  db 'Packets sent:', 0
  576. str_packets_rx  db 'Packets received:', 0
  577. str_bytes_tx    db 'Bytes sent:', 0
  578. str_bytes_rx    db 'Bytes received:', 0
  579. str_MAC         db 'MAC address:', 0
  580. str_queue_in    db 'IN-queue size:', 0
  581. str_queue_out   db 'OUT-queue size:', 0
  582. str_ip          db 'IP address:', 0
  583. str_dns         db 'DNS address:', 0
  584. str_subnet      db 'Subnet mask:', 0
  585. str_gateway     db 'Standard gateway:', 0
  586. str_arp         db 'ARP entrys:', 0
  587. str_conflicts   db 'ARP conflicts:', 0
  588. str_unknown     db 'unknown', 0
  589.  
  590. namebuf         rb 64
  591.  
  592. I_PARAM rb 1024
  593.  
  594. I_END:
  595.  
  596.  
  597.