Subversion Repositories Kolibri OS

Rev

Rev 7892 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7892 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
;;  tracert.asm - Trace network route for KolibriOS                ;;
6
;;  tracert.asm - Trace network route for KolibriOS                ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;  Written by hidnplayr@kolibrios.org                             ;;
8
;;  Written by hidnplayr@kolibrios.org                             ;;
Line 52... Line 52...
52
; load libraries
52
; load libraries
53
        stdcall dll.Load, @IMPORT
53
        stdcall dll.Load, @IMPORT
54
        test    eax, eax
54
        test    eax, eax
55
        jnz     exit
55
        jnz     exit
56
; initialize console
56
; initialize console
57
        push    1
-
 
58
        call    [con_start]
57
        invoke  con_start, 1
59
        push    title
-
 
60
        push    250
-
 
61
        push    80
-
 
62
        push    25
-
 
63
        push    80
-
 
64
        call    [con_init]
58
        invoke  con_init, 80, 25, 80, 250, title
65
; main loop
59
; main loop
66
        cmp     byte[params], 0
60
        cmp     byte[params], 0
67
        jne     parse_param
61
        jne     parse_param
Line 68... Line -...
68
 
-
 
69
        push    str_welcome
62
 
70
        call    [con_write_asciiz]
63
        invoke  con_write_asciiz, str_welcome
71
main:
64
main:
72
; write prompt
-
 
73
        push    str_prompt
65
; write prompt
74
        call    [con_write_asciiz]
66
        invoke  con_write_asciiz, str_prompt
75
; read string
67
; read string
76
        mov     esi, params
-
 
77
        push    1024
-
 
78
        push    esi
68
        mov     esi, params
79
        call    [con_gets]
69
        invoke  con_gets, esi, 1024
80
; check for exit
70
; check for exit
81
        test    eax, eax
71
        test    eax, eax
82
        jz      exit
72
        jz      exit
83
        cmp     byte [esi], 10
73
        cmp     byte [esi], 10
Line 117... Line 107...
117
        cmp     al, '-'
107
        cmp     al, '-'
118
        jne     .invalid
108
        jne     .invalid
119
        lodsb
109
        lodsb
120
        ; implement more parameters here
110
        ; implement more parameters here
121
  .invalid:
111
  .invalid:
122
        push    str13
-
 
123
        call    [con_write_asciiz]
112
        invoke  con_write_asciiz, str13
124
        jmp     main
113
        jmp     main
Line 125... Line 114...
125
 
114
 
126
  .resolve:
115
  .resolve:
127
        DEBUGF  2, "resolve\n"
116
        DEBUGF  2, "resolve\n"
128
; resolve name
117
; resolve name
129
        push    esp     ; reserve stack place
-
 
130
        push    esp     ; fourth parameter
-
 
131
        push    0       ; third parameter
-
 
132
        push    0       ; second parameter
-
 
133
        push    params  ; first parameter
118
        push    esp     ; reserve stack place
134
        call    [getaddrinfo]
119
        invoke  getaddrinfo, params, 0, 0, esp
135
        pop     esi
120
        pop     esi
136
; test for error
121
; test for error
137
        test    eax, eax
122
        test    eax, eax
Line 138... Line 123...
138
        jnz     fail
123
        jnz     fail
139
 
124
 
140
; convert IP address to decimal notation
125
; convert IP address to decimal notation
141
        mov     eax, [esi+addrinfo.ai_addr]
126
        mov     eax, [esi+addrinfo.ai_addr]
142
        mov     eax, [eax+sockaddr_in.sin_addr]
-
 
143
        mov     [sockaddr1.ip], eax
127
        mov     eax, [eax+sockaddr_in.sin_addr]
144
        push    eax
128
        mov     [sockaddr1.ip], eax
145
        call    [inet_ntoa]
129
        invoke  inet_ntoa
Line 146... Line 130...
146
; write result
130
; write result
Line 147... Line 131...
147
        mov     [ip_ptr], eax
131
        mov     [ip_ptr], eax
148
 
-
 
149
        push    eax
132
 
Line 150... Line -...
150
 
-
 
151
; free allocated memory
133
        push    eax
Line 152... Line 134...
152
        push    esi
134
 
153
        call    [freeaddrinfo]
135
; free allocated memory
154
 
136
        invoke  freeaddrinfo, esi
155
        push    str4
137
 
Line 169... Line 151...
169
        cmp     eax, -1
151
        cmp     eax, -1
170
        je      fail2
152
        je      fail2
Line 171... Line 153...
171
 
153
 
Line 172... Line -...
172
        mcall   40, EVM_STACK
-
 
173
 
154
        mcall   40, EVM_STACK
174
        push    str3
-
 
175
        call    [con_write_asciiz]
-
 
176
 
155
 
177
        push    [ip_ptr]
-
 
178
        call    [con_write_asciiz]
-
 
179
 
156
        invoke  con_write_asciiz, str3
Line 180... Line 157...
180
        push    str4
157
        invoke  con_write_asciiz, [ip_ptr]
Line 181... Line 158...
181
        call    [con_write_asciiz]
158
        invoke  con_write_asciiz, str4
Line 182... Line 159...
182
 
159
 
Line 183... Line 160...
183
        mov     [ttl], 1
160
        mov     [ttl], 1
184
 
161
 
185
 ;;       mcall   send, [udp_socket], udp_packet, 5, 0    ; dummy send
