Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5805 → Rev 5804

/programs/network/icmp/ping.asm
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2010-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; ping.asm - ICMP echo client for KolibriOS ;;
12,7 → 12,7
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
; TODO: ttl, user selectable size/number of packets
; TODO: more precise timer, ttl, user selectable size/number of packets
 
format binary as ""
 
24,16 → 24,18
 
db 'MENUET01' ; signature
dd 1 ; header version
dd START ; entry point
dd start ; entry point
dd I_END ; initialized size
dd IM_END+0x1000 ; required memory
dd IM_END+0x1000 ; stack pointer
dd mem ; required memory
dd mem ; stack pointer
dd s ; parameters
dd 0 ; path
 
include '../../proc32.inc'
 
; useful includes
include '../../macros.inc'
purge mov,add,sub
include '../../proc32.inc'
include '../../dll.inc'
include '../../network.inc'
 
40,11 → 42,7
include 'icmp.inc'
 
 
START:
; init heap
mcall 68, 11
test eax, eax
jz exit
start:
; load libraries
stdcall dll.Load, @IMPORT
test eax, eax
84,7 → 82,7
lodsb
test al, al
jnz @b
mov [esi-2], al
mov byte [esi-2], al
pop esi
 
; reset stats
167,7 → 165,7
 
mcall connect, [socketnum], sockaddr1, 18
 
mcall 40, EVM_STACK
mcall 40, 1 shl 7 ; + 7
; call [con_cls]
 
push str3
186,21 → 184,16
jnz exit_now
 
inc [stats.tx]
mcall 26, 10 ; Get high precision timer count
mcall 26, 9
mov [time_reference], eax
mcall send, [socketnum], icmp_packet, icmp_packet.length, 0
 
mcall 23, 300 ; 3 seconds time-out
mcall 26, 10 ; Get high precision timer count
mcall 26, 9
sub eax, [time_reference]
jz @f
xor edx, edx
mov ebx, 100000
div ebx
cmp edx, 50000
jb @f
inc eax
@@:
mov cx, 10
mul cx
mov [time_reference], eax
 
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT
230,14 → 223,9
jne .miscomp
 
; All OK, print to the user!
mov eax, [time_reference]
xor edx, edx
mov ebx, 10
div ebx
push edx
push [time_reference]
movzx eax, word[buffer_ptr + ICMP_Packet.SequenceNumber]
push eax
; movzx eax, word[buffer_ptr + ICMP_Packet.SequenceNumber]
; push eax
push [recvd]
 
push str7
282,17 → 270,12
cmp [stats.rx], 0
jne @f
xor eax, eax
xor edx, edx
jmp .zero
@@:
xor edx, edx
mov eax, [stats.time]
div [stats.rx]
xor edx, edx
mov ebx, 10
div ebx
.zero:
push edx
push eax
push [stats.rx]
push [stats.tx]
334,12 → 317,12
str13 db 'Invalid parameter(s)',10,0
 
str11 db 'Answer: ',0
str7 db 'bytes=%u time=%u.%u ms',10,0
str8 db 'Timeout',10,0
str9 db 'Miscompare at offset %u',10,0
str10 db 'Invalid reply',10,0
str7 db 'bytes=%u seq=%u time=%u ms',10,0
str8 db 'timeout!',10,0
str9 db 'miscompare at offset %u',10,0
str10 db 'reply invalid',10,0
 
str12 db 10,'Statistics:',10,'%u packets sent, %u packets received',10,'average response time=%u.%u ms',10,0
str12 db 10,'Ping stats:',10,'%u packets sent, %u packets received',10,'average response time=%u ms',10,0
 
sockaddr1:
dw AF_INET4
381,7 → 364,7
 
socketnum dd ?
 
icmp_packet db 8 ; type
icmp_packet: db 8 ; type
db 0 ; code
dw 0 ;
.id dw IDENTIFIER ; identifier
391,8 → 374,8
 
I_END:
 
s db 0
rb 1024
buffer_ptr rb BUFFERSIZE
 
IM_END:
s rb 1024
rb 4096 ; stack
mem: