netstat now works with all network interfaces instead of default device 0.

git-svn-id: svn://kolibrios.org@2864 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-07-13 12:35:23 +00:00
parent ce6a93da60
commit 042f832f0c

View File

@ -1,209 +1,195 @@
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Netstat for KolibriOS v0.2 ;; ;;
; ;; Copyright (C) KolibriOS team 2010-2012. All rights reserved. ;;
; 0.1 - 22 sept 2009 - initial release ;; Distributed under terms of the GNU General Public License ;;
; 0.2 - 9 july 2012 - converted to new sysfunc numbers ;; ;;
; ;; netstat.asm - Network Status Tool for KolibriOS ;;
; hidnplayr@gmail.com ;; ;;
; ;; Written by hidnplayr@kolibrios.org ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
;; ;;
;; ;;
;; 0.1 - 22 sept 2009 - initial release ;;
;; 0.2 - 9 july 2012 - converted to new sysfunc numbers ;;
;; 0.3 - 13 july 2012 - work with multiple network interfaces ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
format binary as "" format binary as ""
use32 use32
org 0x0 org 0x0
db 'MENUET01' ; 8 byte id db 'MENUET01' ; 8 byte id
dd 0x01 ; header version dd 0x01 ; header version
dd START ; start of code dd START ; start of code
dd I_END ; size of image dd I_END ; size of image
dd (I_END+0x100) ; memory for app dd (I_END+0x100) ; memory for app
dd (I_END+0x100) ; esp dd (I_END+0x100) ; esp
dd I_PARAM , 0x0 ; I_Param , I_Icon dd I_PARAM , 0x0 ; I_Param , I_Icon
__DEBUG__ equ 1
__DEBUG_LEVEL__ equ 1
include '..\macros.inc' include '..\macros.inc'
include '..\debug-fdo.inc'
include '..\network.inc' include '..\network.inc'
START: ; start of execution START:
; TODO: check Parameters mcall 40, 101b
DEBUGF 1, 'Netstat application loaded!\n' redraw:
mcall 12, 1
mcall 0, 100 shl 16 + 600, 100 shl 16 + 240, 0x34bcbcbc , , name ; draw window
redraw: call draw_interfaces
mcall 12, 1
mcall 0, 100 shl 16 + 520, 100 shl 16 + 240, 0x34bcbcbc , , name mov edx, 101
mov esi, 0x00aaaaff
mov edi, 0x00aaffff
mov edx, 101 cmp dl, [mode]
mov esi, 0x00aaaaff cmove esi, edi
mov edi, 0x00aaffff mcall 8, 25 shl 16 + 65, 25 shl 16 + 20
cmp dl, [mode]
cmove esi, edi
mcall 8, 25 shl 16 + 65, 25 shl 16 + 20
.morebuttons: .morebuttons:
inc edx inc edx
add ebx, 75 shl 16 add ebx, 75 shl 16
mov esi, 0x00aaaaff mov esi, 0x00aaaaff
cmp dl, [mode] cmp dl, [mode]
cmove esi, edi cmove esi, edi
mcall mcall
cmp edx, 105 cmp edx, 105
jle .morebuttons jle .morebuttons
mcall 4, 28 shl 16 + 31, 0x80000000, modes mcall 4, 28 shl 16 + 31, 0x80000000, modes
cmp [mode], 101 cmp [mode], 101
jne .no_eth jne .no_eth
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx
add ebx, 18 add ebx, 18
mov edx, str_packets_rx mov edx, str_packets_rx
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_bytes_tx mov edx, str_bytes_tx
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_bytes_rx mov edx, str_bytes_rx
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_MAC mov edx, str_MAC
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_queue_in mov edx, str_queue_in
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_queue_out mov edx, str_queue_out
mcall mcall
mov ebx, API_ETH + 4 mov ebx, API_ETH + 4
mov bh, [device] mov bh, [device]
mcall 76 mcall 76
push eax push eax
push bx push bx
mov edx, 135 shl 16 + 75 + 4*18 mov edx, 135 shl 16 + 75 + 4*18
call draw_mac call draw_mac
jmp end_of_draw jmp end_of_draw
.no_eth: .no_eth:
cmp [mode], 102 cmp [mode], 102
jne .no_ip jne .no_ip
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx
add ebx, 18 add ebx, 18
mov edx, str_packets_rx mov edx, str_packets_rx
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_ip mov edx, str_ip
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_dns mov edx, str_dns
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_subnet mov edx, str_subnet
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_gateway mov edx, str_gateway
mcall mcall
mov ebx, API_IPv4 + 8 mov ebx, API_IPv4 + 8
mov bh, [device] mov bh, [device]
mcall 76 mcall 76
push eax push eax
dec bl dec bl
dec bl dec bl
mcall 76 mcall 76
push eax push eax
dec bl dec bl
dec bl dec bl
mcall 76 mcall 76
push eax push eax
dec bl dec bl
dec bl dec bl
mcall 76 mcall 76
push eax push eax
mov edx, 135 shl 16 + 75 + 2*18 mov edx, 135 shl 16 + 75 + 2*18
call draw_ip call draw_ip
add edx, 18 add edx, 18
call draw_ip call draw_ip
add edx, 18 add edx, 18
call draw_ip call draw_ip
add edx, 18 add edx, 18
call draw_ip call draw_ip
jmp end_of_draw jmp end_of_draw
.no_ip: .no_ip:
cmp [mode], 103 cmp [mode], 103
jne .no_arp jne .no_arp
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx
add ebx, 18 add ebx, 18
mov edx, str_packets_rx mov edx, str_packets_rx
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_arp mov edx, str_arp
mcall mcall
jmp end_of_draw jmp end_of_draw
.no_arp: .no_arp:
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx
add ebx, 18 add ebx, 18
mov edx, str_packets_rx mov edx, str_packets_rx
mcall mcall
end_of_draw:
mcall 12, 2
jmp draw_stats
mainloop:
mcall 23,500 ; wait for event with timeout (0,5 s)
cmp eax, 1
je redraw
cmp eax, 2
je key
cmp eax, 3
je button
end_of_draw:
mcall 12, 2
;------------------------------- draw_stats:
;
;------------------------------
draw_stats:
cmp [mode], 101 cmp [mode], 101
jne not_101 jne not_101
mov ebx, API_ETH mov ebx, API_ETH
mov bh, [device] mov bh, [device]
@@: @@:
push ebx push ebx
mcall 76 mcall 76
pop ebx pop ebx
@ -215,7 +201,7 @@ START: ; start of execution
inc bl ;5 inc bl ;5
inc bl ;6 inc bl ;6
@@: @@:
push ebx push ebx
mcall 76 mcall 76
pop ebx pop ebx
@ -416,22 +402,33 @@ not_105:
not_106: not_106:
jmp mainloop mainloop:
key: mcall 23, 50 ; wait for event with timeout (0,5 s)
mcall 2
jmp mainloop
cmp eax, 1
je redraw
cmp eax, 3
je button
button: ; button jmp draw_stats
mcall 17 ; get id
cmp ah, 1
je exit
mov [mode], ah
jmp redraw
exit: button: ; button
mcall -1 mcall 17 ; get id
cmp ah, 1
je exit
cmp ah, 0
je .interface
mov [mode], ah
jmp redraw
.interface:
shr eax, 16
mov [device], al
jmp redraw
exit:
mcall -1
@ -498,27 +495,82 @@ draw_ip:
ret 4 ret 4
draw_interfaces:
mov [.btnpos], 8 shl 16 + 20
mov [.txtpos], 490 shl 16 + 15
mcall 74, -1 ; get number of active network devices
mov ecx, eax
xor ebx, ebx ; get device type
.loop:
mcall 74
cmp eax, 1 ; ethernet?
je .hit
inc bh
jb .loop ; tried all 256?
ret
.hit:
push ecx ebx
movzx edx, bh
shl edx, 8
mov esi, 0x00aaaaff
cmp bh, [device]
cmove esi, 0x00aaffff
mcall 8, 485 shl 16 + 100, [.btnpos]
mov ebx, [esp]
inc bl
mov ecx, namebuf
mov edx, namebuf
mcall 74 ; get device name
cmp eax, -1
jne @f
mov edx, str_unknown
@@:
mcall 4, [.txtpos], 0x80000000 ; print the name
pop ebx ecx
inc bh
add [.btnpos], 25 shl 16
add [.txtpos], 25
dec ecx
jnz .loop
ret
.btnpos dd ?
.txtpos dd ?
; DATA AREA ; DATA AREA
name db 'Netstat', 0 name db 'Netstat', 0
mode db 101 mode db 101
device db 0 device db 0
modes db 'Ethernet IPv4 ARP ICMP UDP TCP', 0 modes db 'Ethernet IPv4 ARP ICMP UDP TCP', 0
str_packets_tx db 'Packets sent:', 0 str_packets_tx db 'Packets sent:', 0
str_packets_rx db 'Packets received:', 0 str_packets_rx db 'Packets received:', 0
str_bytes_tx db 'Bytes sent:', 0 str_bytes_tx db 'Bytes sent:', 0
str_bytes_rx db 'Bytes received:', 0 str_bytes_rx db 'Bytes received:', 0
str_MAC db 'MAC address:', 0 str_MAC db 'MAC address:', 0
str_queue_in db 'IN-queue size:', 0 str_queue_in db 'IN-queue size:', 0
str_queue_out db 'OUT-queue size:', 0 str_queue_out db 'OUT-queue size:', 0
str_ip db 'IP address:', 0 str_ip db 'IP address:', 0
str_dns db 'DNS address:', 0 str_dns db 'DNS address:', 0
str_subnet db 'Subnet mask:', 0 str_subnet db 'Subnet mask:', 0
str_gateway db 'Standard gateway:', 0 str_gateway db 'Standard gateway:', 0
str_arp db 'ARP entrys:', 0 str_arp db 'ARP entrys:', 0
str_unknown db 'unknown', 0
include_debug_strings ; ALWAYS present in data section namebuf rb 64
I_PARAM rb 1024 I_PARAM rb 1024