162
 ;;       mcall   send, [udp_socket], udp_packet, 5, 0    ; dummy send
186
 
163
 
Line -... Line 164...
-
 
164
        mcall   recv, [icmp_socket], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT ;; dummy read
-
 
165
 
-
 
166
mainloop:
-
 
167
        invoke  con_get_flags
-
 
168
        test    eax, 0x200                      ; con window closed?
-
 
169
        jnz     exit_now
-
 
170
 
-
 
171
        invoke  con_kbhit
187
        mcall   recv, [icmp_socket], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT ;; dummy read
172
        test    eax, eax
188
 
-
 
189
mainloop:
173
        jz      .nokey
190
        call    [con_get_flags]
174
        invoke  con_getch2
Line 191... Line 175...
191
        test    eax, 0x200                      ; con window closed?
175
        cmp     ax, 0x1E03      ; Ctrl+C
Line 192... Line 176...
192
        jnz     exit_now
176
        je      main
Line 283... Line 267...
283
        mov     ebx, 10
267
        mov     ebx, 10
284
        div     ebx
268
        div     ebx
285
        push    edx
269
        push    edx
286
        push    eax
270
        push    eax
Line 287... Line -...
287
 
-
 
288
        push    str1
271
 
289
        call    [con_printf]
272
        invoke  con_printf, str1
Line 290... Line 273...
290
        add     esp, 3*4
273
        add     esp, 3*4
291
 
274
 
292
        mov     ebx, [buffer_ptr + IPv4_header.SourceAddress]
275
        mov     ebx, [buffer_ptr + IPv4_header.SourceAddress]
Line 303... Line 286...
303
        movzx   ebx, ah
286
        movzx   ebx, ah
304
        push    ebx
287
        push    ebx
305
        movzx   ebx, al
288
        movzx   ebx, al
306
        push    ebx
289
        push    ebx
Line 307... Line -...
307
 
-
 
308
        push    str2
290
 
309
        call    [con_printf]
291
        invoke  con_printf, str2
Line 310... Line 292...
310
        add     esp, 5*4
292
        add     esp, 5*4
Line 311... Line 293...
311
 
293
 
312
        ret
294
        ret
313
 
295
 
314
 
-
 
315
; Invalid reply
296
 
316
  .invalid:
297
; Invalid reply
Line 317... Line 298...
317
        DEBUGF  2, "Invalid response\n"
298
  .invalid:
318
        push    str10
299
        DEBUGF  2, "Invalid response\n"
319
        call    [con_write_asciiz]
300
        invoke  con_write_asciiz, str10
320
        jmp     main    ;.continue
-
 
321
 
301
        jmp     main    ;.continue
Line 322... Line 302...
322
; Timeout!
302
 
323
  .timeout:
303
; Timeout!
324
        DEBUGF  2, "Timeout\n", eax
304
  .timeout:
Line 333... Line 313...
333
        mcall   5, 100
313
        mcall   5, 100
334
        jmp     mainloop
314
        jmp     mainloop
Line 335... Line 315...
335
 
315
 
336
; DNS error
316
; DNS error
337
fail:
-
 
338
        push    str5
317
fail:
339
        call    [con_write_asciiz]
318
        invoke  con_write_asciiz, str5
Line 340... Line 319...
340
        jmp     main
319
        jmp     main
341
 
320
 
342
; Socket error
-
 
343
fail2:
321
; Socket error
344
        push    str6
322
fail2:
Line 345... Line 323...
345
        call    [con_write_asciiz]
323
        invoke  con_write_asciiz, str6
346
        jmp     main
324
        jmp     main
347
 
-
 
348
; Finally.. exit!
325
 
349
exit:
326
; Finally.. exit!
350
        push    1
327
exit:
Line 351... Line 328...
351
        call    [con_exit]
328
        invoke  con_exit, 1
Line 448... Line 425...
448
        stosb
425
        stosb
449
        jmp     @r
426
        jmp     @r
450
  @@:
427
  @@:
451
        stosb
428
        stosb
Line 452... Line -...
452
 
-
 
453
        push    buffer_ptr
429
 
454
        call    [con_write_asciiz]
-
 
455
 
-
 
456
        push    str7
430
        invoke  con_write_asciiz, buffer_ptr
457
        call    [con_write_asciiz]
-
 
458
 
431
        invoke  con_write_asciiz, str7
Line 459... Line 432...
459
        ret
432
        ret
460
 
433
 
Line 559... Line 532...
559
        con_exit,       'con_exit',     \
532
        con_exit,       'con_exit',     \
560
        con_gets,       'con_gets',\
533
        con_gets,       'con_gets',\
561
        con_cls,        'con_cls',\
534
        con_cls,        'con_cls',\
562
        con_getch2,     'con_getch2',\
535
        con_getch2,     'con_getch2',\
563
        con_set_cursor_pos, 'con_set_cursor_pos',\
536
        con_set_cursor_pos, 'con_set_cursor_pos',\
564
        con_get_flags,  'con_get_flags'
537
        con_get_flags,  'con_get_flags',\
-
 
538
        con_kbhit,      'con_kbhit'
Line 565... Line 539...
565
 
539
 
566
import  network,        \
540
import  network,        \
567
        getaddrinfo,    'getaddrinfo',  \
541
        getaddrinfo,    'getaddrinfo',  \
568
        freeaddrinfo,   'freeaddrinfo', \
542
        freeaddrinfo,   'freeaddrinfo', \