Rev 6477 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6477 | Rev 7891 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2010-2020. 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 12... | Line 12... | ||
12 | ;; ;; |
12 | ;; ;; |
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 14... | Line 14... | ||
14 | 14 | ||
Line 15... | Line 15... | ||
15 | format binary as "" |
15 | format binary as "" |
16 | - | ||
Line 17... | Line 16... | ||
17 | BUFFERSIZE = 1500 |
16 | |
18 | IDENTIFIER = 0x1337 |
17 | BUFFERSIZE = 65536 |
Line 19... | Line 18... | ||
19 | 18 | ||
Line 56... | Line 55... | ||
56 | push 250 |
55 | push 250 |
57 | push 80 |
56 | push 80 |
58 | push 25 |
57 | push 25 |
59 | push 80 |
58 | push 80 |
60 | call [con_init] |
59 | call [con_init] |
- | 60 | ; Init identifier with our PID number |
|
- | 61 | mcall 9, thread_info, -1 |
|
- | 62 | mov eax, [thread_info.PID] |
|
- | 63 | mov [icmp_packet.id], ax |
|
61 | ; expand payload to 65504 bytes |
64 | ; expand payload to 65504 bytes |
62 | mov edi, icmp_packet.data+32 |
65 | mov edi, icmp_packet.data+32 |
63 | mov ecx, 65504/32-1 |
66 | mov ecx, 65504/32-1 |
64 | .expand_payload: |
67 | .expand_payload: |
65 | mov esi, icmp_packet.data |
68 | mov esi, icmp_packet.data |
Line 259... | Line 262... | ||
259 | xor edi, edi |
262 | xor edi, edi |
260 | mcall send, [socketnum], icmp_packet |
263 | mcall send, [socketnum], icmp_packet |
261 | cmp eax, -1 |
264 | cmp eax, -1 |
262 | je fail2 |
265 | je fail2 |
Line -... | Line 266... | ||
- | 266 | ||
- | 267 | mov [time_exceeded], 0 |
|
263 | 268 | .receiveloop: |
|
- | 269 | mov ebx, [timeout] |
|
- | 270 | sub ebx, [time_exceeded] |
|
- | 271 | jb .no_response |
|
- | 272 | mcall 23 ; Wait for network event with timeout |
|
264 | mcall 23, [timeout] |
273 | |
265 | mcall 26, 10 ; Get high precision timer count |
274 | mcall 26, 10 ; Get high precision timer count |
266 | sub eax, [time_reference] |
275 | sub eax, [time_reference] |
267 | jz @f |
276 | jz @f |
268 | xor edx, edx |
277 | xor edx, edx |
269 | mov ebx, 100000 |
278 | mov ebx, 100000 |
270 | div ebx |
279 | div ebx |
271 | cmp edx, 50000 |
280 | cmp edx, 50000 |
272 | jb @f |
281 | jb @f |
273 | inc eax |
282 | inc eax |
274 | @@: |
283 | @@: |
Line 275... | Line 284... | ||
275 | mov [time_reference], eax |
284 | mov [time_exceeded], eax ; Exceeded time in 1/100 s |
276 | 285 | ||
277 | ; Receive reply |
286 | ; Receive reply |
278 | mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT |
287 | mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT |
Line 293... | Line 302... | ||
293 | mov [recvd], eax |
302 | mov [recvd], eax |
Line 294... | Line 303... | ||
294 | 303 | ||
295 | ; make esi point to ICMP packet header |
304 | ; make esi point to ICMP packet header |
Line -... | Line 305... | ||
- | 305 | add esi, buffer_ptr |
|
- | 306 | ||
- | 307 | ; Check identifier |
|
- | 308 | mov ax, [icmp_packet.id] |
|
- | 309 | cmp [esi + ICMP_header.Identifier], ax |
|
296 | add esi, buffer_ptr |
310 | jne .receiveloop |
297 | 311 | ||
298 | ; we have a response, print the sender IP |
312 | ; we have a response, print the sender IP |
299 | push esi |
313 | push esi |
300 | mov eax, [buffer_ptr + IPv4_header.SourceAddress] |
314 | mov eax, [buffer_ptr + IPv4_header.SourceAddress] |
Line 322... | Line 336... | ||
322 | jmp .invalid |
336 | jmp .invalid |
Line 323... | Line 337... | ||
323 | 337 | ||
Line 324... | Line -... | ||
324 | - | ||
325 | .echo_reply: |
- | |
326 | - | ||
327 | cmp [esi + ICMP_header.Identifier], IDENTIFIER |
338 | |
328 | jne .invalid |
339 | .echo_reply: |
329 | 340 | ||
330 | ; Validate the packet |
341 | ; Validate the payload |
331 | add esi, sizeof.ICMP_header |
342 | add esi, sizeof.ICMP_header |
332 | mov ecx, [size] |
343 | mov ecx, [size] |
Line 333... | Line 344... | ||
333 | mov edi, icmp_packet.data |
344 | mov edi, icmp_packet.data |
334 | repe cmpsb |
345 | repe cmpsb |
335 | jne .miscomp |
346 | jne .miscomp |
336 | 347 | ||
Line -... | Line 348... | ||
- | 348 | ; update stats |
|
337 | ; update stats |
349 | inc [stats.rx] |
338 | inc [stats.rx] |
350 | mov eax, [time_exceeded] |
339 | mov eax, [time_reference] |
351 | add [stats.time], eax |
340 | add [stats.time], eax |
352 | |
341 | 353 | ; Print time exceeded |
|
342 | movzx eax, [buffer_ptr + IPv4_header.TimeToLive] |
354 | movzx eax, [buffer_ptr + IPv4_header.TimeToLive] |
343 | push eax |
355 | push eax |
344 | mov eax, [time_reference] |
356 | mov eax, [time_exceeded] |
Line 502... | Line 514... | ||
502 | dw AF_INET4 |
514 | dw AF_INET4 |
503 | .port dw 0 |
515 | .port dw 0 |
504 | .ip dd 0 |
516 | .ip dd 0 |
505 | rb 10 |
517 | rb 10 |
Line 506... | Line 518... | ||
506 | 518 | ||
- | 519 | time_reference dd ? ; start time of sent packet |
|
507 | time_reference dd ? |
520 | time_exceeded dd ? ; time exceeded between send and receive |
508 | ip_ptr dd ? |
521 | ip_ptr dd ? |
509 | count dd ? |
522 | count dd ? |
510 | size dd ? |
523 | size dd ? |
511 | ttl dd ? |
524 | ttl dd ? |
Line 542... | Line 555... | ||
542 | socketnum dd ? |
555 | socketnum dd ? |
Line 543... | Line 556... | ||
543 | 556 | ||
544 | icmp_packet db ICMP_ECHO ; type |
557 | icmp_packet db ICMP_ECHO ; type |
545 | db 0 ; code |
558 | db 0 ; code |
546 | dw 0 ; checksum |
559 | dw 0 ; checksum |
547 | .id dw IDENTIFIER ; identifier |
560 | .id dw 0 ; identifier |
548 | .seq dw 0x0000 ; sequence number |
561 | .seq dw 0x0000 ; sequence number |
Line 549... | Line 562... | ||
549 | .data db 'abcdefghijklmnopqrstuvwxyz012345' |
562 | .data db 'abcdefghijklmnopqrstuvwxyz012345' |
550 | 563 | ||
Line -... | Line 564... | ||
- | 564 | I_END: |
|
- | 565 | rb 65504-32 |
|
551 | I_END: |
566 | |
552 | rb 65504-32 |
567 | thread_info process_information |
Line 553... | Line 568... | ||
553 | 568 |