Subversion Repositories Kolibri OS

Rev

Rev 4736 | Rev 4740 | 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+0x1000)   ; memory for app
  26.         dd     (I_END+0x1000)   ; esp
  27.         dd     0, 0             ; I_Param , I_Path
  28.  
  29. include '../../macros.inc'
  30. include '../../network.inc'
  31.  
  32.  
  33. macro DrawRectangle x, y, w, h, color
  34. {
  35.         mcall 13, x shl 16 + w,     y shl 16 + 1,     color   ; top
  36.         mcall   , x shl 16 + 1,     y shl 16 + h,     color   ; left
  37.         mcall   , (x+w) shl 16 +1,  y shl 16 + (h+1), color   ; right
  38.         mcall   , x shl 16 + w,   (y+h) shl 16 + 1,   color   ; bottom
  39. }
  40.  
  41.  
  42. START:
  43.         mcall   40, EVM_REDRAW + EVM_BUTTON + EVM_STACK2
  44.  
  45. window_redraw:
  46.         mcall   12, 1
  47.         mcall   0, 100 shl 16 + 600, 100 shl 16 + 240, 0x34E1E1E1, , name       ; draw window
  48.                 mcall   12, 2
  49.                 DrawRectangle 0, 25, 400, 180, 0x777777
  50.  
  51. redraw:
  52.                 mcall   13, 1 shl 16 + 399, 26 shl 16 + 179, 0x00F3F3F3
  53.         call    draw_interfaces
  54.  
  55.         xor     ebx, ebx
  56.         mov     bh, [device]
  57.         mcall   74
  58.         mov     [device_type], eax
  59.  
  60.         mov     edx, 101
  61.         mov     esi, 0x00BBBbbb
  62.         mov     edi, 0x0081BBFF
  63.  
  64.         cmp     dl, [mode]
  65.         cmove   esi, edi
  66.         mcall   8, 5 shl 16 + 55, 5 shl 16 + 20
  67.   .morebuttons:
  68.         inc     edx
  69.         add     ebx, 60 shl 16
  70.         mov     esi, 0x00BBBbbb
  71.  
  72.         cmp     dl, [mode]
  73.         cmove   esi, edi
  74.         mcall
  75.  
  76.         cmp     edx, 105
  77.         jle     .morebuttons
  78.  
  79.         mcall   4, 9 shl 16 + 12, 0x80000000, modes
  80.  
  81.         cmp     [mode], 101
  82.         jne     .no_eth
  83.  
  84.         mcall   4, 8 shl 16 + 35, 0x80000000, str_packets_tx
  85.         add     ebx, 18
  86.         mov     edx, str_packets_rx
  87.         mcall
  88.         add     ebx, 18
  89.         mov     edx, str_bytes_tx
  90.         mcall
  91.         add     ebx, 18
  92.         mov     edx, str_bytes_rx
  93.         mcall
  94.         add     ebx, 18
  95.         mov     edx, str_link
  96.         mcall
  97.  
  98.         cmp     [device_type], 1
  99.         jne     end_of_draw
  100.  
  101.         add     ebx, 18
  102.         mov     edx, str_MAC
  103.         mcall
  104.  
  105.         mov     ebx, API_ETH
  106.         mov     bh, [device]
  107.         mcall   76
  108.         push    eax
  109.         push    bx
  110.  
  111.         mov     edx, 135 shl 16 + 35 + 5*18
  112.         call    draw_mac
  113.         jmp     end_of_draw
  114.  
  115.  .no_eth:
  116.  
  117.         cmp     [mode], 102
  118.         jne     .no_ip
  119.  
  120.         mcall   4, 8 shl 16 + 35, 0x80000000, str_packets_tx
  121.         add     ebx, 18
  122.         mov     edx, str_packets_rx
  123.         mcall
  124.         add     ebx, 18
  125.         mov     edx, str_ip
  126.         mcall
  127.         add     ebx, 18
  128.         mov     edx, str_dns
  129.         mcall
  130.         add     ebx, 18
  131.         mov     edx, str_subnet
  132.         mcall
  133.         add     ebx, 18
  134.         mov     edx, str_gateway
  135.         mcall
  136.  
  137.  
  138.         mov     ebx, API_IPv4 + 8
  139.         mov     bh, [device]
  140.         mcall   76
  141.         push    eax
  142.  
  143.         dec     bl
  144.         dec     bl
  145.         mcall   76
  146.         push    eax
  147.  
  148.         dec     bl
  149.         dec     bl
  150.         mcall   76
  151.         push    eax
  152.  
  153.         dec     bl
  154.         dec     bl
  155.         mcall   76
  156.         push    eax
  157.  
  158.         mov     edx, 135 shl 16 + 35 + 2*18
  159.         call    draw_ip
  160.  
  161.         add     edx, 18
  162.         call    draw_ip
  163.  
  164.         add     edx, 18
  165.         call    draw_ip
  166.  
  167.         add     edx, 18
  168.         call    draw_ip
  169.  
  170.         jmp     end_of_draw
  171.  
  172.  .no_ip:
  173.  
  174.         cmp     [mode], 103
  175.         jne     .no_arp
  176.  
  177.         mcall   4, 8 shl 16 + 35, 0x80000000, str_packets_tx
  178.         add     ebx, 18
  179.         mov     edx, str_packets_rx
  180.         mcall
  181.         add     ebx, 18
  182.         mov     edx, str_arp
  183.         mcall
  184.         add     ebx, 18
  185.         mov     edx, str_conflicts
  186.         mcall
  187.  
  188.         mcall   4, 8 shl 16 + 130, 0x80000000, str_ARP_legend
  189.  
  190.         jmp     end_of_draw
  191.  
  192.  .no_arp:
  193.  
  194.         mcall   4, 8 shl 16 + 35, 0x80000000, str_packets_tx
  195.  
  196.         add     ebx, 18
  197.         mov     edx, str_packets_rx
  198.         mcall
  199.  
  200.         cmp     [mode], 106
  201.         jne     end_of_draw
  202.  
  203.         add     ebx, 18
  204.         mov     edx, str_missed
  205.         mcall
  206.  
  207.         add     ebx, 18
  208.         mov     edx, str_dumped
  209.         mcall
  210.  
  211.  
  212.  
  213. end_of_draw:
  214.  
  215. draw_stats:
  216.  
  217.         cmp     [mode], 101
  218.         jne     not_101
  219.  
  220.         mov     ebx, API_ETH
  221.         mov     bh, [device]
  222.         mov     bl, 6
  223.   @@:
  224.         push    ebx
  225.         mcall   74
  226.         pop     ebx
  227.         push    eax
  228.         inc     bl
  229.         cmp     bl, 10
  230.         jbe     @r
  231.  
  232.         mov     ebx, 0x000a0000
  233.         pop     ecx
  234.         mov     edx, 135 shl 16 + 35 + 4*18
  235.         mov     esi, 0x40000000
  236.         mov     edi, 0x00F3F3F3
  237.         mcall   47
  238.  
  239.         sub     edx, 18
  240.         pop     ecx
  241.         mcall
  242.  
  243.         sub     edx, 18
  244.         pop     ecx
  245.         mcall
  246.  
  247.         sub     edx, 18
  248.         pop     ecx
  249.         mcall
  250.  
  251.         sub     edx, 18
  252.         pop     ecx
  253.         mcall
  254.  
  255.         jmp     mainloop
  256.  
  257.  
  258. not_101:
  259.  
  260.         cmp     [mode], 102
  261.         jne     not_102
  262.  
  263.         mov     ebx, API_IPv4
  264.         mov     bh, [device]
  265.         push    ebx
  266.         mcall   76
  267.         pop     ebx
  268.         push    eax
  269.  
  270.         inc     bl
  271.         push    ebx
  272.         mcall   76
  273.         pop     ebx
  274.         push    eax
  275.  
  276.  
  277.         mov     ebx, 0x000a0000
  278.         pop     ecx
  279.         mov     edx, 135 shl 16 + 35 + 18
  280.         mov     esi, 0x40000000
  281.         mov     edi, 0x00F3F3F3
  282.         mcall   47
  283.  
  284.         sub     edx, 18
  285.         pop     ecx
  286.         mcall
  287.  
  288.         jmp     mainloop
  289.  
  290.  
  291. not_102:
  292.  
  293.         cmp     [mode], 103
  294.         jne     not_103
  295.  
  296.         mov     ebx, API_ARP
  297.         mov     bh, [device]
  298.         push    ebx
  299.         mcall   76      ; tx
  300.         pop     ebx
  301.         push    eax
  302.  
  303.         inc     bl
  304.         push    ebx
  305.         mcall   76      ; rx
  306.         pop     ebx
  307.         push    eax
  308.  
  309.         inc     bl
  310.         push    ebx
  311.         mcall   76      ; entries
  312.         pop     ebx
  313.         push    eax
  314.  
  315.         mov     bl, 7
  316.         push    ebx
  317.         mcall   76
  318.         pop     ebx
  319.         push    eax
  320.  
  321.         mov     ebx, 0x000a0000
  322.         pop     ecx
  323.         mov     edx, 135 shl 16 + 35 + 3*18
  324.         mov     esi, 0x40000000
  325.         mov     edi, 0x00F3F3F3
  326.         mcall   47
  327.  
  328.         sub     edx, 18
  329.         pop     ecx
  330.         mcall
  331.  
  332.         sub     edx, 18
  333.         pop     ecx
  334.         mcall
  335.  
  336.         sub     edx, 18
  337.         pop     ecx
  338.         mcall
  339.  
  340. ;        mov     edx, 50 shl 16 + 150
  341.         mov     [last], 0
  342.  
  343.   .arp_loop:
  344.         mov     ebx, API_ARP + 3                ; read ARP entry
  345.         mov     bh, [device]
  346.         mcall   76, ,[last], , , arp_buf
  347.         cmp     eax, -1
  348.         je      mainloop
  349.  
  350.         mov     ebx, [last]
  351.         imul    ebx, 16
  352.         add     ebx, 8 shl 16 + 140
  353.         mcall   4, , 0x80000000, str_ARP_entry
  354.         mov     edx, ebx
  355.  
  356.         mov     eax, 47
  357.         mov     ebx, 0x00030000
  358.         mov     esi, 0x40000000
  359.         mov     edi, 0x00F3F3F3
  360.         xor     ecx, ecx
  361.  
  362.         mov     cl, byte[arp_buf.IP+0]
  363.         mcall
  364.  
  365.         mov     cl, byte[arp_buf.IP+1]
  366.         add     edx, 24 shl 16
  367.         mcall
  368.  
  369.         mov     cl, byte[arp_buf.IP+2]
  370.         add     edx, 24 shl 16
  371.         mcall
  372.  
  373.         mov     cl, byte[arp_buf.IP+3]
  374.         add     edx, 24 shl 16
  375.         mcall
  376.  
  377.  
  378.         mov     ebx, 0x00020100
  379.         mov     cl, byte[arp_buf.MAC+0]
  380.         add     edx, 36 shl 16
  381.         mcall
  382.  
  383.         mov     cl, byte[arp_buf.MAC+1]
  384.         add     edx, 18 shl 16
  385.         mcall
  386.  
  387.         mov     cl, byte[arp_buf.MAC+2]
  388.         add     edx, 18 shl 16
  389.         mcall
  390.  
  391.         mov     cl, byte[arp_buf.MAC+3]
  392.         add     edx, 18 shl 16
  393.         mcall
  394.  
  395.         mov     cl, byte[arp_buf.MAC+4]
  396.         add     edx, 18 shl 16
  397.         mcall
  398.  
  399.         mov     cl, byte[arp_buf.MAC+5]
  400.         add     edx, 18 shl 16
  401.         mcall
  402.  
  403.         mov     ebx, 0x00040000
  404.         mov     cx, [arp_buf.status]
  405.         add     edx, 30 shl 16
  406.         mcall
  407.  
  408.         mov     cx, [arp_buf.TTL]
  409.         add     edx, 60 shl 16
  410.         mcall
  411.  
  412.         add     dx, 18
  413.         rol     edx, 16
  414.         mov     dx, 8
  415.         rol     edx, 16
  416.         inc     [last]
  417.  
  418.         jmp     .arp_loop
  419.  
  420. not_103:
  421.  
  422.         cmp     [mode], 104
  423.         jne     not_104
  424.  
  425.         mov     ebx, API_ICMP
  426.         mov     bh, [device]
  427.         push    ebx
  428.         mcall   76
  429.         pop     ebx
  430.         push    eax
  431.  
  432.         inc     bl
  433.         push    ebx
  434.         mcall   76
  435.         pop     ebx
  436.         push    eax
  437.  
  438.         mov     ebx, 0x000a0000
  439.         pop     ecx
  440.         mov     edx, 135 shl 16 + 35 + 18
  441.         mov     esi, 0x40000000
  442.         mov     edi, 0x00F3F3F3
  443.         mcall   47
  444.  
  445.         sub     edx, 18
  446.         pop     ecx
  447.         mcall
  448.  
  449.         jmp     mainloop
  450.  
  451. not_104:
  452.  
  453.         cmp     [mode], 105
  454.         jne     not_105
  455.  
  456.         mov     ebx, API_UDP
  457.         mov     bh, [device]
  458.         push    ebx
  459.         mcall   76
  460.         pop     ebx
  461.         push    eax
  462.  
  463.         inc     bl
  464.         push    ebx
  465.         mcall   76
  466.         pop     ebx
  467.         push    eax
  468.  
  469.         mov     ebx, 0x000a0000
  470.         pop     ecx
  471.         mov     edx, 135 shl 16 + 35 + 18
  472.         mov     esi, 0x40000000
  473.         mov     edi, 0x00F3F3F3
  474.         mcall   47
  475.  
  476.         sub     edx, 18
  477.         pop     ecx
  478.         mcall
  479.  
  480.         jmp     mainloop
  481.  
  482. not_105:
  483.  
  484.         cmp     [mode], 106
  485.         jne     not_106
  486.  
  487.         mov     ebx, API_TCP
  488.         mov     bh, [device]
  489.         push    ebx
  490.         mcall   76
  491.         pop     ebx
  492.         push    eax
  493.  
  494.         inc     bl
  495.         push    ebx
  496.         mcall   76
  497.         pop     ebx
  498.         push    eax
  499.  
  500.         inc     bl
  501.         push    ebx
  502.         mcall   76
  503.         pop     ebx
  504.         push    eax
  505.  
  506.         inc     bl
  507.         push    ebx
  508.         mcall   76
  509.         pop     ebx
  510.         push    eax
  511.  
  512.         mov     ebx, 0x000a0000
  513.         pop     ecx
  514.         mov     edx, 135 shl 16 + 35 + 18*3
  515.         mov     esi, 0x40000000
  516.         mov     edi, 0x00F3F3F3
  517.         mcall   47
  518.  
  519.         sub     edx, 18
  520.         pop     ecx
  521.         mcall
  522.  
  523.         sub     edx, 18
  524.         pop     ecx
  525.         mcall
  526.  
  527.         sub     edx, 18
  528.         pop     ecx
  529.         mcall
  530.  
  531.         jmp     mainloop
  532.  
  533. not_106:
  534.  
  535. mainloop:
  536.  
  537.         mcall   23, 50          ; wait for event with timeout    (0,5 s)
  538.  
  539.         cmp     eax, 1
  540.         je      window_redraw
  541.         cmp     eax, 3
  542.         je      button
  543.         cmp     eax, 11
  544.         je      redraw
  545.  
  546.         jmp     draw_stats
  547.  
  548. button:                         ; button
  549.         mcall   17              ; get id
  550.         cmp     ah, 1
  551.         je      exit
  552.         cmp     ah, 0
  553.         je      .interface
  554.         mov     [mode], ah
  555.         jmp     redraw
  556.  
  557.   .interface:
  558.         shr     eax, 16
  559.         mov     [device], al
  560.         jmp     redraw
  561.  
  562. exit:
  563.         mcall   -1
  564.  
  565.  
  566.  
  567. draw_mac:
  568.  
  569.         mov     eax, 47
  570.         mov     ebx, 0x00020100
  571.         mov     esi, 0x40000000
  572.         mov     edi, 0x00F3F3F3
  573.  
  574.         mov     cl, [esp+4]
  575.         mcall
  576.  
  577.         mov     cl, [esp+4+1]
  578.         add     edx, 15 shl 16
  579.         mcall
  580.  
  581.         mov     cl, [esp+4+2]
  582.         add     edx, 15 shl 16
  583.         mcall
  584.  
  585.         mov     cl, [esp+4+3]
  586.         add     edx, 15 shl 16
  587.         mcall
  588.  
  589.         mov     cl, [esp+4+4]
  590.         add     edx, 15 shl 16
  591.         mcall
  592.  
  593.         mov     cl, [esp+4+5]
  594.         add     edx, 15 shl 16
  595.         mcall
  596.  
  597.         sub     edx, 5*15 shl 16
  598.  
  599.         ret     6
  600.  
  601.  
  602. draw_ip:
  603.  
  604.         mov     eax, 47
  605.         mov     ebx, 0x00030000
  606.         mov     esi, 0x40000000
  607.         mov     edi, 0x00F3F3F3
  608.  
  609.         xor     ecx, ecx
  610.  
  611.         mov     cl, [esp+4]
  612.         mcall
  613.  
  614.         mov     cl, [esp+4+1]
  615.         add     edx, 30 shl 16
  616.         mcall
  617.  
  618.         mov     cl, [esp+4+2]
  619.         add     edx, 30 shl 16
  620.         mcall
  621.  
  622.         mov     cl, [esp+4+3]
  623.         add     edx, 30 shl 16
  624.         mcall
  625.  
  626.         sub     edx, 3*30 shl 16
  627.         ret     4
  628.  
  629.  
  630. draw_interfaces:
  631.  
  632.         mov     [.btnpos], 5 shl 16 + 20
  633.         mov     [.txtpos], 455 shl 16 + 12
  634.  
  635.         mcall   74, -1          ; get number of active network devices
  636.         mov     ecx, eax
  637.  
  638.         xor     ebx, ebx        ; get device type
  639.   .loop:
  640.         mcall   74
  641.         cmp     eax, 1          ; loopback or ethernet?
  642.         jbe     .hit
  643.         inc     bh
  644.         jb      .loop           ; tried all 256?
  645.         ret
  646.  
  647.  
  648.   .hit:
  649.         push    ecx ebx
  650.         movzx   edx, bh
  651.         shl     edx, 8
  652.         mov     esi, 0x00BBBbbb
  653.         cmp     bh, [device]
  654.         cmove   esi, 0x0081BBFF
  655.         mcall   8, 450 shl 16 + 135, [.btnpos]
  656.         mov     ebx, [esp]
  657.         inc     bl
  658.         mov     ecx, namebuf
  659.         mov     edx, namebuf
  660.         mcall   74                              ; get device name
  661.         cmp     eax, -1
  662.         jne     @f
  663.         mov     edx, str_unknown
  664.        @@:
  665.         mcall   4, [.txtpos], 0x80000000        ; print the name
  666.         pop     ebx ecx
  667.  
  668.         inc     bh
  669.  
  670.         add     [.btnpos], 25 shl 16
  671.         add     [.txtpos], 25
  672.  
  673.         dec     ecx
  674.         jnz     .loop
  675.  
  676.         ret
  677.  
  678.   .btnpos       dd ?
  679.   .txtpos       dd ?
  680.  
  681.  
  682. ; DATA AREA
  683.  
  684. name            db 'Netstat', 0
  685. mode            db 101
  686. device          db 0
  687. device_type     dd 0
  688. last            dd 0
  689. modes           db 'Physical    IPv4       ARP      ICMP      UDP       TCP', 0
  690.  
  691. str_packets_tx  db 'Packets sent:', 0
  692. str_packets_rx  db 'Packets received:', 0
  693. str_bytes_tx    db 'Bytes sent:', 0
  694. str_bytes_rx    db 'Bytes received:', 0
  695. str_MAC         db 'MAC address:', 0
  696. str_ip          db 'IP address:', 0
  697. str_dns         db 'DNS address:', 0
  698. str_subnet      db 'Subnet mask:', 0
  699. str_gateway     db 'Standard gateway:', 0
  700. str_arp         db 'ARP entrys:', 0
  701. str_conflicts   db 'ARP conflicts:', 0
  702. str_unknown     db 'unknown', 0
  703. str_missed      db 'Packets missed:',0
  704. str_dumped      db 'Packets dumped:',0
  705. str_link        db 'Link state:',0
  706.  
  707. str_ARP_legend  db 'IP-address        MAC-address         Status    TTL', 0
  708. str_ARP_entry   db '   .   .   .        -  -  -  -  -                    s', 0
  709.  
  710. namebuf         rb 64
  711. arp_buf         ARP_entry
  712.  
  713. I_END:
  714.  
  715.  
  716.