Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5585 → Rev 5586

/programs/network/netstat/ipcfg.inc
0,0 → 1,397
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; Written by hidnplayr@kolibrios.org ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
enum_callback:
 
ipcfg:
 
mcall 40, EVM_MOUSE + EVM_MOUSE_FILTER + EVM_REDRAW + EVM_BUTTON + EVM_KEY + EVM_STACK
 
; Create the 'ip..' string with correct device number
call create_str_ini_int
 
; Try to read settings from .ini file
invoke ini.get_str, net_ini, str_ini_int, str_ini_ip_type, ini_buf, 16, sz_0
test eax, eax
jz @f
; If settings not found, use default settings from 'ip?' section
mov dword[str_ini_int], 'ip?'
@@:
 
; Read ip/subnet/gateway type
mov [option_ip], op_ip_static
invoke ini.get_str, net_ini, str_ini_int, str_ini_ip_type, ini_buf, 16, sz_0
; test eax, eax
; jz .disabled
cmp dword[ini_buf], 'dhcp'
jne @f
mov [option_ip], op_ip_auto
@@:
 
; Read DNS type
mov [option_dns], op_dns_static
invoke ini.get_str, net_ini, str_ini_int, str_ini_dns_type, ini_buf, 16, sz_0
cmp dword[ini_buf], 'dhcp'
jne @f
mov [option_dns], op_dns_auto
@@:
 
; Read all IP addresses
mov [str_edit_ip], 0
mov [str_edit_subnet], 0
mov [str_edit_gateway], 0
mov [str_edit_dns], 0
 
invoke ini.get_str, net_ini, str_ini_int, str_ini_ip, str_edit_ip, 16, sz_0
invoke ini.get_str, net_ini, str_ini_int, str_ini_subnet, str_edit_subnet, 16, sz_0
invoke ini.get_str, net_ini, str_ini_int, str_ini_gateway, str_edit_gateway, 16, sz_0
invoke ini.get_str, net_ini, str_ini_int, str_ini_dns, str_edit_dns, 16, sz_0
 
invoke edit_set_text, edit_ip, str_edit_ip
invoke edit_set_text, edit_subnet, str_edit_subnet
invoke edit_set_text, edit_gateway, str_edit_gateway
invoke edit_set_text, edit_dns, str_edit_dns
 
.parse_settings:
call toggle_editboxes
 
.draw:
; get system colors
mcall 48, 3, sc, 40
 
mcall 12, 1
 
mov edx, [sc.work]
or edx, 0x34000000
xor esi, esi
mov edi, str_title
mcall 0, 50 shl 16 + 200, 30 shl 16 + 200
 
mov ecx, 0x80000000
or ecx, [sc.work_text]
; mov ebx, 47 shl 16 + 10
; mov edx, str_mode
; mcall
mov ebx, 59 shl 16 + 35
mov edx, sz_ip
mcall 4
mov ebx, 5 shl 16 + 55
mov edx, sz_subnet
mcall
mov ebx, 29 shl 16 + 75
mov edx, sz_gateway
mcall
; mov ebx, 47 shl 16 + 80
; mov edx, str_mode
; mcall
mov ebx, 53 shl 16 + 120
mov edx, sz_dns
mcall
 
invoke edit_box_draw, edit_ip
invoke edit_box_draw, edit_subnet
invoke edit_box_draw, edit_gateway
invoke edit_box_draw, edit_dns
 
invoke option_box_draw, Option_boxs1
invoke option_box_draw, Option_boxs2
 
mcall 8, 80 shl 16 + 100, 150 shl 16 + 16, 2, [sc.work_button]
 
mov ecx, 0x80000000
or ecx, [sc.work_button_text]
mov ebx, 112 shl 16 + 155
mov edx, sz_apply
mcall 4
 
mcall 12, 2
 
.loop:
mcall 10
dec eax
jz .draw
dec eax
jz .key
dec eax
jz .btn
 
cmp [edit_ip.color], 0xcacaca
je @f
invoke edit_box_mouse, edit_ip
invoke edit_box_mouse, edit_subnet
invoke edit_box_mouse, edit_gateway
@@:
 
cmp [edit_dns.color], 0xcacaca
je @f
invoke edit_box_mouse, edit_dns
@@:
 
push [option_ip] [option_dns]
invoke option_box_mouse, Option_boxs1
invoke option_box_mouse, Option_boxs2
pop ebx eax
cmp eax, [option_ip]
jne @f
cmp ebx, [option_dns]
je .loop
@@:
call toggle_editboxes
jmp .draw
 
