2013-05-28 19:34:26 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-09-05 19:54:21 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; ping.asm - ICMP echo client for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
format binary as ""
|
|
|
|
|
2013-06-07 19:26:03 +02:00
|
|
|
BUFFERSIZE = 1500
|
2013-10-12 15:59:29 +02:00
|
|
|
IDENTIFIER = 0x1337
|
2013-06-07 19:26:03 +02:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
use32
|
|
|
|
org 0x0
|
|
|
|
|
|
|
|
db 'MENUET01' ; signature
|
|
|
|
dd 1 ; header version
|
2015-09-05 19:54:21 +02:00
|
|
|
dd START ; entry point
|
2013-05-28 19:34:26 +02:00
|
|
|
dd I_END ; initialized size
|
2015-09-05 19:54:21 +02:00
|
|
|
dd IM_END+0x1000 ; required memory
|
|
|
|
dd IM_END+0x1000 ; stack pointer
|
2015-10-11 20:23:40 +02:00
|
|
|
dd params ; parameters
|
2013-05-28 19:34:26 +02:00
|
|
|
dd 0 ; path
|
|
|
|
|
2015-09-05 19:54:21 +02:00
|
|
|
include '../../proc32.inc'
|
2013-06-07 19:26:03 +02:00
|
|
|
include '../../macros.inc'
|
2013-05-28 19:34:26 +02:00
|
|
|
purge mov,add,sub
|
2013-06-07 19:26:03 +02:00
|
|
|
include '../../dll.inc'
|
2015-10-11 20:23:40 +02:00
|
|
|
include '../../struct.inc'
|
2013-06-07 19:26:03 +02:00
|
|
|
include '../../network.inc'
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
include 'icmp.inc'
|
2015-10-11 20:23:40 +02:00
|
|
|
include 'ip.inc'
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
2015-09-05 19:54:21 +02:00
|
|
|
START:
|
|
|
|
; init heap
|
|
|
|
mcall 68, 11
|
|
|
|
test eax, eax
|
|
|
|
jz exit
|
2013-05-28 19:34:26 +02:00
|
|
|
; load libraries
|
|
|
|
stdcall dll.Load, @IMPORT
|
|
|
|
test eax, eax
|
|
|
|
jnz exit
|
|
|
|
; initialize console
|
|
|
|
push 1
|
|
|
|
call [con_start]
|
|
|
|
push title
|
2015-10-11 20:23:40 +02:00
|
|
|
push 250
|
2013-05-28 19:34:26 +02:00
|
|
|
push 80
|
|
|
|
push 25
|
|
|
|
push 80
|
|
|
|
call [con_init]
|
2015-10-11 20:23:40 +02:00
|
|
|
; expand payload to 65504 bytes
|
|
|
|
mov edi, icmp_packet.data+32
|
|
|
|
mov ecx, 65504/32-1
|
|
|
|
.expand_payload:
|
|
|
|
mov esi, icmp_packet.data
|
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
dec ecx
|
|
|
|
jnz .expand_payload
|
2013-05-28 19:34:26 +02:00
|
|
|
; main loop
|
2015-10-11 20:23:40 +02:00
|
|
|
cmp byte[params], 0
|
2014-12-19 23:46:30 +01:00
|
|
|
jne parse_param
|
2013-10-13 22:27:48 +02:00
|
|
|
|
|
|
|
push str_welcome
|
|
|
|
call [con_write_asciiz]
|
2013-05-28 19:34:26 +02:00
|
|
|
main:
|
|
|
|
; write prompt
|
2013-10-13 22:27:48 +02:00
|
|
|
push str_prompt
|
2013-05-28 19:34:26 +02:00
|
|
|
call [con_write_asciiz]
|
|
|
|
; read string
|
2015-10-11 20:23:40 +02:00
|
|
|
mov esi, params
|
|
|
|
push 1024
|
2013-05-28 19:34:26 +02:00
|
|
|
push esi
|
|
|
|
call [con_gets]
|
|
|
|
; check for exit
|
|
|
|
test eax, eax
|
2013-10-14 09:03:53 +02:00
|
|
|
jz exit
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp byte [esi], 10
|
2013-10-14 09:03:53 +02:00
|
|
|
jz exit
|
2013-05-28 19:34:26 +02:00
|
|
|
; delete terminating '\n'
|
|
|
|
push esi
|
|
|
|
@@:
|
|
|
|
lodsb
|
|
|
|
test al, al
|
|
|
|
jnz @b
|
2015-09-05 19:54:21 +02:00
|
|
|
mov [esi-2], al
|
2013-05-28 19:34:26 +02:00
|
|
|
pop esi
|
|
|
|
|
2013-10-13 22:27:48 +02:00
|
|
|
; reset stats
|
|
|
|
mov [stats.tx], 0
|
|
|
|
mov [stats.rx], 0
|
|
|
|
mov [stats.time], 0
|
|
|
|
|
2014-12-19 23:46:30 +01:00
|
|
|
parse_param:
|
2015-10-11 20:23:40 +02:00
|
|
|
; parameters defaults
|
|
|
|
mov [count], 4
|
|
|
|
mov [size], 32
|
|
|
|
mov [ttl], 128
|
|
|
|
mov [timeout], 300
|
2014-12-19 23:46:30 +01:00
|
|
|
|
|
|
|
; Check if any additional parameters were given
|
2015-10-11 20:23:40 +02:00
|
|
|
mov esi, params
|
2014-12-19 23:46:30 +01:00
|
|
|
mov ecx, 1024
|
|
|
|
.addrloop:
|
|
|
|
lodsb
|
|
|
|
test al, al
|
|
|
|
jz .resolve
|
|
|
|
cmp al, ' '
|
|
|
|
jne .addrloop
|
|
|
|
mov byte[esi-1], 0
|
|
|
|
jmp .param
|
|
|
|
|
|
|
|
.param_loop:
|
|
|
|
lodsb
|
|
|
|
test al, al
|
|
|
|
jz .resolve
|
|
|
|
cmp al, ' '
|
|
|
|
jne .invalid
|
|
|
|
.param:
|
|
|
|
lodsb
|
|
|
|
cmp al, '-'
|
|
|
|
jne .invalid
|
|
|
|
lodsb
|
|
|
|
cmp al, 't'
|
|
|
|
jne @f
|
|
|
|
mov [count], -1 ; infinite
|
|
|
|
jmp .param_loop
|
2015-10-11 20:23:40 +02:00
|
|
|
@@:
|
|
|
|
cmp al, 'n'
|
|
|
|
jne @f
|
|
|
|
call ascii_to_dec
|
|
|
|
test ebx, ebx
|
|
|
|
jz .invalid
|
|
|
|
mov [count], ebx
|
|
|
|
jmp .param_loop
|
|
|
|
@@:
|
|
|
|
cmp al, 'l'
|
|
|
|
jne @f
|
|
|
|
call ascii_to_dec
|
|
|
|
test ebx, ebx
|
|
|
|
jz .invalid
|
|
|
|
cmp ebx, 65500
|
|
|
|
ja .invalid
|
|
|
|
mov [size], ebx
|
|
|
|
jmp .param_loop
|
|
|
|
@@:
|
|
|
|
cmp al, 'i'
|
|
|
|
jne @f
|
|
|
|
call ascii_to_dec
|
|
|
|
test ebx, ebx
|
|
|
|
jz .invalid
|
|
|
|
cmp ebx, 255
|
|
|
|
ja .invalid
|
|
|
|
mov [ttl], ebx
|
|
|
|
jmp .param_loop
|
|
|
|
@@:
|
|
|
|
cmp al, 'w'
|
|
|
|
jne @f
|
|
|
|
call ascii_to_dec
|
|
|
|
test ebx, ebx
|
|
|
|
jz .invalid
|
|
|
|
mov [timeout], ebx
|
|
|
|
jmp .param_loop
|
2014-12-19 23:46:30 +01:00
|
|
|
@@:
|
|
|
|
; implement more parameters here
|
|
|
|
.invalid:
|
|
|
|
push str13
|
|
|
|
call [con_write_asciiz]
|
|
|
|
jmp main
|
|
|
|
|
|
|
|
.resolve:
|
2013-05-28 19:34:26 +02:00
|
|
|
; resolve name
|
|
|
|
push esp ; reserve stack place
|
|
|
|
push esp ; fourth parameter
|
|
|
|
push 0 ; third parameter
|
|
|
|
push 0 ; second parameter
|
2015-10-11 20:23:40 +02:00
|
|
|
push params ; first parameter
|
2013-05-28 19:34:26 +02:00
|
|
|
call [getaddrinfo]
|
|
|
|
pop esi
|
|
|
|
; test for error
|
|
|
|
test eax, eax
|
|
|
|
jnz fail
|
|
|
|
|
|
|
|
; convert IP address to decimal notation
|
|
|
|
mov eax, [esi+addrinfo.ai_addr]
|
|
|
|
mov eax, [eax+sockaddr_in.sin_addr]
|
|
|
|
mov [sockaddr1.ip], eax
|
|
|
|
push eax
|
|
|
|
call [inet_ntoa]
|
|
|
|
; write result
|
|
|
|
mov [ip_ptr], eax
|
|
|
|
|
|
|
|
push eax
|
|
|
|
|
|
|
|
; free allocated memory
|
|
|
|
push esi
|
|
|
|
call [freeaddrinfo]
|
|
|
|
|
|
|
|
push str4
|
|
|
|
call [con_write_asciiz]
|
|
|
|
|
|
|
|
mcall socket, AF_INET4, SOCK_RAW, IPPROTO_ICMP
|
|
|
|
cmp eax, -1
|
|
|
|
jz fail2
|
|
|
|
mov [socketnum], eax
|
|
|
|
|
|
|
|
mcall connect, [socketnum], sockaddr1, 18
|
2015-10-11 20:23:40 +02:00
|
|
|
cmp eax, -1
|
|
|
|
je fail2
|
|
|
|
|
|
|
|
pushd [ttl]
|
|
|
|
pushd 4 ; length of option
|
|
|
|
pushd IP_TTL
|
|
|
|
pushd IPPROTO_IP
|
|
|
|
mcall setsockopt, [socketnum], esp
|
|
|
|
add esp, 16
|
|
|
|
cmp eax, -1
|
|
|
|
je fail2
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-09-05 19:54:21 +02:00
|
|
|
mcall 40, EVM_STACK
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
push str3
|
|
|
|
call [con_write_asciiz]
|
2013-10-12 15:59:29 +02:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
push [ip_ptr]
|
|
|
|
call [con_write_asciiz]
|
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
push [size]
|
2013-10-12 15:59:29 +02:00
|
|
|
push str3b
|
|
|
|
call [con_printf]
|
2015-10-11 20:23:40 +02:00
|
|
|
add esp, 2*4
|
2013-10-12 15:59:29 +02:00
|
|
|
|
|
|
|
mainloop:
|
2014-12-19 23:46:30 +01:00
|
|
|
call [con_get_flags]
|
|
|
|
test eax, 0x200 ; con window closed?
|
|
|
|
jnz exit_now
|
|
|
|
|
2013-10-12 15:59:29 +02:00
|
|
|
inc [stats.tx]
|
2015-09-05 19:54:21 +02:00
|
|
|
mcall 26, 10 ; Get high precision timer count
|
2013-05-28 19:34:26 +02:00
|
|
|
mov [time_reference], eax
|
2015-10-11 20:23:40 +02:00
|
|
|
mov esi, [size]
|
|
|
|
add esi, sizeof.ICMP_header
|
|
|
|
xor edi, edi
|
|
|
|
mcall send, [socketnum], icmp_packet
|
|
|
|
cmp eax, -1
|
|
|
|
je fail2
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
mcall 23, [timeout]
|
2015-09-05 19:54:21 +02:00
|
|
|
mcall 26, 10 ; Get high precision timer count
|
2013-10-12 21:39:47 +02:00
|
|
|
sub eax, [time_reference]
|
2015-09-05 19:54:21 +02:00
|
|
|
jz @f
|
2013-10-12 21:39:47 +02:00
|
|
|
xor edx, edx
|
2015-09-05 19:54:21 +02:00
|
|
|
mov ebx, 100000
|
|
|
|
div ebx
|
|
|
|
cmp edx, 50000
|
|
|
|
jb @f
|
|
|
|
inc eax
|
|
|
|
@@:
|
2013-10-12 21:39:47 +02:00
|
|
|
mov [time_reference], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
; Receive reply
|
2013-10-12 15:59:29 +02:00
|
|
|
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp eax, -1
|
|
|
|
je .no_response
|
2015-10-11 20:23:40 +02:00
|
|
|
test eax, eax
|
|
|
|
jz fail2
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
; IP header length
|
|
|
|
movzx esi, byte[buffer_ptr]
|
|
|
|
and esi, 0xf
|
|
|
|
shl esi, 2
|
|
|
|
|
|
|
|
; Check packet length
|
|
|
|
sub eax, esi
|
|
|
|
sub eax, sizeof.ICMP_header
|
2014-01-17 14:46:09 +01:00
|
|
|
jb .invalid
|
2013-10-12 15:59:29 +02:00
|
|
|
mov [recvd], eax
|
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
; make esi point to ICMP packet header
|
|
|
|
add esi, buffer_ptr
|
2013-10-12 15:59:29 +02:00
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
; we have a response, print the sender IP
|
|
|
|
push esi
|
|
|
|
mov eax, [buffer_ptr + IPv4_header.SourceAddress]
|
|
|
|
rol eax, 16
|
|
|
|
movzx ebx, ah
|
|
|
|
push ebx
|
|
|
|
movzx ebx, al
|
|
|
|
push ebx
|
|
|
|
shr eax, 16
|
|
|
|
movzx ebx, ah
|
|
|
|
push ebx
|
|
|
|
movzx ebx, al
|
|
|
|
push ebx
|
|
|
|
push str11
|
|
|
|
call [con_printf]
|
|
|
|
add esp, 5*4
|
|
|
|
pop esi
|
2013-10-12 15:59:29 +02:00
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
; What kind of response is it?
|
|
|
|
cmp [esi + ICMP_header.Type], ICMP_ECHOREPLY
|
|
|
|
je .echo_reply
|
|
|
|
cmp [esi + ICMP_header.Type], ICMP_TIMXCEED
|
|
|
|
je .ttl_exceeded
|
|
|
|
|
|
|
|
jmp .invalid
|
2013-10-12 15:59:29 +02:00
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
|
|
|
|
.echo_reply:
|
|
|
|
|
|
|
|
cmp [esi + ICMP_header.Identifier], IDENTIFIER
|
|
|
|
jne .invalid
|
|
|
|
|
|
|
|
; Validate the packet
|
|
|
|
add esi, sizeof.ICMP_header
|
|
|
|
mov ecx, [size]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov edi, icmp_packet.data
|
2013-10-12 15:59:29 +02:00
|
|
|
repe cmpsb
|
2013-05-28 19:34:26 +02:00
|
|
|
jne .miscomp
|
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
; update stats
|
|
|
|
inc [stats.rx]
|
|
|
|
mov eax, [time_reference]
|
|
|
|
add [stats.time], eax
|
|
|
|
|
|
|
|
movzx eax, [buffer_ptr + IPv4_header.TimeToLive]
|
|
|
|
push eax
|
2015-09-05 19:54:21 +02:00
|
|
|
mov eax, [time_reference]
|
|
|
|
xor edx, edx
|
|
|
|
mov ebx, 10
|
|
|
|
div ebx
|
|
|
|
push edx
|
2013-10-12 15:59:29 +02:00
|
|
|
push eax
|
|
|
|
push [recvd]
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
push str7
|
|
|
|
call [con_printf]
|
2015-10-11 20:23:40 +02:00
|
|
|
add esp, 5*4
|
|
|
|
|
|
|
|
jmp .continue
|
|
|
|
|
|
|
|
|
|
|
|
.ttl_exceeded:
|
|
|
|
push str14
|
|
|
|
call [con_write_asciiz]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-01-17 14:46:09 +01:00
|
|
|
jmp .continue
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
|
2013-10-12 15:59:29 +02:00
|
|
|
; Error in packet, print it to user
|
2013-05-28 19:34:26 +02:00
|
|
|
.miscomp:
|
2015-10-11 20:23:40 +02:00
|
|
|
sub edi, icmp_packet.data+1
|
2013-05-28 19:34:26 +02:00
|
|
|
push edi
|
|
|
|
push str9
|
|
|
|
call [con_printf]
|
2015-10-11 20:23:40 +02:00
|
|
|
add esp, 2*4
|
2014-01-17 14:46:09 +01:00
|
|
|
jmp .continue
|
|
|
|
|
|
|
|
; Invalid reply
|
|
|
|
.invalid:
|
|
|
|
push str10
|
|
|
|
call [con_write_asciiz]
|
|
|
|
jmp .continue
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-10-12 15:59:29 +02:00
|
|
|
; Timeout!
|
2013-05-28 19:34:26 +02:00
|
|
|
.no_response:
|
|
|
|
push str8
|
|
|
|
call [con_write_asciiz]
|
|
|
|
|
2013-10-12 15:59:29 +02:00
|
|
|
; Send more ICMP packets ?
|
2014-01-17 14:46:09 +01:00
|
|
|
.continue:
|
2014-01-10 08:29:28 +01:00
|
|
|
inc [icmp_packet.seq]
|
|
|
|
|
2014-12-19 23:46:30 +01:00
|
|
|
cmp [count], -1
|
|
|
|
je .forever
|
2013-05-28 19:34:26 +02:00
|
|
|
dec [count]
|
2015-10-11 20:23:40 +02:00
|
|
|
jz .stats
|
2014-12-19 23:46:30 +01:00
|
|
|
.forever:
|
2015-10-11 20:23:40 +02:00
|
|
|
; wait a second before sending next request
|
|
|
|
mcall 5, 100
|
2013-10-12 15:59:29 +02:00
|
|
|
jmp mainloop
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
; Print statistics
|
|
|
|
.stats:
|
2013-10-13 22:27:48 +02:00
|
|
|
cmp [stats.rx], 0
|
|
|
|
jne @f
|
|
|
|
xor eax, eax
|
2015-09-05 19:54:21 +02:00
|
|
|
xor edx, edx
|
2013-10-13 22:27:48 +02:00
|
|
|
jmp .zero
|
|
|
|
@@:
|
2013-10-12 15:59:29 +02:00
|
|
|
xor edx, edx
|
|
|
|
mov eax, [stats.time]
|
|
|
|
div [stats.rx]
|
2015-09-05 19:54:21 +02:00
|
|
|
xor edx, edx
|
|
|
|
mov ebx, 10
|
|
|
|
div ebx
|
2013-10-13 22:27:48 +02:00
|
|
|
.zero:
|
2015-09-05 19:54:21 +02:00
|
|
|
push edx
|
2013-10-12 15:59:29 +02:00
|
|
|
push eax
|
|
|
|
push [stats.rx]
|
|
|
|
push [stats.tx]
|
|
|
|
push str12
|
|
|
|
call [con_printf]
|
2015-10-11 20:23:40 +02:00
|
|
|
add esp, 5*4
|
2013-10-13 22:27:48 +02:00
|
|
|
jmp main
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-10-12 15:59:29 +02:00
|
|
|
; DNS error
|
2013-05-28 19:34:26 +02:00
|
|
|
fail:
|
|
|
|
push str5
|
|
|
|
call [con_write_asciiz]
|
2013-10-13 22:27:48 +02:00
|
|
|
jmp main
|
2013-10-12 15:59:29 +02:00
|
|
|
|
|
|
|
; Socket error
|
2013-05-28 19:34:26 +02:00
|
|
|
fail2:
|
|
|
|
push str6
|
|
|
|
call [con_write_asciiz]
|
2013-10-13 22:27:48 +02:00
|
|
|
jmp main
|
|
|
|
|
|
|
|
; Finally.. exit!
|
|
|
|
exit:
|
|
|
|
push 1
|
|
|
|
call [con_exit]
|
2014-12-19 23:46:30 +01:00
|
|
|
exit_now:
|
2013-10-13 22:27:48 +02:00
|
|
|
mcall -1
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
ascii_to_dec:
|
|
|
|
|
|
|
|
lodsb
|
|
|
|
cmp al, ' '
|
|
|
|
jne .fail
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
.loop:
|
|
|
|
lodsb
|
|
|
|
test al, al
|
|
|
|
jz .done
|
|
|
|
cmp al, ' '
|
|
|
|
je .done
|
|
|
|
sub al, '0'
|
|
|
|
jb .fail
|
|
|
|
cmp al, 9
|
|
|
|
ja .fail
|
|
|
|
lea ebx, [ebx*4+ebx]
|
|
|
|
lea ebx, [ebx*2+eax]
|
|
|
|
jmp .loop
|
|
|
|
.fail:
|
|
|
|
xor ebx, ebx
|
|
|
|
.done:
|
|
|
|
dec esi
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
; data
|
2013-10-13 22:27:48 +02:00
|
|
|
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
|
2015-10-11 20:23:40 +02:00
|
|
|
db 'or just press enter to exit.',10,10
|
|
|
|
db 'Options:',10
|
|
|
|
db ' -t Send packets till users abort.',10
|
|
|
|
db ' -n number Number of requests to send.',10
|
|
|
|
db ' -i TTL Time to live.',10
|
|
|
|
db ' -l size Size of echo request.',10
|
|
|
|
db ' -w time-out Time-out in hundredths of a second.',10,0
|
2013-10-13 22:27:48 +02:00
|
|
|
str_prompt db 10,'> ',0
|
2013-10-12 15:59:29 +02:00
|
|
|
str3 db 'Pinging to ',0
|
|
|
|
str3b db ' with %u data bytes',10,0
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
str4 db 10,0
|
|
|
|
str5 db 'Name resolution failed.',10,0
|
2015-10-11 20:23:40 +02:00
|
|
|
str6 db 'Socket error.',10,0
|
2014-12-19 23:46:30 +01:00
|
|
|
str13 db 'Invalid parameter(s)',10,0
|
2013-10-12 15:59:29 +02:00
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
str11 db 'Answer from %u.%u.%u.%u: ',0
|
|
|
|
str7 db 'bytes=%u time=%u.%u ms TTL=%u',10,0
|
2015-09-05 19:54:21 +02:00
|
|
|
str8 db 'Timeout',10,0
|
2015-10-11 20:23:40 +02:00
|
|
|
str9 db 'miscompare at offset %u.',10,0
|
|
|
|
str10 db 'invalid reply.',10,0
|
|
|
|
str14 db 'TTL expired.',10,0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-09-05 19:54:21 +02:00
|
|
|
str12 db 10,'Statistics:',10,'%u packets sent, %u packets received',10,'average response time=%u.%u ms',10,0
|
2013-10-12 15:59:29 +02:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
sockaddr1:
|
|
|
|
dw AF_INET4
|
|
|
|
.port dw 0
|
|
|
|
.ip dd 0
|
|
|
|
rb 10
|
|
|
|
|
|
|
|
time_reference dd ?
|
|
|
|
ip_ptr dd ?
|
|
|
|
count dd ?
|
2015-10-11 20:23:40 +02:00
|
|
|
size dd ?
|
|
|
|
ttl dd ?
|
|
|
|
timeout dd ?
|
2013-10-12 15:59:29 +02:00
|
|
|
recvd dd ? ; received number of bytes in last packet
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-10-12 15:59:29 +02:00
|
|
|
stats:
|
2013-10-13 22:27:48 +02:00
|
|
|
.tx dd ?
|
|
|
|
.rx dd ?
|
|
|
|
.time dd ?
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; import
|
|
|
|
align 4
|
|
|
|
@IMPORT:
|
|
|
|
|
|
|
|
library network, 'network.obj', console, 'console.obj'
|
|
|
|
import network, \
|
|
|
|
getaddrinfo, 'getaddrinfo', \
|
|
|
|
freeaddrinfo, 'freeaddrinfo', \
|
|
|
|
inet_ntoa, 'inet_ntoa'
|
|
|
|
|
|
|
|
import console, \
|
|
|
|
con_start, 'START', \
|
|
|
|
con_init, 'con_init', \
|
|
|
|
con_write_asciiz, 'con_write_asciiz', \
|
|
|
|
con_printf, 'con_printf', \
|
|
|
|
con_exit, 'con_exit', \
|
|
|
|
con_gets, 'con_gets',\
|
|
|
|
con_cls, 'con_cls',\
|
|
|
|
con_getch2, 'con_getch2',\
|
2014-12-19 23:46:30 +01:00
|
|
|
con_set_cursor_pos, 'con_set_cursor_pos',\
|
|
|
|
con_get_flags, 'con_get_flags'
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
socketnum dd ?
|
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
icmp_packet db ICMP_ECHO ; type
|
2013-05-28 19:34:26 +02:00
|
|
|
db 0 ; code
|
2015-10-11 20:23:40 +02:00
|
|
|
dw 0 ; checksum
|
2013-10-12 15:59:29 +02:00
|
|
|
.id dw IDENTIFIER ; identifier
|
|
|
|
.seq dw 0x0000 ; sequence number
|
|
|
|
.data db 'abcdefghijklmnopqrstuvwxyz012345'
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
I_END:
|
2015-10-11 20:23:40 +02:00
|
|
|
rb 65504-32
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-10-11 20:23:40 +02:00
|
|
|
params rb 1024
|
|
|
|
buffer_ptr: rb BUFFERSIZE
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-09-05 19:54:21 +02:00
|
|
|
IM_END:
|