forked from KolibriOS/kolibrios
Ping: improved user interface.
git-svn-id: svn://kolibrios.org@4012 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
f31a95f957
commit
b07f07e58c
@ -12,9 +12,12 @@
|
|||||||
;; ;;
|
;; ;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
; TODO: more precise timer, ttl, user selectable size/number of packets
|
||||||
|
|
||||||
format binary as ""
|
format binary as ""
|
||||||
|
|
||||||
BUFFERSIZE = 1500
|
BUFFERSIZE = 1500
|
||||||
|
IDENTIFIER = 0x1337
|
||||||
|
|
||||||
use32
|
use32
|
||||||
org 0x0
|
org 0x0
|
||||||
@ -122,12 +125,18 @@ resolve:
|
|||||||
|
|
||||||
mov [count], 4
|
mov [count], 4
|
||||||
|
|
||||||
mainloop:
|
|
||||||
push str3
|
push str3
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
|
|
||||||
push [ip_ptr]
|
push [ip_ptr]
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
|
|
||||||
|
push (icmp_packet.length - ICMP_Packet.Data)
|
||||||
|
push str3b
|
||||||
|
call [con_printf]
|
||||||
|
|
||||||
|
mainloop:
|
||||||
|
inc [stats.tx]
|
||||||
mcall 26,9
|
mcall 26,9
|
||||||
mov [time_reference], eax
|
mov [time_reference], eax
|
||||||
mcall send, [socketnum], icmp_packet, icmp_packet.length, 0
|
mcall send, [socketnum], icmp_packet, icmp_packet.length, 0
|
||||||
@ -137,23 +146,44 @@ mainloop:
|
|||||||
neg [time_reference]
|
neg [time_reference]
|
||||||
add [time_reference], eax
|
add [time_reference], eax
|
||||||
|
|
||||||
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
|
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je .no_response
|
je .no_response
|
||||||
|
|
||||||
|
sub eax, ICMP_Packet.Data
|
||||||
|
jb .no_response ; FIXME: use other error message?
|
||||||
|
mov [recvd], eax
|
||||||
|
|
||||||
|
cmp word[buffer_ptr + ICMP_Packet.Identifier], IDENTIFIER
|
||||||
|
jne .no_response ; FIXME: use other error message?
|
||||||
|
|
||||||
|
; OK, we have a response, update stats and let the user know
|
||||||
|
inc [stats.rx]
|
||||||
|
mov eax, [time_reference]
|
||||||
|
add [stats.time], eax
|
||||||
|
|
||||||
|
push str11 ; TODO: print IP address of packet sender
|
||||||
|
call [con_write_asciiz]
|
||||||
|
|
||||||
; validate the packet
|
; validate the packet
|
||||||
lea esi, [buffer_ptr + ICMP_Packet.Data]
|
lea esi, [buffer_ptr + ICMP_Packet.Data]
|
||||||
|
mov ecx, [recvd]
|
||||||
mov edi, icmp_packet.data
|
mov edi, icmp_packet.data
|
||||||
mov ecx, 32/4
|
repe cmpsb
|
||||||
repe cmpsd
|
|
||||||
jne .miscomp
|
jne .miscomp
|
||||||
|
|
||||||
|
; All OK, print to the user!
|
||||||
push [time_reference]
|
push [time_reference]
|
||||||
|
movzx eax, word[buffer_ptr + ICMP_Packet.SequenceNumber]
|
||||||
|
push eax
|
||||||
|
push [recvd]
|
||||||
|
|
||||||
push str7
|
push str7
|
||||||
call [con_printf]
|
call [con_printf]
|
||||||
|
|
||||||
jmp continue
|
jmp continue
|
||||||
|
|
||||||
|
; Error in packet, print it to user
|
||||||
.miscomp:
|
.miscomp:
|
||||||
sub edi, icmp_packet.data
|
sub edi, icmp_packet.data
|
||||||
push edi
|
push edi
|
||||||
@ -161,32 +191,49 @@ mainloop:
|
|||||||
call [con_printf]
|
call [con_printf]
|
||||||
jmp continue
|
jmp continue
|
||||||
|
|
||||||
|
; Timeout!
|
||||||
.no_response:
|
.no_response:
|
||||||
push str8
|
push str8
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
|
|
||||||
|
; Send more ICMP packets ?
|
||||||
continue:
|
continue:
|
||||||
dec [count]
|
dec [count]
|
||||||
jz done
|
jz done
|
||||||
|
|
||||||
mcall 5, 100 ; wait a second
|
mcall 5, 100 ; wait a second
|
||||||
inc [icmp_packet.id]
|
|
||||||
|
inc [icmp_packet.seq]
|
||||||
jmp mainloop
|
jmp mainloop
|
||||||
|
|
||||||
|
; Done..
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
xor edx, edx
|
||||||
|
mov eax, [stats.time]
|
||||||
|
div [stats.rx]
|
||||||
|
push eax
|
||||||
|
push [stats.rx]
|
||||||
|
push [stats.tx]
|
||||||
|
push str12
|
||||||
|
call [con_printf]
|
||||||
|
|
||||||
push str10
|
push str10
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
call [con_getch2]
|
call [con_getch2]
|
||||||
push 1
|
push 1
|
||||||
call [con_exit]
|
call [con_exit]
|
||||||
|
|
||||||
|
; Finally.. exit!
|
||||||
exit:
|
exit:
|
||||||
mcall -1
|
mcall -1
|
||||||
|
|
||||||
|
; DNS error
|
||||||
fail:
|
fail:
|
||||||
push str5
|
push str5
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
jmp done
|
jmp done
|
||||||
|
|
||||||
|
; Socket error
|
||||||
fail2:
|
fail2:
|
||||||
push str6
|
push str6
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
@ -196,15 +243,21 @@ fail2:
|
|||||||
; data
|
; data
|
||||||
title db 'ICMP - echo client',0
|
title db 'ICMP - echo client',0
|
||||||
str2 db '> ',0
|
str2 db '> ',0
|
||||||
str3 db 'Ping to ',0
|
str3 db 'Pinging to ',0
|
||||||
|
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
|
||||||
str7 db ' time= %u0ms',10,0
|
|
||||||
str8 db ' timeout!',10,0
|
str11 db 'Answer: ',0
|
||||||
str9 db ' miscompare at offset %u',10,0
|
str7 db 'bytes=%u seq=%u time=%u0 ms',10,0
|
||||||
|
str8 db 'timeout!',10,0
|
||||||
|
str9 db 'miscompare at offset %u',10,0
|
||||||
str10 db 10,'Press any key to exit',0
|
str10 db 10,'Press any key to exit',0
|
||||||
|
|
||||||
|
str12 db 10,'Ping stats:',10,'%u packets sent, %u packets received',10,'average response time=%u0 ms',10,0
|
||||||
|
|
||||||
sockaddr1:
|
sockaddr1:
|
||||||
dw AF_INET4
|
dw AF_INET4
|
||||||
.port dw 0
|
.port dw 0
|
||||||
@ -214,7 +267,12 @@ sockaddr1:
|
|||||||
time_reference dd ?
|
time_reference dd ?
|
||||||
ip_ptr dd ?
|
ip_ptr dd ?
|
||||||
count dd ?
|
count dd ?
|
||||||
|
recvd dd ? ; received number of bytes in last packet
|
||||||
|
|
||||||
|
stats:
|
||||||
|
.tx dd 0
|
||||||
|
.rx dd 0
|
||||||
|
.time dd 0
|
||||||
|
|
||||||
; import
|
; import
|
||||||
align 4
|
align 4
|
||||||
@ -242,9 +300,9 @@ socketnum dd ?
|
|||||||
icmp_packet: db 8 ; type
|
icmp_packet: db 8 ; type
|
||||||
db 0 ; code
|
db 0 ; code
|
||||||
dw 0 ;
|
dw 0 ;
|
||||||
.id dw 0x0000 ; identifier
|
.id dw IDENTIFIER ; identifier
|
||||||
.seq dw 0x0001 ; sequence number
|
.seq dw 0x0000 ; sequence number
|
||||||
.data db 'abcdefghijklmnopqrstuvwxyz012345678'
|
.data db 'abcdefghijklmnopqrstuvwxyz012345'
|
||||||
.length = $ - icmp_packet
|
.length = $ - icmp_packet
|
||||||
|
|
||||||
I_END:
|
I_END:
|
||||||
|
Loading…
Reference in New Issue
Block a user