Subversion Repositories Kolibri OS

Rev

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