Subversion Repositories Kolibri OS

Rev

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

Rev 2853 Rev 2872
Line -... Line 1...
-
 
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
2
;;                                                                 ;;
-
 
3
;; Copyright (C) KolibriOS team 2010-2012. All rights reserved.    ;;
-
 
4
;; Distributed under terms of the GNU General Public License       ;;
-
 
5
;;                                                                 ;;
-
 
6
;;  ping.asm - ICMP echo client for KolibriOS                      ;;
-
 
7
;;                                                                 ;;
-
 
8
;;  Written by hidnplayr@kolibrios.org                             ;;
-
 
9
;;                                                                 ;;
-
 
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
-
 
11
;;             Version 2, June 1991                                ;;
-
 
12
;;                                                                 ;;
-
 
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
14
 
Line 1... Line 15...
1
format binary as ""
15
 
Line 2... Line 16...
2
 
16
format binary as ""
3
use32
17
 
4
        org     0x0
-
 
-
 
18
use32
5
; standard header
19
        org     0x0
6
        db      'MENUET01'      ; signature
20
 
7
        dd      1               ; header version
21
        db      'MENUET01'      ; signature
8
        dd      start           ; entry point
22
        dd      1               ; header version
9
        dd      I_END           ; initialized size
23
        dd      start           ; entry point
10
        dd      mem             ; required memory
24
        dd      I_END           ; initialized size
11
        dd      mem             ; stack pointer
25
        dd      mem             ; required memory
12
        dd      0               ; parameters
26
        dd      mem             ; stack pointer
Line 13... Line 27...
13
        dd      0               ; path
27
        dd      s               ; parameters
14
 
28
        dd      0               ; path
15
 
29
 
16
BUFFERSIZE      equ 1500
30
 
17
; useful includes
31
BUFFERSIZE      equ 1500
18
include '../macros.inc'
32
; useful includes
19
purge mov,add,sub
-
 
20
include '../proc32.inc'
33
include '../macros.inc'
Line -... Line 34...
-
 
34
purge mov,add,sub
Line 21... Line -...
21
include '../dll.inc'
-
 
22
 
-
 
23
include '../network.inc'
-
 
24
 
-
 
25
 
-
 
26
 
-
 
27
; ICMP types & codes
-
 
28
 
-
 
29
ICMP_ECHOREPLY                  equ 0               ; echo reply message
-
 
30
 
-
 
31
ICMP_UNREACH                    equ 3
-
 
32
ICMP_UNREACH_NET                equ  0               ; bad net
-
 
33
ICMP_UNREACH_HOST               equ  1               ; bad host
-
 
34
ICMP_UNREACH_PROTOCOL           equ  2               ; bad protocol
-
 
35
ICMP_UNREACH_PORT               equ  3               ; bad port
-
 
36
ICMP_UNREACH_NEEDFRAG           equ  4               ; IP_DF caused drop
-
 
37
ICMP_UNREACH_SRCFAIL            equ  5               ; src route failed
-
 
38
ICMP_UNREACH_NET_UNKNOWN        equ  6               ; unknown net
-
 
39
ICMP_UNREACH_HOST_UNKNOWN       equ  7               ; unknown host
-
 
40
ICMP_UNREACH_ISOLATED           equ  8               ; src host isolated
-
 
41
ICMP_UNREACH_NET_PROHIB         equ  9               ; prohibited access
-
 
42
ICMP_UNREACH_HOST_PROHIB        equ 10              ; ditto
-
 
43
ICMP_UNREACH_TOSNET             equ 11              ; bad tos for net
-
 
44
ICMP_UNREACH_TOSHOST            equ 12              ; bad tos for host
-
 
45
ICMP_UNREACH_FILTER_PROHIB      equ 13              ; admin prohib
-
 
46
ICMP_UNREACH_HOST_PRECEDENCE    equ 14             ; host prec vio.
-
 
47
ICMP_UNREACH_PRECEDENCE_CUTOFF  equ 15           ; prec cutoff
-
 
48
 
-
 
49
ICMP_SOURCEQUENCH               equ 4               ; Packet lost, slow down
-
 
50
 
-
 
51
ICMP_REDIRECT                   equ 5               ; shorter route, codes:
-
 
52
ICMP_REDIRECT_NET               equ  0               ; for network
-
 
53
ICMP_REDIRECT_HOST              equ  1               ; for host
-
 
54
ICMP_REDIRECT_TOSNET            equ  2               ; for tos and net
-
 
55
ICMP_REDIRECT_TOSHOST           equ  3               ; for tos and host
-
 
56
 
-
 
57
ICMP_ALTHOSTADDR                equ 6               ; alternate host address
-
 
58
ICMP_ECHO                       equ  8               ; echo service
-
 
59
ICMP_ROUTERADVERT               equ  9               ; router advertisement
-
 
60
ICMP_ROUTERADVERT_NORMAL        equ  0                  ; normal advertisement
-
 
61
ICMP_ROUTERADVERT_NOROUTE_COMMON equ 16         ; selective routing
-
 
62
 
-
 
63
ICMP_ROUTERSOLICIT              equ 10              ; router solicitation
-
 
64
ICMP_TIMXCEED                   equ 11              ; time exceeded, code:
-
 
65
ICMP_TIMXCEED_INTRANS           equ 0               ; ttl==0 in transit
-
 
66
ICMP_TIMXCEED_REASS             equ 1               ; ttl==0 in reass
-
 
67
 
-
 
68
ICMP_PARAMPROB                  equ 12               ; ip header bad
-
 
69
ICMP_PARAMPROB_ERRATPTR         equ 0            ; error at param ptr
-
 
70
ICMP_PARAMPROB_OPTABSENT        equ 1            ; req. opt. absent
-
 
71
ICMP_PARAMPROB_LENGTH           equ 2            ; bad length
-
 
72
 
-
 
73
ICMP_TSTAMP                     equ 13              ; timestamp request
-
 
74
ICMP_TSTAMPREPLY                equ 14              ; timestamp reply
-
 
75
ICMP_IREQ                       equ 15              ; information request
-
 
76
ICMP_IREQREPLY                  equ 16              ; information reply
-
 
77
ICMP_MASKREQ                    equ 17              ; address mask request
-
 
78
ICMP_MASKREPLY                  equ 18              ; address mask reply
-
 
79
ICMP_TRACEROUTE                 equ 30              ; traceroute
-
 
80
ICMP_DATACONVERR                equ 31              ; data conversion error
-
 
81
ICMP_MOBILE_REDIRECT            equ 32              ; mobile host redirect
-
 
82
ICMP_IPV6_WHEREAREYOU           equ 33              ; IPv6 where-are-you
-
 
83
ICMP_IPV6_IAMHERE               equ 34              ; IPv6 i-am-here
-
 
84
ICMP_MOBILE_REGREQUEST          equ 35              ; mobile registration req
-
 
85
ICMP_MOBILE_REGREPLY            equ 36              ; mobile registreation reply
-
 
86
ICMP_SKIP                       equ 39              ; SKIP
-
 
87
 
-
 
88
ICMP_PHOTURIS                   equ 40              ; Photuris
-
 
89
ICMP_PHOTURIS_UNKNOWN_INDEX     equ 1                ; unknown sec index
-
 
90
ICMP_PHOTURIS_AUTH_FAILED       equ 2                ; auth failed
-
 
91
ICMP_PHOTURIS_DECRYPT_FAILED    equ 3                ; decrypt failed
-
 
92
 
-
 
93
 
-
 
94
 
-
 
95
virtual at 0
-
 
96
        ICMP_Packet:
-
 
97
        .Type           db   ?
-
 
98
        .Code           db   ?
-
 
99
        .Checksum       dw   ?
-
 
100
        .Identifier     dw   ?
-
 
101
        .SequenceNumber dw   ?
35
include '../proc32.inc'
102
        .Data:
36
include '../dll.inc'
103
end virtual
37
include '../network.inc'
104
 
38
 
105
 
39
include 'icmp.inc'
Line 118... Line 52...
118
        push    25
52
        push    80
119
        push    80
53
        push    25
120
        call    [con_init]
54
        push    80
121
; main loop
55
        call    [con_init]
122
        push    str1
56
; main loop
123
        call    [con_write_asciiz]
57
        cmp     byte[s], 0
124
main:
58
        jne     resolve
125
; write prompt
59
main:
126
        push    str2
60
; write prompt
127
        call    [con_write_asciiz]
61
        push    str2
128
; read string
62
        call    [con_write_asciiz]
129
        mov     esi, s
63
; read string
Line 142... Line 76...
142
        test    al, al
76
        lodsb
143
        jnz     @b
77
        test    al, al
144
        mov     byte [esi-2], al
78
        jnz     @b
145
        pop     esi
79
        mov     byte [esi-2], al
146
; resolve name
80
        pop     esi
-
 
81
 
-
 
82
resolve:
147
        push    esp     ; reserve stack place
83
; resolve name
148
        push    esp     ; fourth parameter
84
        push    esp     ; reserve stack place
149
        push    0       ; third parameter
85
        push    esp     ; fourth parameter
150
        push    0       ; second parameter
86
        push    0       ; third parameter
151
        push    esi     ; first parameter
87
        push    0       ; second parameter
152
        call    [getaddrinfo]
88
        push    s       ; first parameter
153
        pop     esi
89
        call    [getaddrinfo]
154
; test for error
90
        pop     esi
155
        test    eax, eax
91
; test for error
156
        jnz     fail
92
        test    eax, eax
157
 
93
        jnz     fail
Line 256... Line 192...
256
        jmp     done
192
        call    [con_write_asciiz]
257
 
193
        jmp     done
Line 258... Line 194...
258
 
194
 
259
; data
195
 
260
title   db      'ICMP - test application',0
-
 
261
str1    db      'ICMP test application v0.1',10,' for KolibriOS # 1540 or later. ',10,10,0
196
; data
262
str2    db      '> ',0
197
title   db      'ICMP - echo client',0
263
str3    db      'Ping to: ',0
198
str2    db      '> ',0
264
str4    db      10,0
199
str3    db      'Ping to ',0
265
str5    db      'Name resolution failed.',10,10,0
200
str4    db      10,0
266
str6    db      'Could not open socket',10,10,0
201
str5    db      'Name resolution failed.',10,0
267
str7    db      ' time= %u0ms',10,0
202
str6    db      'Could not open socket',10,0
268
str8    db      ' timeout!',10,0
203
str7    db      ' time= %u0ms',10,0
269
str9    db      ' miscompare at offset %u',10,0
204
str8    db      ' timeout!',10,0
Line 270... Line 205...
270
str10   db      10,10,'Press any key to exit',0
205
str9    db      ' miscompare at offset %u',10,0
271
 
206
str10   db      10,'Press any key to exit',0
272
sockaddr1:
207
 
273
        dw AF_INET4
208
sockaddr1:
Line 314... Line 249...
314
I_END:
249
 
Line 315... Line 250...
315
 
250
I_END:
Line 316... Line 251...
316
buffer_ptr      rb BUFFERSIZE
251
 
317
 
-
 
318
s       rb 256
252
buffer_ptr      rb BUFFERSIZE
319
align   4
253