.btn:
mcall 17
 
test ah , ah
jz .loop
 
cmp ah, 2 ; apply
jne .exit
 
; Apply settings!
.apply:
xor edi, edi
 
cmp [edit_ip.color], 0xcacaca
je .skip_ip
mov [edit_ip.color], 0xffffff
mov esi, str_edit_ip
call validate_ip
test eax, eax
jz @f
mov [edit_ip.color], 0xff4444
inc edi
@@:
 
mov [edit_subnet.color], 0xffffff
mov esi, str_edit_subnet
call validate_ip
test eax, eax
jz @f
mov [edit_subnet.color], 0xff4444
inc edi
@@:
 
mov [edit_gateway.color], 0xffffff
mov esi, str_edit_gateway
call validate_ip
test eax, eax
jz @f
mov [edit_gateway.color], 0xff4444
inc edi
@@:
.skip_ip:
 
cmp [edit_dns.color], 0xcacaca
je .skip_dns
mov [edit_dns.color], 0xffffff
mov esi, str_edit_dns
call validate_ip
test eax, eax
jz @f
mov [edit_dns.color], 0xff4444
inc edi
@@:
.skip_dns:
 
test edi, edi
jnz .draw
 
; Settings look valid, save them to the ini file
; Re-create 'ip..' string, we dont want to save to 'ip?' section.
call create_str_ini_int
 
cmp [option_ip], op_ip_auto
jne .ip_static
invoke ini.set_str, net_ini, str_ini_int, str_ini_ip_type, sz_dhcp, 4
jmp @f
.ip_static:
invoke ini.set_str, net_ini, str_ini_int, str_ini_ip_type, sz_static2, 6
@@:
 
cmp [option_dns], op_dns_auto
invoke ini.set_str, net_ini, str_ini_int, str_ini_dns_type, sz_dhcp, 4
jmp @f
.dns_static:
invoke ini.set_str, net_ini, str_ini_int, str_ini_dns_type, sz_static2, 6
@@:
 
invoke ini.set_str, net_ini, str_ini_int, str_ini_ip, str_edit_ip, [edit_ip.size]
invoke ini.set_str, net_ini, str_ini_int, str_ini_subnet, str_edit_subnet, [edit_subnet.size]
invoke ini.set_str, net_ini, str_ini_int, str_ini_gateway, str_edit_gateway, [edit_gateway.size]
invoke ini.set_str, net_ini, str_ini_int, str_ini_dns, str_edit_dns, [edit_dns.size]
 
.exit:
mcall -1
 
.key:
mcall 2
 
; Stupid editbox doesnt allow us to disable edit boxes nor filter input decently, so we do it here.
cmp ah, 13
je .apply
cmp ah, 8
je @f
cmp ah, '.'
je @f
cmp ah, '0'
jb .loop
cmp ah, '9'
ja .loop
@@:
cmp [edit_ip.color], 0xffffff
jne @f
invoke edit_box_key, edit_ip
invoke edit_box_key, edit_subnet
invoke edit_box_key, edit_gateway
@@:
 
cmp [edit_dns.color], 0xffffff
jne @f
invoke edit_box_key, edit_dns
@@:
 
jmp .loop
 
toggle_editboxes:
 
mov [edit_ip.color], 0xffffff
mov [edit_subnet.color], 0xffffff
mov [edit_gateway.color], 0xffffff
cmp [option_ip], op_ip_static
je @f
mov [edit_ip.color], 0xcacaca
mov [edit_subnet.color], 0xcacaca
mov [edit_gateway.color], 0xcacaca
@@:
 
mov [edit_dns.color], 0xffffff
cmp [option_dns], op_dns_static
je @f
mov [edit_dns.color], 0xcacaca
@@:
 
ret
 
 
; in: esi = ptr to ascii ip
; out: eax = 0 - ok / -1 - error
validate_ip:
xor ecx, ecx ; octet count
.outer_loop:
xor ebx, ebx ; current number
inc ecx
.inner_loop:
lodsb ; load one character from ascii string
test al, al
je .finish
cmp al, '.'
je .outer_loop
; Convert current digit from ascii to bin, if valid
sub al, '0'
jb .invalid
cmp al, 9
ja .invalid
; multiply current number by 10
add bl, bl
jc .invalid
lea ebx, [ebx + 4 * ebx]
test ebx, 0xffffff00
jnz .invalid
; add current digit to current number
add bl, al
jc .invalid
jmp .inner_loop
.finish:
cmp cl, 4
jne .invalid
xor eax, eax
ret
 
