forked from KolibriOS/kolibrios
ping: Use high precision timer.
git-svn-id: svn://kolibrios.org@5805 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
5d4d8a053c
commit
a7431a44f0
@ -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 ;;
|
;; Distributed under terms of the GNU General Public License ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; ping.asm - ICMP echo client for KolibriOS ;;
|
;; ping.asm - ICMP echo client for KolibriOS ;;
|
||||||
@ -12,7 +12,7 @@
|
|||||||
;; ;;
|
;; ;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
; TODO: more precise timer, ttl, user selectable size/number of packets
|
; TODO: ttl, user selectable size/number of packets
|
||||||
|
|
||||||
format binary as ""
|
format binary as ""
|
||||||
|
|
||||||
@ -24,25 +24,27 @@ use32
|
|||||||
|
|
||||||
db 'MENUET01' ; signature
|
db 'MENUET01' ; signature
|
||||||
dd 1 ; header version
|
dd 1 ; header version
|
||||||
dd start ; entry point
|
dd START ; entry point
|
||||||
dd I_END ; initialized size
|
dd I_END ; initialized size
|
||||||
dd mem ; required memory
|
dd IM_END+0x1000 ; required memory
|
||||||
dd mem ; stack pointer
|
dd IM_END+0x1000 ; stack pointer
|
||||||
dd s ; parameters
|
dd s ; parameters
|
||||||
dd 0 ; path
|
dd 0 ; path
|
||||||
|
|
||||||
|
include '../../proc32.inc'
|
||||||
; useful includes
|
|
||||||
include '../../macros.inc'
|
include '../../macros.inc'
|
||||||
purge mov,add,sub
|
purge mov,add,sub
|
||||||
include '../../proc32.inc'
|
|
||||||
include '../../dll.inc'
|
include '../../dll.inc'
|
||||||
include '../../network.inc'
|
include '../../network.inc'
|
||||||
|
|
||||||
include 'icmp.inc'
|
include 'icmp.inc'
|
||||||
|
|
||||||
|
|
||||||
start:
|
START:
|
||||||
|
; init heap
|
||||||
|
mcall 68, 11
|
||||||
|
test eax, eax
|
||||||
|
jz exit
|
||||||
; load libraries
|
; load libraries
|
||||||
stdcall dll.Load, @IMPORT
|
stdcall dll.Load, @IMPORT
|
||||||
test eax, eax
|
test eax, eax
|
||||||
@ -82,7 +84,7 @@ main:
|
|||||||
lodsb
|
lodsb
|
||||||
test al, al
|
test al, al
|
||||||
jnz @b
|
jnz @b
|
||||||
mov byte [esi-2], al
|
mov [esi-2], al
|
||||||
pop esi
|
pop esi
|
||||||
|
|
||||||
; reset stats
|
; reset stats
|
||||||
@ -165,7 +167,7 @@ parse_param:
|
|||||||
|
|
||||||
mcall connect, [socketnum], sockaddr1, 18
|
mcall connect, [socketnum], sockaddr1, 18
|
||||||
|
|
||||||
mcall 40, 1 shl 7 ; + 7
|
mcall 40, EVM_STACK
|
||||||
; call [con_cls]
|
; call [con_cls]
|
||||||
|
|
||||||
push str3
|
push str3
|
||||||
@ -184,16 +186,21 @@ mainloop:
|
|||||||
jnz exit_now
|
jnz exit_now
|
||||||
|
|
||||||
inc [stats.tx]
|
inc [stats.tx]
|
||||||
mcall 26, 9
|
mcall 26, 10 ; Get high precision timer count
|
||||||
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
|
||||||
|
|
||||||
mcall 23, 300 ; 3 seconds time-out
|
mcall 23, 300 ; 3 seconds time-out
|
||||||
mcall 26, 9
|
mcall 26, 10 ; Get high precision timer count
|
||||||
sub eax, [time_reference]
|
sub eax, [time_reference]
|
||||||
|
jz @f
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
mov cx, 10
|
mov ebx, 100000
|
||||||
mul cx
|
div ebx
|
||||||
|
cmp edx, 50000
|
||||||
|
jb @f
|
||||||
|
inc eax
|
||||||
|
@@:
|
||||||
mov [time_reference], eax
|
mov [time_reference], eax
|
||||||
|
|
||||||
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT
|
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT
|
||||||
@ -223,9 +230,14 @@ mainloop:
|
|||||||
jne .miscomp
|
jne .miscomp
|
||||||
|
|
||||||
; All OK, print to the user!
|
; All OK, print to the user!
|
||||||
push [time_reference]
|
mov eax, [time_reference]
|
||||||
movzx eax, word[buffer_ptr + ICMP_Packet.SequenceNumber]
|
xor edx, edx
|
||||||
|
mov ebx, 10
|
||||||
|
div ebx
|
||||||
|
push edx
|
||||||
push eax
|
push eax
|
||||||
|
; movzx eax, word[buffer_ptr + ICMP_Packet.SequenceNumber]
|
||||||
|
; push eax
|
||||||
push [recvd]
|
push [recvd]
|
||||||
|
|
||||||
push str7
|
push str7
|
||||||
@ -270,12 +282,17 @@ done:
|
|||||||
cmp [stats.rx], 0
|
cmp [stats.rx], 0
|
||||||
jne @f
|
jne @f
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
|
xor edx, edx
|
||||||
jmp .zero
|
jmp .zero
|
||||||
@@:
|
@@:
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
mov eax, [stats.time]
|
mov eax, [stats.time]
|
||||||
div [stats.rx]
|
div [stats.rx]
|
||||||
|
xor edx, edx
|
||||||
|
mov ebx, 10
|
||||||
|
div ebx
|
||||||
.zero:
|
.zero:
|
||||||
|
push edx
|
||||||
push eax
|
push eax
|
||||||
push [stats.rx]
|
push [stats.rx]
|
||||||
push [stats.tx]
|
push [stats.tx]
|
||||||
@ -317,12 +334,12 @@ str6 db 'Could not open socket',10,0
|
|||||||
str13 db 'Invalid parameter(s)',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 time=%u.%u ms',10,0
|
||||||
str8 db 'timeout!',10,0
|
str8 db 'Timeout',10,0
|
||||||
str9 db 'miscompare at offset %u',10,0
|
str9 db 'Miscompare at offset %u',10,0
|
||||||
str10 db 'reply invalid',10,0
|
str10 db 'Invalid reply',10,0
|
||||||
|
|
||||||
str12 db 10,'Ping stats:',10,'%u packets sent, %u packets received',10,'average response time=%u ms',10,0
|
str12 db 10,'Statistics:',10,'%u packets sent, %u packets received',10,'average response time=%u.%u ms',10,0
|
||||||
|
|
||||||
sockaddr1:
|
sockaddr1:
|
||||||
dw AF_INET4
|
dw AF_INET4
|
||||||
@ -364,7 +381,7 @@ import console, \
|
|||||||
|
|
||||||
socketnum dd ?
|
socketnum dd ?
|
||||||
|
|
||||||
icmp_packet: db 8 ; type
|
icmp_packet db 8 ; type
|
||||||
db 0 ; code
|
db 0 ; code
|
||||||
dw 0 ;
|
dw 0 ;
|
||||||
.id dw IDENTIFIER ; identifier
|
.id dw IDENTIFIER ; identifier
|
||||||
@ -374,8 +391,8 @@ icmp_packet: db 8 ; type
|
|||||||
|
|
||||||
I_END:
|
I_END:
|
||||||
|
|
||||||
|
s db 0
|
||||||
|
rb 1024
|
||||||
buffer_ptr rb BUFFERSIZE
|
buffer_ptr rb BUFFERSIZE
|
||||||
|
|
||||||
s rb 1024
|
IM_END:
|
||||||
rb 4096 ; stack
|
|
||||||
mem:
|
|
||||||
|
Loading…
Reference in New Issue
Block a user