forked from KolibriOS/kolibrios
Ping: Initiate ICMP packet id with program PID, receive more packets if ID didnt match and timeout didnt exceed.
git-svn-id: svn://kolibrios.org@7891 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
f53424d741
commit
d0a8eb080c
@ -1,6 +1,6 @@
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;;
|
;; Copyright (C) KolibriOS team 2010-2020. 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 ;;
|
||||||
@ -14,8 +14,7 @@
|
|||||||
|
|
||||||
format binary as ""
|
format binary as ""
|
||||||
|
|
||||||
BUFFERSIZE = 1500
|
BUFFERSIZE = 65536
|
||||||
IDENTIFIER = 0x1337
|
|
||||||
|
|
||||||
use32
|
use32
|
||||||
org 0x0
|
org 0x0
|
||||||
@ -58,6 +57,10 @@ START:
|
|||||||
push 25
|
push 25
|
||||||
push 80
|
push 80
|
||||||
call [con_init]
|
call [con_init]
|
||||||
|
; Init identifier with our PID number
|
||||||
|
mcall 9, thread_info, -1
|
||||||
|
mov eax, [thread_info.PID]
|
||||||
|
mov [icmp_packet.id], ax
|
||||||
; expand payload to 65504 bytes
|
; expand payload to 65504 bytes
|
||||||
mov edi, icmp_packet.data+32
|
mov edi, icmp_packet.data+32
|
||||||
mov ecx, 65504/32-1
|
mov ecx, 65504/32-1
|
||||||
@ -261,7 +264,13 @@ mainloop:
|
|||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je fail2
|
je fail2
|
||||||
|
|
||||||
mcall 23, [timeout]
|
mov [time_exceeded], 0
|
||||||
|
.receiveloop:
|
||||||
|
mov ebx, [timeout]
|
||||||
|
sub ebx, [time_exceeded]
|
||||||
|
jb .no_response
|
||||||
|
mcall 23 ; Wait for network event with timeout
|
||||||
|
|
||||||
mcall 26, 10 ; Get high precision timer count
|
mcall 26, 10 ; Get high precision timer count
|
||||||
sub eax, [time_reference]
|
sub eax, [time_reference]
|
||||||
jz @f
|
jz @f
|
||||||
@ -272,7 +281,7 @@ mainloop:
|
|||||||
jb @f
|
jb @f
|
||||||
inc eax
|
inc eax
|
||||||
@@:
|
@@:
|
||||||
mov [time_reference], eax
|
mov [time_exceeded], eax ; Exceeded time in 1/100 s
|
||||||
|
|
||||||
; Receive reply
|
; Receive reply
|
||||||
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT
|
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT
|
||||||
@ -295,6 +304,11 @@ mainloop:
|
|||||||
; make esi point to ICMP packet header
|
; make esi point to ICMP packet header
|
||||||
add esi, buffer_ptr
|
add esi, buffer_ptr
|
||||||
|
|
||||||
|
; Check identifier
|
||||||
|
mov ax, [icmp_packet.id]
|
||||||
|
cmp [esi + ICMP_header.Identifier], ax
|
||||||
|
jne .receiveloop
|
||||||
|
|
||||||
; we have a response, print the sender IP
|
; we have a response, print the sender IP
|
||||||
push esi
|
push esi
|
||||||
mov eax, [buffer_ptr + IPv4_header.SourceAddress]
|
mov eax, [buffer_ptr + IPv4_header.SourceAddress]
|
||||||
@ -324,10 +338,7 @@ mainloop:
|
|||||||
|
|
||||||
.echo_reply:
|
.echo_reply:
|
||||||
|
|
||||||
cmp [esi + ICMP_header.Identifier], IDENTIFIER
|
; Validate the payload
|
||||||
jne .invalid
|
|
||||||
|
|
||||||
; Validate the packet
|
|
||||||
add esi, sizeof.ICMP_header
|
add esi, sizeof.ICMP_header
|
||||||
mov ecx, [size]
|
mov ecx, [size]
|
||||||
mov edi, icmp_packet.data
|
mov edi, icmp_packet.data
|
||||||
@ -336,12 +347,13 @@ mainloop:
|
|||||||
|
|
||||||
; update stats
|
; update stats
|
||||||
inc [stats.rx]
|
inc [stats.rx]
|
||||||
mov eax, [time_reference]
|
mov eax, [time_exceeded]
|
||||||
add [stats.time], eax
|
add [stats.time], eax
|
||||||
|
|
||||||
|
; Print time exceeded
|
||||||
movzx eax, [buffer_ptr + IPv4_header.TimeToLive]
|
movzx eax, [buffer_ptr + IPv4_header.TimeToLive]
|
||||||
push eax
|
push eax
|
||||||
mov eax, [time_reference]
|
mov eax, [time_exceeded]
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
mov ebx, 10
|
mov ebx, 10
|
||||||
div ebx
|
div ebx
|
||||||
@ -504,7 +516,8 @@ sockaddr1:
|
|||||||
.ip dd 0
|
.ip dd 0
|
||||||
rb 10
|
rb 10
|
||||||
|
|
||||||
time_reference dd ?
|
time_reference dd ? ; start time of sent packet
|
||||||
|
time_exceeded dd ? ; time exceeded between send and receive
|
||||||
ip_ptr dd ?
|
ip_ptr dd ?
|
||||||
count dd ?
|
count dd ?
|
||||||
size dd ?
|
size dd ?
|
||||||
@ -544,13 +557,15 @@ socketnum dd ?
|
|||||||
icmp_packet db ICMP_ECHO ; type
|
icmp_packet db ICMP_ECHO ; type
|
||||||
db 0 ; code
|
db 0 ; code
|
||||||
dw 0 ; checksum
|
dw 0 ; checksum
|
||||||
.id dw IDENTIFIER ; identifier
|
.id dw 0 ; identifier
|
||||||
.seq dw 0x0000 ; sequence number
|
.seq dw 0x0000 ; sequence number
|
||||||
.data db 'abcdefghijklmnopqrstuvwxyz012345'
|
.data db 'abcdefghijklmnopqrstuvwxyz012345'
|
||||||
|
|
||||||
I_END:
|
I_END:
|
||||||
rb 65504-32
|
rb 65504-32
|
||||||
|
|
||||||
|
thread_info process_information
|
||||||
|
|
||||||
params rb 1024
|
params rb 1024
|
||||||
buffer_ptr: rb BUFFERSIZE
|
buffer_ptr: rb BUFFERSIZE
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user