.invalid:
or eax, -1
ret
 
create_str_ini_int:
movzx eax, [device]
mov ebx, 10
xor edx, edx
push 0
@@:
div ebx
add dl, '0'
push edx
test eax, eax
jnz @r
@@:
mov edi, str_ini_int+2
@@:
pop eax
stosb
test eax, eax
jnz @r
 
ret
 
 
;-------------------------
; DATA
 
edit_ip edit_box 100, 80, 30, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_ip, mouse_dd, 0, 0, 1
edit_subnet edit_box 100, 80, 50, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_subnet, mouse_dd, 0, 0, 1
edit_gateway edit_box 100, 80, 70, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_gateway, mouse_dd, 0, 0, 1
 
edit_dns edit_box 100, 80, 115, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_dns, mouse_dd, 0, 0, 1
 
op_ip_auto option_box option_ip, 15, 10, 6, 12, 0xffffff, 0, 0, sz_auto, 5
op_ip_static option_box option_ip, 80, 10, 6, 12, 0xffffff, 0, 0, sz_static, 7
 
op_dns_auto option_box option_dns, 15, 95, 6, 12, 0xffffff, 0, 0, sz_auto, 5
op_dns_static option_box option_dns, 80, 95, 6, 12, 0xffffff, 0, 0, sz_static, 7
 
option_ip dd op_ip_auto
option_dns dd op_dns_auto
Option_boxs1 dd op_ip_auto, op_ip_static, 0
Option_boxs2 dd op_dns_auto, op_dns_static, 0
 
net_ini db '/sys/settings/network.ini', 0
 
str_ini_int db 'ip1', 0
rb 10
str_ini_ip db 'ip', 0
str_ini_subnet db 'subnet', 0
str_ini_gateway db 'gateway', 0
str_ini_dns db 'dns1', 0
str_ini_ip_type db 'ip_type', 0
str_ini_dns_type db 'dns_type', 0
 
sz_0 db 0
sz_dhcp db 'dhcp', 0
sz_static2 db 'static', 0
 
str_title db 'IP settings', 0
sz_ip db 'IP:', 0
sz_subnet db 'Subnet mask:', 0
sz_gateway db 'Gateway:', 0
sz_dns db 'DNS:', 0
sz_auto db 'Auto', 0
sz_static db 'Static', 0
sz_apply db 'Apply', 0
 
str_edit_ip rb 16
str_edit_subnet rb 16
str_edit_gateway rb 16
str_edit_dns rb 16
 
ini_buf rb 16
 
mouse_dd dd ?
/programs/network/netstat/netstat.asm
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2010-2014. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; netstat.asm - Network Status Tool for KolibriOS ;;
29,13 → 29,30
dd (I_END+0x1000) ; esp
dd 0, 0 ; I_Param, I_Path
 
include '../../proc32.inc'
include '../../macros.inc'
include '../../dll.inc'
include '../../develop/libraries/box_lib/trunk/box_lib.mac'
 
include '../../network.inc'
 
include 'ipcfg.inc'
 
START:
 
mcall 68, 11
 
stdcall dll.Load, @IMPORT
or eax, eax
jnz exit
 
mcall 40, EVM_REDRAW + EVM_BUTTON + EVM_STACK2 + EVM_KEY
 
window_redraw:
 
; get system colors
mcall 48, 3, sc, 40
 
; Notify kernel of start of window draw
mcall 12, 1
 
134,6 → 151,12
mov edx, str_bytes_rx
mcall
add ebx, 18
mov edx, str_speed_tx
mcall
add ebx, 18
mov edx, str_speed_rx
mcall
add ebx, 18
mov edx, str_link
mcall
 
150,7 → 173,7
push eax
push bx
 
mov edx, 134 shl 16 + 35 + 5*18
mov edx, 134 shl 16 + 35 + 7*18
call draw_mac
jmp end_of_draw
 
209,6 → 232,12
add edx, 18
call draw_ip
 
cmp [device], 0
je end_of_draw
 
mcall 8, 128 shl 16 + 100, 150 shl 16 + 20, 2, [sc.work_button]
mcall 4, 150 shl 16 + 157, [sc.work_button_text], str_ip_cfg, str_ip_cfg.len
 
jmp end_of_draw
 
.no_ip:
275,38 → 304,65
cmp bl, 10
jbe @r
 
pop eax
test al, al
pop ecx
 
