Subversion Repositories Kolibri OS

Rev

Rev 4742 | Rev 4798 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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