Ctrl+C for ping, tracert.

git-svn-id: svn://kolibrios.org@9128 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2021-08-09 06:14:00 +00:00
parent c565761174
commit 3524e7c3b1
2 changed files with 70 additions and 121 deletions

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2010-2020. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2010-2021. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; ping.asm - ICMP echo client for KolibriOS ;; ;; ping.asm - ICMP echo client for KolibriOS ;;
@ -49,14 +49,8 @@ START:
test eax, eax test eax, eax
jnz exit jnz exit
; initialize console ; initialize console
push 1 invoke con_start, 1
call [con_start] invoke con_init, 80, 25, 80, 250, title
push title
push 250
push 80
push 25
push 80
call [con_init]
; Init identifier with our PID number ; Init identifier with our PID number
mcall 9, thread_info, -1 mcall 9, thread_info, -1
mov eax, [thread_info.PID] mov eax, [thread_info.PID]
@ -80,17 +74,13 @@ START:
cmp byte[params], 0 cmp byte[params], 0
jne parse_param jne parse_param
push str_welcome invoke con_write_asciiz, str_welcome
call [con_write_asciiz]
main: main:
; write prompt ; write prompt
push str_prompt invoke con_write_asciiz, str_prompt
call [con_write_asciiz]
; read string ; read string
mov esi, params mov esi, params
push 1024 invoke con_gets, esi, 1024
push esi
call [con_gets]
; check for exit ; check for exit
test eax, eax test eax, eax
jz exit jz exit
@ -183,18 +173,13 @@ parse_param:
@@: @@:
; implement more parameters here ; implement more parameters here
.invalid: .invalid:
push str13 invoke con_write_asciiz, str13
call [con_write_asciiz]
jmp main jmp main
.resolve: .resolve:
; resolve name ; resolve name
push esp ; reserve stack place push esp ; reserve stack place
push esp ; fourth parameter invoke getaddrinfo, params, 0, 0, esp
push 0 ; third parameter
push 0 ; second parameter
push params ; first parameter
call [getaddrinfo]
pop esi pop esi
; test for error ; test for error
test eax, eax test eax, eax
@ -204,19 +189,16 @@ parse_param:
mov eax, [esi+addrinfo.ai_addr] mov eax, [esi+addrinfo.ai_addr]
mov eax, [eax+sockaddr_in.sin_addr] mov eax, [eax+sockaddr_in.sin_addr]
mov [sockaddr1.ip], eax mov [sockaddr1.ip], eax
push eax invoke inet_ntoa, eax
call [inet_ntoa]
; write result ; write result
mov [ip_ptr], eax mov [ip_ptr], eax
push eax push eax
; free allocated memory ; free allocated memory
push esi invoke freeaddrinfo, esi
call [freeaddrinfo]
push str4 invoke con_write_asciiz, str4
call [con_write_asciiz]
mcall socket, AF_INET4, SOCK_RAW, IPPROTO_ICMP mcall socket, AF_INET4, SOCK_RAW, IPPROTO_ICMP
cmp eax, -1 cmp eax, -1
@ -238,19 +220,13 @@ parse_param:
mcall 40, EVM_STACK mcall 40, EVM_STACK
push str3 invoke con_write_asciiz, str3
call [con_write_asciiz] invoke con_write_asciiz, [ip_ptr]
invoke con_printf, str3b, [size]
push [ip_ptr]
call [con_write_asciiz]
push [size]
push str3b
call [con_printf]
add esp, 2*4 add esp, 2*4
mainloop: mainloop:
call [con_get_flags] invoke con_get_flags
test eax, 0x200 ; con window closed? test eax, 0x200 ; con window closed?
jnz exit_now jnz exit_now
@ -361,17 +337,14 @@ mainloop:
push eax push eax
push [recvd] push [recvd]
push str7 invoke con_printf, str7
call [con_printf]
add esp, 5*4 add esp, 5*4
jmp .continue jmp .continue
.ttl_exceeded: .ttl_exceeded:
push str14 invoke con_write_asciiz, str14
call [con_write_asciiz]
jmp .continue jmp .continue
@ -379,26 +352,31 @@ mainloop:
.miscomp: .miscomp:
sub edi, icmp_packet.data+1 sub edi, icmp_packet.data+1
push edi push edi
push str9 invoke con_printf, str9
call [con_printf]
add esp, 2*4 add esp, 2*4
jmp .continue jmp .continue
; Invalid reply ; Invalid reply
.invalid: .invalid:
push str10 invoke con_write_asciiz, str13
call [con_write_asciiz]
jmp .continue jmp .continue
; Timeout! ; Timeout!
.no_response: .no_response:
push str8 invoke con_write_asciiz, str8
call [con_write_asciiz]
; Send more ICMP packets ? ; Send more ICMP packets ?
.continue: .continue:
inc [icmp_packet.seq] inc [icmp_packet.seq]
invoke con_kbhit
test eax, eax
jz .nokey
invoke con_getch2
cmp ax, 0x1E03 ; Ctrl+C
je .stats
.nokey:
cmp [count], -1 cmp [count], -1
je .forever je .forever
dec [count] dec [count]
@ -427,27 +405,23 @@ mainloop:
push eax push eax
push [stats.rx] push [stats.rx]
push [stats.tx] push [stats.tx]
push str12 invoke con_printf, str12
call [con_printf]
add esp, 5*4 add esp, 5*4
jmp main jmp main
; DNS error ; DNS error
fail: fail:
push str5 invoke con_write_asciiz, str5
call [con_write_asciiz]
jmp main jmp main
; Socket error ; Socket error
fail2: fail2:
push str6 invoke con_write_asciiz, str6
call [con_write_asciiz]
jmp main jmp main
; Finally.. exit! ; Finally.. exit!
exit: exit:
push 1 invoke con_exit, 1
call [con_exit]
exit_now: exit_now:
mcall -1 mcall -1
@ -487,7 +461,7 @@ title db 'ICMP echo (ping) client',0
str_welcome db 'Please enter the hostname or IP-address of the host you want to ping,',10 str_welcome db 'Please enter the hostname or IP-address of the host you want to ping,',10
db 'or just press enter to exit.',10,10 db 'or just press enter to exit.',10,10
db 'Options:',10 db 'Options:',10
db ' -t Send packets till users abort.',10 db ' -t Send packets till users abort. (Ctrl+C))',10
db ' -n number Number of requests to send.',10 db ' -n number Number of requests to send.',10
db ' -i TTL Time to live.',10 db ' -i TTL Time to live.',10
db ' -l size Size of echo request.',10 db ' -l size Size of echo request.',10
@ -550,7 +524,8 @@ import console, \
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' con_get_flags, 'con_get_flags',\
con_kbhit, 'con_kbhit'
socketnum dd ? socketnum dd ?

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2010-2020. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2010-2021. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; tracert.asm - Trace network route for KolibriOS ;; ;; tracert.asm - Trace network route for KolibriOS ;;
@ -54,29 +54,19 @@ START:
test eax, eax test eax, eax
jnz exit jnz exit
; initialize console ; initialize console
push 1 invoke con_start, 1
call [con_start] invoke con_init, 80, 25, 80, 250, title
push title
push 250
push 80
push 25
push 80
call [con_init]
; main loop ; main loop
cmp byte[params], 0 cmp byte[params], 0
jne parse_param jne parse_param
push str_welcome invoke con_write_asciiz, str_welcome
call [con_write_asciiz]
main: main:
; write prompt ; write prompt
push str_prompt invoke con_write_asciiz, str_prompt
call [con_write_asciiz]
; read string ; read string
mov esi, params mov esi, params
push 1024 invoke con_gets, esi, 1024
push esi
call [con_gets]
; check for exit ; check for exit
test eax, eax test eax, eax
jz exit jz exit
@ -119,19 +109,14 @@ parse_param:
lodsb lodsb
; implement more parameters here ; implement more parameters here
.invalid: .invalid:
push str13 invoke con_write_asciiz, str13
call [con_write_asciiz]
jmp main jmp main
.resolve: .resolve:
DEBUGF 2, "resolve\n" DEBUGF 2, "resolve\n"
; resolve name ; resolve name
push esp ; reserve stack place push esp ; reserve stack place
push esp ; fourth parameter invoke getaddrinfo, params, 0, 0, esp
push 0 ; third parameter
push 0 ; second parameter
push params ; first parameter
call [getaddrinfo]
pop esi pop esi
; test for error ; test for error
test eax, eax test eax, eax
@ -141,19 +126,16 @@ parse_param:
mov eax, [esi+addrinfo.ai_addr] mov eax, [esi+addrinfo.ai_addr]
mov eax, [eax+sockaddr_in.sin_addr] mov eax, [eax+sockaddr_in.sin_addr]
mov [sockaddr1.ip], eax mov [sockaddr1.ip], eax
push eax invoke inet_ntoa
call [inet_ntoa]
; write result ; write result
mov [ip_ptr], eax mov [ip_ptr], eax
push eax push eax
; free allocated memory ; free allocated memory
push esi invoke freeaddrinfo, esi
call [freeaddrinfo]
push str4 invoke con_write_asciiz, str4
call [con_write_asciiz]
mcall socket, AF_INET4, SOCK_RAW, IPPROTO_ICMP mcall socket, AF_INET4, SOCK_RAW, IPPROTO_ICMP
cmp eax, -1 cmp eax, -1
@ -171,14 +153,9 @@ parse_param:
mcall 40, EVM_STACK mcall 40, EVM_STACK
push str3 invoke con_write_asciiz, str3
call [con_write_asciiz] invoke con_write_asciiz, [ip_ptr]
invoke con_write_asciiz, str4
push [ip_ptr]
call [con_write_asciiz]
push str4
call [con_write_asciiz]
mov [ttl], 1 mov [ttl], 1
@ -187,13 +164,20 @@ parse_param:
mcall recv, [icmp_socket], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT ;; dummy read mcall recv, [icmp_socket], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT ;; dummy read
mainloop: mainloop:
call [con_get_flags] invoke con_get_flags
test eax, 0x200 ; con window closed? test eax, 0x200 ; con window closed?
jnz exit_now jnz exit_now
invoke con_kbhit
test eax, eax
jz .nokey
invoke con_getch2
cmp ax, 0x1E03 ; Ctrl+C
je main
.nokey:
pushd [ttl] pushd [ttl]
pushd str9 invoke con_printf, str9
call [con_printf]
add esp, 2*4 add esp, 2*4
DEBUGF 2, "Setsockopt\n" DEBUGF 2, "Setsockopt\n"
@ -285,8 +269,7 @@ mainloop:
push edx push edx
push eax push eax
push str1 invoke con_printf, str1
call [con_printf]
add esp, 3*4 add esp, 3*4
mov ebx, [buffer_ptr + IPv4_header.SourceAddress] mov ebx, [buffer_ptr + IPv4_header.SourceAddress]
@ -305,8 +288,7 @@ mainloop:
movzx ebx, al movzx ebx, al
push ebx push ebx
push str2 invoke con_printf, str2
call [con_printf]
add esp, 5*4 add esp, 5*4
ret ret
@ -315,15 +297,13 @@ mainloop:
; Invalid reply ; Invalid reply
.invalid: .invalid:
DEBUGF 2, "Invalid response\n" DEBUGF 2, "Invalid response\n"
push str10 invoke con_write_asciiz, str10
call [con_write_asciiz]
jmp main ;.continue jmp main ;.continue
; Timeout! ; Timeout!
.timeout: .timeout:
DEBUGF 2, "Timeout\n", eax DEBUGF 2, "Timeout\n", eax
push str8 invoke con_write_asciiz, str8
call [con_write_asciiz]
; Send more ICMP packets ? ; Send more ICMP packets ?
.continue: .continue:
@ -335,20 +315,17 @@ mainloop:
; DNS error ; DNS error
fail: fail:
push str5 invoke con_write_asciiz, str5
call [con_write_asciiz]
jmp main jmp main
; Socket error ; Socket error
fail2: fail2:
push str6 invoke con_write_asciiz, str6
call [con_write_asciiz]
jmp main jmp main
; Finally.. exit! ; Finally.. exit!
exit: exit:
push 1 invoke con_exit, 1
call [con_exit]
exit_now: exit_now:
mcall -1 mcall -1
@ -450,12 +427,8 @@ reverse_dns_lookup:
@@: @@:
stosb stosb
push buffer_ptr invoke con_write_asciiz, buffer_ptr
call [con_write_asciiz] invoke con_write_asciiz, str7
push str7
call [con_write_asciiz]
ret ret
.fail: .fail:
@ -561,7 +534,8 @@ import console, \
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' con_get_flags, 'con_get_flags',\
con_kbhit, 'con_kbhit'
import network, \ import network, \
getaddrinfo, 'getaddrinfo', \ getaddrinfo, 'getaddrinfo', \