Rev 7891 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7891 | Rev 9128 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2010-2020. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2010-2021. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; ping.asm - ICMP echo client for KolibriOS ;; |
6 | ;; ping.asm - ICMP echo client for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
Line 47... | Line 47... | ||
47 | ; load libraries |
47 | ; load libraries |
48 | stdcall dll.Load, @IMPORT |
48 | stdcall dll.Load, @IMPORT |
49 | test eax, eax |
49 | test eax, eax |
50 | jnz exit |
50 | jnz exit |
51 | ; initialize console |
51 | ; initialize console |
52 | push 1 |
- | |
53 | call [con_start] |
52 | invoke con_start, 1 |
54 | push title |
- | |
55 | push 250 |
- | |
56 | push 80 |
- | |
57 | push 25 |
- | |
58 | push 80 |
- | |
59 | call [con_init] |
53 | invoke con_init, 80, 25, 80, 250, title |
60 | ; Init identifier with our PID number |
54 | ; Init identifier with our PID number |
61 | mcall 9, thread_info, -1 |
55 | mcall 9, thread_info, -1 |
62 | mov eax, [thread_info.PID] |
56 | mov eax, [thread_info.PID] |
63 | mov [icmp_packet.id], ax |
57 | mov [icmp_packet.id], ax |
64 | ; expand payload to 65504 bytes |
58 | ; expand payload to 65504 bytes |
Line 78... | Line 72... | ||
78 | jnz .expand_payload |
72 | jnz .expand_payload |
79 | ; main loop |
73 | ; main loop |
80 | cmp byte[params], 0 |
74 | cmp byte[params], 0 |
81 | jne parse_param |
75 | jne parse_param |
Line 82... | Line -... | ||
82 | - | ||
83 | push str_welcome |
76 | |
84 | call [con_write_asciiz] |
77 | invoke con_write_asciiz, str_welcome |
85 | main: |
78 | main: |
86 | ; write prompt |
- | |
87 | push str_prompt |
79 | ; write prompt |
88 | call [con_write_asciiz] |
80 | invoke con_write_asciiz, str_prompt |
89 | ; read string |
81 | ; read string |
90 | mov esi, params |
- | |
91 | push 1024 |
- | |
92 | push esi |
82 | mov esi, params |
93 | call [con_gets] |
83 | invoke con_gets, esi, 1024 |
94 | ; check for exit |
84 | ; check for exit |
95 | test eax, eax |
85 | test eax, eax |
96 | jz exit |
86 | jz exit |
97 | cmp byte [esi], 10 |
87 | cmp byte [esi], 10 |
Line 181... | Line 171... | ||
181 | mov [timeout], ebx |
171 | mov [timeout], ebx |
182 | jmp .param_loop |
172 | jmp .param_loop |
183 | @@: |
173 | @@: |
184 | ; implement more parameters here |
174 | ; implement more parameters here |
185 | .invalid: |
175 | .invalid: |
186 | push str13 |
- | |
187 | call [con_write_asciiz] |
176 | invoke con_write_asciiz, str13 |
188 | jmp main |
177 | jmp main |
Line 189... | Line 178... | ||
189 | 178 | ||
190 | .resolve: |
179 | .resolve: |
191 | ; resolve name |
180 | ; resolve name |
192 | push esp ; reserve stack place |
- | |
193 | push esp ; fourth parameter |
- | |
194 | push 0 ; third parameter |
- | |
195 | push 0 ; second parameter |
- | |
196 | push params ; first parameter |
181 | push esp ; reserve stack place |
197 | call [getaddrinfo] |
182 | invoke getaddrinfo, params, 0, 0, esp |
198 | pop esi |
183 | pop esi |
199 | ; test for error |
184 | ; test for error |
200 | test eax, eax |
185 | test eax, eax |
Line 201... | Line 186... | ||
201 | jnz fail |
186 | jnz fail |
202 | 187 | ||
203 | ; convert IP address to decimal notation |
188 | ; convert IP address to decimal notation |
204 | mov eax, [esi+addrinfo.ai_addr] |
189 | mov eax, [esi+addrinfo.ai_addr] |
205 | mov eax, [eax+sockaddr_in.sin_addr] |
- | |
206 | mov [sockaddr1.ip], eax |
190 | mov eax, [eax+sockaddr_in.sin_addr] |
207 | push eax |
191 | mov [sockaddr1.ip], eax |
208 | call [inet_ntoa] |
192 | invoke inet_ntoa, eax |
Line 209... | Line 193... | ||
209 | ; write result |
193 | ; write result |
Line 210... | Line 194... | ||
210 | mov [ip_ptr], eax |
194 | mov [ip_ptr], eax |
211 | - | ||
212 | push eax |
195 | |
Line 213... | Line -... | ||
213 | - | ||
214 | ; free allocated memory |
196 | push eax |
Line 215... | Line 197... | ||
215 | push esi |
197 | |
216 | call [freeaddrinfo] |
198 | ; free allocated memory |
217 | 199 | invoke freeaddrinfo, esi |
|
218 | push str4 |
200 | |
Line 236... | Line 218... | ||
236 | cmp eax, -1 |
218 | cmp eax, -1 |
237 | je fail2 |
219 | je fail2 |
Line 238... | Line 220... | ||
238 | 220 | ||
Line 239... | Line -... | ||
239 | mcall 40, EVM_STACK |
- | |
240 | 221 | mcall 40, EVM_STACK |
|
241 | push str3 |
- | |
242 | call [con_write_asciiz] |
- | |
243 | 222 | ||
244 | push [ip_ptr] |
- | |
245 | call [con_write_asciiz] |
- | |
246 | - | ||
247 | push [size] |
223 | invoke con_write_asciiz, str3 |
248 | push str3b |
224 | invoke con_write_asciiz, [ip_ptr] |
Line 249... | Line 225... | ||
249 | call [con_printf] |
225 | invoke con_printf, str3b, [size] |
250 | add esp, 2*4 |
226 | add esp, 2*4 |
251 | 227 | ||
252 | mainloop: |
228 | mainloop: |
Line 253... | Line 229... | ||
253 | call [con_get_flags] |
229 | invoke con_get_flags |
254 | test eax, 0x200 ; con window closed? |
230 | test eax, 0x200 ; con window closed? |
Line 359... | Line 335... | ||
359 | div ebx |
335 | div ebx |
360 | push edx |
336 | push edx |
361 | push eax |
337 | push eax |
362 | push [recvd] |
338 | push [recvd] |
Line 363... | Line -... | ||
363 | - | ||
364 | push str7 |
339 | |
365 | call [con_printf] |
340 | invoke con_printf, str7 |
Line 366... | Line 341... | ||
366 | add esp, 5*4 |
341 | add esp, 5*4 |
Line 367... | Line 342... | ||
367 | 342 | ||
368 | jmp .continue |
- | |
369 | 343 | jmp .continue |
|
370 | - | ||
371 | .ttl_exceeded: |
344 | |
Line 372... | Line 345... | ||
372 | push str14 |
345 | |
373 | call [con_write_asciiz] |
346 | .ttl_exceeded: |
374 | 347 | invoke con_write_asciiz, str14 |
|
375 | jmp .continue |
348 | jmp .continue |
376 | - | ||
377 | 349 | ||
378 | ; Error in packet, print it to user |
350 | |
379 | .miscomp: |
351 | ; Error in packet, print it to user |
Line 380... | Line 352... | ||
380 | sub edi, icmp_packet.data+1 |
352 | .miscomp: |
381 | push edi |
353 | sub edi, icmp_packet.data+1 |
382 | push str9 |
- | |
383 | call [con_printf] |
354 | push edi |
384 | add esp, 2*4 |
355 | invoke con_printf, str9 |
Line 385... | Line 356... | ||
385 | jmp .continue |
356 | add esp, 2*4 |
386 | 357 | jmp .continue |
|
387 | ; Invalid reply |
- | |
388 | .invalid: |
358 | |
Line 389... | Line 359... | ||
389 | push str10 |
359 | ; Invalid reply |
390 | call [con_write_asciiz] |
360 | .invalid: |
391 | jmp .continue |
361 | invoke con_write_asciiz, str13 |
Line -... | Line 362... | ||
- | 362 | jmp .continue |
|
- | 363 | ||
- | 364 | ; Timeout! |
|
- | 365 | .no_response: |
|
- | 366 | invoke con_write_asciiz, str8 |
|
- | 367 | ||
- | 368 | ; Send more ICMP packets ? |
|
- | 369 | .continue: |
|
392 | 370 | inc [icmp_packet.seq] |
|
393 | ; Timeout! |
371 | |
394 | .no_response: |
372 | invoke con_kbhit |
395 | push str8 |
373 | test eax, eax |
396 | call [con_write_asciiz] |
374 | jz .nokey |
Line 425... | Line 403... | ||
425 | .zero: |
403 | .zero: |
426 | push edx |
404 | push edx |
427 | push eax |
405 | push eax |
428 | push [stats.rx] |
406 | push [stats.rx] |
429 | push [stats.tx] |
407 | push [stats.tx] |
430 | push str12 |
- | |
431 | call [con_printf] |
408 | invoke con_printf, str12 |
432 | add esp, 5*4 |
409 | add esp, 5*4 |
433 | jmp main |
410 | jmp main |
Line 434... | Line 411... | ||
434 | 411 | ||
435 | ; DNS error |
412 | ; DNS error |
436 | fail: |
- | |
437 | push str5 |
413 | fail: |
438 | call [con_write_asciiz] |
414 | invoke con_write_asciiz, str5 |
Line 439... | Line 415... | ||
439 | jmp main |
415 | jmp main |
440 | 416 | ||
441 | ; Socket error |
- | |
442 | fail2: |
417 | ; Socket error |
443 | push str6 |
418 | fail2: |
Line 444... | Line 419... | ||
444 | call [con_write_asciiz] |
419 | invoke con_write_asciiz, str6 |
445 | jmp main |
420 | jmp main |
446 | - | ||
447 | ; Finally.. exit! |
421 | |
448 | exit: |
422 | ; Finally.. exit! |
449 | push 1 |
423 | exit: |
Line 450... | Line 424... | ||
450 | call [con_exit] |
424 | invoke con_exit, 1 |
Line 485... | Line 459... | ||
485 | ; data |
459 | ; data |
486 | title db 'ICMP echo (ping) client',0 |
460 | title db 'ICMP echo (ping) client',0 |
487 | str_welcome db 'Please enter the hostname or IP-address of the host you want to ping,',10 |
461 | str_welcome db 'Please enter the hostname or IP-address of the host you want to ping,',10 |
488 | db 'or just press enter to exit.',10,10 |
462 | db 'or just press enter to exit.',10,10 |
489 | db 'Options:',10 |
463 | db 'Options:',10 |
490 | db ' -t Send packets till users abort.',10 |
464 | db ' -t Send packets till users abort. (Ctrl+C))',10 |
491 | db ' -n number Number of requests to send.',10 |
465 | db ' -n number Number of requests to send.',10 |
492 | db ' -i TTL Time to live.',10 |
466 | db ' -i TTL Time to live.',10 |
493 | db ' -l size Size of echo request.',10 |
467 | db ' -l size Size of echo request.',10 |
494 | db ' -w time-out Time-out in hundredths of a second.',10,0 |
468 | db ' -w time-out Time-out in hundredths of a second.',10,0 |
495 | str_prompt db 10,'> ',0 |
469 | str_prompt db 10,'> ',0 |
Line 548... | Line 522... | ||
548 | con_exit, 'con_exit', \ |
522 | con_exit, 'con_exit', \ |
549 | con_gets, 'con_gets',\ |
523 | con_gets, 'con_gets',\ |
550 | con_cls, 'con_cls',\ |
524 | con_cls, 'con_cls',\ |
551 | con_getch2, 'con_getch2',\ |
525 | con_getch2, 'con_getch2',\ |
552 | con_set_cursor_pos, 'con_set_cursor_pos',\ |
526 | con_set_cursor_pos, 'con_set_cursor_pos',\ |
553 | con_get_flags, 'con_get_flags' |
527 | con_get_flags, 'con_get_flags',\ |
- | 528 | con_kbhit, 'con_kbhit' |
|
Line 554... | Line 529... | ||
554 | 529 | ||
Line 555... | Line 530... | ||
555 | socketnum dd ? |
530 | socketnum dd ? |
556 | 531 |