Subversion Repositories Kolibri OS

Rev

Rev 3601 | Go to most recent revision | Blame | Compare with Previous | 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 + EVM_STACK2
  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.         cmp     eax, 11
  445.         je      redraw
  446.  
  447.         jmp     draw_stats
  448.  
  449. button:                         ; button
  450.         mcall   17              ; get id
  451.         cmp     ah, 1
  452.         je      exit
  453.         cmp     ah, 0
  454.         je      .interface
  455.         mov     [mode], ah
  456.         jmp     redraw
  457.  
  458.   .interface:
  459.         shr     eax, 16
  460.         mov     [device], al
  461.         jmp     redraw
  462.  
  463. exit:
  464.         mcall   -1
  465.  
  466.  
  467.  
  468. draw_mac:
  469.  
  470.         mov     eax, 47
  471.         mov     ebx, 0x00020100
  472.         mov     esi, 0x40000000
  473.         mov     edi, 0x00bcbcbc
  474.  
  475.         mov     cl, [esp+4]
  476.         mcall
  477.  
  478.         mov     cl, [esp+4+1]
  479.         add     edx, 15 shl 16
  480.         mcall
  481.  
  482.         mov     cl, [esp+4+2]
  483.         add     edx, 15 shl 16
  484.         mcall
  485.  
  486.         mov     cl, [esp+4+3]
  487.         add     edx, 15 shl 16
  488.         mcall
  489.  
  490.         mov     cl, [esp+4+4]
  491.         add     edx, 15 shl 16
  492.         mcall
  493.  
  494.         mov     cl, [esp+4+5]
  495.         add     edx, 15 shl 16
  496.         mcall
  497.  
  498.         sub     edx, 5*15 shl 16
  499.  
  500.         ret     6
  501.  
  502.  
  503. draw_ip:
  504.  
  505.         mov     eax, 47
  506.         mov     ebx, 0x00030000
  507.         mov     esi, 0x40000000
  508.         mov     edi, 0x00bcbcbc
  509.  
  510.         xor     ecx, ecx
  511.  
  512.         mov     cl, [esp+4]
  513.         mcall
  514.  
  515.         mov     cl, [esp+4+1]
  516.         add     edx, 30 shl 16
  517.         mcall
  518.  
  519.         mov     cl, [esp+4+2]
  520.         add     edx, 30 shl 16
  521.         mcall
  522.  
  523.         mov     cl, [esp+4+3]
  524.         add     edx, 30 shl 16
  525.         mcall
  526.  
  527.         sub     edx, 3*30 shl 16
  528.         ret     4
  529.  
  530.  
  531. draw_interfaces:
  532.  
  533.         mov     [.btnpos], 8 shl 16 + 20
  534.         mov     [.txtpos], 490 shl 16 + 15
  535.  
  536.         mcall   74, -1          ; get number of active network devices
  537.         mov     ecx, eax
  538.  
  539.         xor     ebx, ebx        ; get device type
  540.   .loop:
  541.         mcall   74
  542.         cmp     eax, 1          ; ethernet?
  543.         je      .hit
  544.         inc     bh
  545.         jb      .loop           ; tried all 256?
  546.         ret
  547.  
  548.  
  549.   .hit:
  550.         push    ecx ebx
  551.         movzx   edx, bh
  552.         shl     edx, 8
  553.         mov     esi, 0x00aaaaff
  554.         cmp     bh, [device]
  555.         cmove   esi, 0x00aaffff
  556.         mcall   8, 485 shl 16 + 100, [.btnpos]
  557.         mov     ebx, [esp]
  558.         inc     bl
  559.         mov     ecx, namebuf
  560.         mov     edx, namebuf
  561.         mcall   74              ; get device name
  562.         cmp     eax, -1
  563.         jne     @f
  564.         mov     edx, str_unknown
  565.        @@:
  566.         mcall   4, [.txtpos], 0x80000000   ; print the name
  567.         pop     ebx ecx
  568.  
  569.         inc     bh
  570.  
  571.         add     [.btnpos], 25 shl 16
  572.         add     [.txtpos], 25
  573.  
  574.         dec     ecx
  575.         jnz     .loop
  576.  
  577.         ret
  578.  
  579.   .btnpos       dd ?
  580.   .txtpos       dd ?
  581.  
  582.  
  583.  
  584.  
  585. ; DATA AREA
  586.  
  587. name            db 'Netstat', 0
  588. mode            db 101
  589. device          db 0
  590. modes           db 'Ethernet        IPv4        ARP         ICMP         UDP         TCP', 0
  591.  
  592. str_packets_tx  db 'Packets sent:', 0
  593. str_packets_rx  db 'Packets received:', 0
  594. str_bytes_tx    db 'Bytes sent:', 0
  595. str_bytes_rx    db 'Bytes received:', 0
  596. str_MAC         db 'MAC address:', 0
  597. str_ip          db 'IP address:', 0
  598. str_dns         db 'DNS address:', 0
  599. str_subnet      db 'Subnet mask:', 0
  600. str_gateway     db 'Standard gateway:', 0
  601. str_arp         db 'ARP entrys:', 0
  602. str_conflicts   db 'ARP conflicts:', 0
  603. str_unknown     db 'unknown', 0
  604. str_missed      db 'Packets missed:',0
  605. str_dumped      db 'Packets dumped:',0
  606. str_link        db 'Link state:',0
  607.  
  608. namebuf         rb 64
  609.  
  610. I_PARAM rb 1024
  611.  
  612. I_END:
  613.  
  614.  
  615.