ping: accept -t parameter

git-svn-id: svn://kolibrios.org@5249 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2014-12-19 22:46:30 +00:00
parent 30ef1a01d0
commit b8aec230ec

View File

@ -58,7 +58,7 @@ start:
call [con_init] call [con_init]
; main loop ; main loop
cmp byte[s], 0 cmp byte[s], 0
jne resolve jne parse_param
push str_welcome push str_welcome
call [con_write_asciiz] call [con_write_asciiz]
@ -90,7 +90,44 @@ main:
mov [stats.rx], 0 mov [stats.rx], 0
mov [stats.time], 0 mov [stats.time], 0
resolve: parse_param:
mov [count], 4 ; default number of pings to send
; Check if any additional parameters were given
mov esi, s
mov ecx, 1024
.addrloop:
lodsb
test al, al
jz .resolve
cmp al, ' '
jne .addrloop
mov byte[esi-1], 0
jmp .param
.param_loop:
lodsb
test al, al
jz .resolve
cmp al, ' '
jne .invalid
.param:
lodsb
cmp al, '-'
jne .invalid
lodsb
cmp al, 't'
jne @f
mov [count], -1 ; infinite
jmp .param_loop
@@:
; implement more parameters here
.invalid:
push str13
call [con_write_asciiz]
jmp main
.resolve:
; resolve name ; resolve name
push esp ; reserve stack place push esp ; reserve stack place
push esp ; fourth parameter push esp ; fourth parameter
@ -131,8 +168,6 @@ resolve:
mcall 40, 1 shl 7 ; + 7 mcall 40, 1 shl 7 ; + 7
; call [con_cls] ; call [con_cls]
mov [count], 4
push str3 push str3
call [con_write_asciiz] call [con_write_asciiz]
@ -144,6 +179,10 @@ resolve:
call [con_printf] call [con_printf]
mainloop: mainloop:
call [con_get_flags]
test eax, 0x200 ; con window closed?
jnz exit_now
inc [stats.tx] inc [stats.tx]
mcall 26, 9 mcall 26, 9
mov [time_reference], eax mov [time_reference], eax
@ -217,9 +256,11 @@ mainloop:
.continue: .continue:
inc [icmp_packet.seq] inc [icmp_packet.seq]
cmp [count], -1
je .forever
dec [count] dec [count]
jz done jz done
.forever:
mcall 5, 100 ; wait a second mcall 5, 100 ; wait a second
jmp mainloop jmp mainloop
@ -258,7 +299,7 @@ fail2:
exit: exit:
push 1 push 1
call [con_exit] call [con_exit]
exit_now:
mcall -1 mcall -1
@ -273,6 +314,7 @@ str3b db ' with %u data bytes',10,0
str4 db 10,0 str4 db 10,0
str5 db 'Name resolution failed.',10,0 str5 db 'Name resolution failed.',10,0
str6 db 'Could not open socket',10,0 str6 db 'Could not open socket',10,0
str13 db 'Invalid parameter(s)',10,0
str11 db 'Answer: ',0 str11 db 'Answer: ',0
str7 db 'bytes=%u seq=%u time=%u ms',10,0 str7 db 'bytes=%u seq=%u time=%u ms',10,0
@ -317,7 +359,8 @@ import console, \
con_gets, 'con_gets',\ con_gets, 'con_gets',\
con_cls, 'con_cls',\ con_cls, 'con_cls',\
con_getch2, 'con_getch2',\ con_getch2, 'con_getch2',\
con_set_cursor_pos, 'con_set_cursor_pos' con_set_cursor_pos, 'con_set_cursor_pos',\
con_get_flags, 'con_get_flags'
socketnum dd ? socketnum dd ?