Subversion Repositories Kolibri OS

Rev

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