push [time]
pop [delta_time]
mcall 26, 9
mov [time], eax
sub eax, [delta_time]
jnz @f
inc eax ; Zero time units? Lets make it at least one.
@@:
mov [delta_time], eax
 
mov eax, [esp+4] ; bytes received
push eax
sub eax, [prev_rx]
pop [prev_rx]
xor edx, edx
div [delta_time]
push eax
 
mov eax, [esp+4] ; bytes sent
push eax
sub eax, [prev_tx]
pop [prev_tx]
xor edx, edx
div [delta_time]
push eax
 
test cl, cl
jnz @f
mov edx, str_down
jmp .print_link
@@:
cmp al, 100b
cmp cl, 100b
jnz @f
mov edx, str_10m
jmp .print_link
@@:
cmp al, 110b
cmp cl, 110b
jnz @f
mov edx, str_10mfd
jmp .print_link
@@:
cmp al, 1000b
cmp cl, 1000b
jnz @f
mov edx, str_100m
jmp .print_link
@@:
cmp al, 1010b
cmp cl, 1010b
jnz @f
mov edx, str_100mfd
jmp .print_link
@@:
cmp al, 1100b
cmp cl, 1100b
jnz @f
mov edx, str_1g
jmp .print_link
@@:
cmp al, 1110b
cmp cl, 1110b
jnz @f
mov edx, str_1gfd
jmp .print_link
314,29 → 370,43
mov edx, str_unknown
 
.print_link:
mov ebx, 134 shl 16 + 35 + 4*18
mov ebx, 134 shl 16 + 35 + 6*18
mov ecx, 0xc0000000
mov edi, 0x00f3f3f3
mcall 4
 
; speed tx
mov ebx, 0x000a0000
pop ecx
mov edx, 134 shl 16 + 35 + 3*18
mov edx, 134 shl 16 + 35 + 5*18
mov esi, 0x40000000
mcall 47
 
; speed rx
sub edx, 18
pop ecx
mcall
 
; bytes received
sub edx, 18
pop ecx
mcall
 
; bytes sent
sub edx, 18
pop ecx
mcall
 
; packets received
sub edx, 18
pop ecx
mcall
 
; packets sent
sub edx, 18
pop ecx
mcall
 
jmp mainloop
 
 
646,6 → 716,8
mcall 17 ; get id
cmp ah, 1
je exit
cmp ah, 2
je .ipcfg
cmp ah, 0
je .interface
shr ax, 8
652,6 → 724,10
mov [mode], ax
jmp redraw
 
.ipcfg:
mcall 51, 1, ipcfg, I_END+0x1000
jmp mainloop
 
.interface:
shr eax, 16
mov [device], al
818,6 → 894,31
 
; DATA AREA
 
align 16
@IMPORT:
 
library box_lib , 'box_lib.obj', \
libini , 'libini.obj'
 
import libini, \
ini.get_str , 'ini_get_str' ,\
ini.set_str , 'ini_set_str' ,\
ini.enum_sections, 'ini_enum_sections'
 
import box_lib ,\
edit_box_draw , 'edit_box' ,\
edit_box_key , 'edit_box_key' ,\
edit_box_mouse , 'edit_box_mouse' ,\
edit_set_text , 'edit_box_set_text' ,\
version_ed , 'version_ed' ,\
init_checkbox , 'init_checkbox2' ,\
check_box_draw , 'check_box_draw2' ,\
check_box_mouse , 'check_box_mouse2' ,\
version_ch , 'version_ch2' ,\
option_box_draw , 'option_box_draw' ,\
option_box_mouse, 'option_box_mouse' ,\
version_op , 'version_op'
 
name db 'Network status', 0
mode dw 101 ; currently selected protocol
device db 1 ; currently selected device
841,6 → 942,10
str_dumped db 'Packets dumped:',0
str_queued db 'Packets queued:',0
str_link db 'Link state:',0
str_speed_tx db 'Upload (kb/s):', 0
str_speed_rx db 'Download (kb/s):', 0
str_ip_cfg db 'Configure'
.len = $ - str_ip_cfg
 
str_down db 'disconnected ', 0
str_unknown db 'unknown ', 0
854,7 → 959,14
str_ARP_legend db 'IP-address MAC-address Status TTL', 0
str_ARP_entry db ' . . . - - - - -', 0
 
prev_rx dd ?
prev_tx dd ?
time dd ?
delta_time dd ?
 
namebuf rb 64
arp_buf ARP_entry
 
sc system_colors
 
I_END: