Subversion Repositories Kolibri OS

Rev

Rev 3618 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3618 Rev 4012
Line 10... Line 10...
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;             Version 2, June 1991                                ;;
11
;;             Version 2, June 1991                                ;;
12
;;                                                                 ;;
12
;;                                                                 ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line -... Line 14...
-
 
14
 
-
 
15
; TODO: more precise timer, ttl, user selectable size/number of packets
14
 
16
 
Line 15... Line 17...
15
format binary as ""
17
format binary as ""
-
 
18
 
Line 16... Line 19...
16
 
19
BUFFERSIZE      = 1500
17
BUFFERSIZE      = 1500
20
IDENTIFIER      = 0x1337
Line 18... Line 21...
18
 
21
 
Line 120... Line 123...
120
        mcall   40, 1 shl 7 ; + 7
123
        mcall   40, 1 shl 7 ; + 7
121
;        call    [con_cls]
124
;        call    [con_cls]
Line 122... Line 125...
122
 
125
 
Line 123... Line -...
123
        mov     [count], 4
-
 
124
 
126
        mov     [count], 4
125
mainloop:
127
 
-
 
128
        push    str3
126
        push    str3
129
        call    [con_write_asciiz]
127
        call    [con_write_asciiz]
130
 
Line -... Line 131...
-
 
131
        push    [ip_ptr]
-
 
132
        call    [con_write_asciiz]
-
 
133
 
-
 
134
        push    (icmp_packet.length - ICMP_Packet.Data)
-
 
135
        push    str3b
-
 
136
        call    [con_printf]
128
        push    [ip_ptr]
137
 
129
        call    [con_write_asciiz]
138
mainloop:
130
 
139
        inc     [stats.tx]
Line 131... Line 140...
131
        mcall   26,9
140
        mcall   26,9
132
        mov     [time_reference], eax
141
        mov     [time_reference], eax
133
        mcall   send, [socketnum], icmp_packet, icmp_packet.length, 0
142
        mcall   send, [socketnum], icmp_packet, icmp_packet.length, 0
134
 
143
 
Line 135... Line 144...
135
        mcall   23, 300 ; 3 seconds time-out
144
        mcall   23, 300 ; 3 seconds time-out
136
        mcall   26,9
145
        mcall   26,9
137
        neg     [time_reference]
146
        neg     [time_reference]
Line -... Line 147...
-
 
147
        add     [time_reference], eax
-
 
148
 
-
 
149
        mcall   recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT
-
 
150
        cmp     eax, -1
-
 
151
        je      .no_response
-
 
152
 
-
 
153
        sub     eax, ICMP_Packet.Data
-
 
154
        jb      .no_response            ; FIXME: use other error message?
-
 
155
        mov     [recvd], eax
-
 
156
 
-
 
157
        cmp     word[buffer_ptr + ICMP_Packet.Identifier], IDENTIFIER
-
 
158
        jne     .no_response            ; FIXME: use other error message?
-
 
159
 
-
 
160
; OK, we have a response, update stats and let the user know
-
 
161
        inc     [stats.rx]
138
        add     [time_reference], eax
162
        mov     eax, [time_reference]
139
 
163
        add     [stats.time], eax
-
 
164
 
140
        mcall   recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
165
        push    str11                   ; TODO: print IP address of packet sender
141
        cmp     eax, -1
-
 
142
        je      .no_response
166
        call    [con_write_asciiz]
143
 
167
 
Line -... Line 168...
-
 
168
; validate the packet
144
; validate the packet
169
        lea     esi, [buffer_ptr + ICMP_Packet.Data]
-
 
170
        mov     ecx, [recvd]
-
 
171
        mov     edi, icmp_packet.data
-
 
172
        repe    cmpsb
-
 
173
        jne     .miscomp
145
        lea     esi, [buffer_ptr + ICMP_Packet.Data]
174
 
146
        mov     edi, icmp_packet.data
175
; All OK, print to the user!
Line 147... Line 176...
147
        mov     ecx, 32/4
176
        push    [time_reference]
Line -... Line 177...
-
 
177
        movzx   eax, word[buffer_ptr + ICMP_Packet.SequenceNumber]
148
        repe    cmpsd
178
        push    eax
149
        jne     .miscomp
179
        push    [recvd]
150
 
180
 
151
        push    [time_reference]
181
        push    str7
152
        push    str7
182
        call    [con_printf]
153
        call    [con_printf]
183
 
Line -... Line 184...
-
 
184
        jmp     continue
154
 
185
 
155
        jmp     continue
186
; Error in packet, print it to user
156
 
187
  .miscomp:
Line -... Line 188...
-
 
188
        sub     edi, icmp_packet.data
157
  .miscomp:
189
        push    edi
158
        sub     edi, icmp_packet.data
190
        push    str9
159
        push    edi
191
        call    [con_printf]
160
        push    str9
-
 
161
        call    [con_printf]
-
 
162
        jmp     continue
-
 
Line -... Line 192...
-
 
192
        jmp     continue
Line -... Line 193...
-
 
193
 
-
 
194
; Timeout!
Line -... Line 195...
-
 
195
  .no_response:
163
 
196
        push    str8
-
 
197
        call    [con_write_asciiz]
-
 
198
 
-
 
199
; Send more ICMP packets ?
-
 
200
   continue:
-
 
201
        dec     [count]
-
 
202
        jz      done
-
 
203
 
-
 
204
        mcall   5, 100  ; wait a second
-
 
205
 
164
  .no_response:
206
        inc     [icmp_packet.seq]
165
        push    str8
207
        jmp     mainloop
166
        call    [con_write_asciiz]
208
 
167
 
209
; Done..
168
   continue:
210
done:
-
 
211
        xor     edx, edx
-
 
212
        mov     eax, [stats.time]
169
        dec     [count]
213
        div     [stats.rx]
170
        jz      done
214
        push    eax
Line -... Line 215...
-
 
215
        push    [stats.rx]
171
        mcall   5, 100  ; wait a second
216
        push    [stats.tx]
172
        inc     [icmp_packet.id]
217
        push    str12
173
        jmp     mainloop
218
        call    [con_printf]
174
 
219
 
-
 
220
        push    str10
-
 
221
        call    [con_write_asciiz]
175
 
222
        call    [con_getch2]
176
 
223
        push    1
177
done:
224
        call    [con_exit]
178
        push    str10
225
 
Line 179... Line 226...
179
        call    [con_write_asciiz]
226
; Finally.. exit!
180
        call    [con_getch2]
227
exit:
181
        push    1
228
        mcall   -1
182
        call    [con_exit]
229
 
-
 
230
; DNS error
-
 
231
fail:
183
exit:
232
        push    str5
184
        mcall   -1
233
        call    [con_write_asciiz]
185
 
234
        jmp     done
-
 
235
 
-
 
236
; Socket error
186
fail:
237
fail2:
187
        push    str5
238
        push    str6
188
        call    [con_write_asciiz]
239
        call    [con_write_asciiz]
189
        jmp     done
240
        jmp     done
Line -... Line 241...
-
 
241
 
-
 
242
 
190
fail2:
243
; data
191
        push    str6
244
title   db      'ICMP - echo client',0
192
        call    [con_write_asciiz]
245
str2    db      '> ',0
193
        jmp     done
246
str3    db      'Pinging to ',0
194
 
247
str3b   db      ' with %u data bytes',10,0
Line 195... Line 248...
195
 
248
 
196
; data
249
str4    db      10,0
197
title   db      'ICMP - echo client',0
250
str5    db      'Name resolution failed.',10,0
-
 
251
str6    db      'Could not open socket',10,0
Line -... Line 252...
-
 
252
 
-
 
253
str11   db      'Answer: ',0
-
 
254
str7    db      'bytes=%u seq=%u time=%u0 ms',10,0
-
 
255
str8    db      'timeout!',10,0
Line 198... Line 256...
198
str2    db      '> ',0
256
str9    db      'miscompare at offset %u',10,0
199
str3    db      'Ping to ',0
257
str10   db      10,'Press any key to exit',0
200
str4    db      10,0
258
 
Line 240... Line 298...
240
socketnum       dd ?
298
socketnum       dd ?
Line 241... Line 299...
241
 
299
 
242
icmp_packet:    db 8            ; type
300
icmp_packet:    db 8            ; type
243
                db 0            ; code
301
                db 0            ; code
244
                dw 0            ;
302
                dw 0            ;
245
 .id            dw 0x0000       ; identifier
303
 .id            dw IDENTIFIER   ; identifier
246
 .seq           dw 0x0001       ; sequence number
304
 .seq           dw 0x0000       ; sequence number
247
 .data          db 'abcdefghijklmnopqrstuvwxyz012345678'
305
 .data          db 'abcdefghijklmnopqrstuvwxyz012345'
Line 248... Line 306...
248
 .length = $ - icmp_packet
306
 .length = $ - icmp_packet
Line 249... Line 307...
249
 
307