Subversion Repositories Kolibri OS

Rev

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

Rev 2314 Rev 2853
Line -... Line 1...
-
 
1
format binary as ""
-
 
2
 
-
 
3
use32
1
use32
4
        org     0x0
2
	org	0x0
5
; standard header
3
; standard header
6
        db      'MENUET01'      ; signature
4
	db	'MENUET01'	; signature
7
        dd      1               ; header version
5
	dd	1		; header version
8
        dd      start           ; entry point
6
	dd	start		; entry point
9
        dd      I_END           ; initialized size
7
	dd	I_END		; initialized size
10
        dd      mem             ; required memory
8
	dd	mem		; required memory
11
        dd      mem             ; stack pointer
9
	dd	mem		; stack pointer
12
        dd      0               ; parameters
10
	dd	0		; parameters
13
        dd      0               ; path
11
	dd	0		; path
14
 
Line 12... Line 15...
12
 
15
 
13
 
16
BUFFERSIZE      equ 1500
14
BUFFERSIZE	equ 1500
17
; useful includes
15
; useful includes
18
include '../macros.inc'
16
include '../macros.inc'
19
purge mov,add,sub
17
purge mov,add,sub
20
include '../proc32.inc'
Line 22... Line 25...
22
 
25
 
Line 23... Line 26...
23
 
26
 
Line 24... Line 27...
24
 
27
; ICMP types & codes
25
; ICMP types & codes
28
 
26
 
29
ICMP_ECHOREPLY                  equ 0               ; echo reply message
27
ICMP_ECHOREPLY			equ 0		    ; echo reply message
30
 
28
 
31
ICMP_UNREACH                    equ 3
29
ICMP_UNREACH			equ 3
32
ICMP_UNREACH_NET                equ  0               ; bad net
30
ICMP_UNREACH_NET		equ  0		     ; bad net
33
ICMP_UNREACH_HOST               equ  1               ; bad host
31
ICMP_UNREACH_HOST		equ  1		     ; bad host
34
ICMP_UNREACH_PROTOCOL           equ  2               ; bad protocol
32
ICMP_UNREACH_PROTOCOL		equ  2		     ; bad protocol
35
ICMP_UNREACH_PORT               equ  3               ; bad port
33
ICMP_UNREACH_PORT		equ  3		     ; bad port
36
ICMP_UNREACH_NEEDFRAG           equ  4               ; IP_DF caused drop
34
ICMP_UNREACH_NEEDFRAG		equ  4		     ; IP_DF caused drop
37
ICMP_UNREACH_SRCFAIL            equ  5               ; src route failed
35
ICMP_UNREACH_SRCFAIL		equ  5		     ; src route failed
38
ICMP_UNREACH_NET_UNKNOWN        equ  6               ; unknown net
36
ICMP_UNREACH_NET_UNKNOWN	equ  6		     ; unknown net
39
ICMP_UNREACH_HOST_UNKNOWN       equ  7               ; unknown host
37
ICMP_UNREACH_HOST_UNKNOWN	equ  7		     ; unknown host
40
ICMP_UNREACH_ISOLATED           equ  8               ; src host isolated
38
ICMP_UNREACH_ISOLATED		equ  8		     ; src host isolated
41
ICMP_UNREACH_NET_PROHIB         equ  9               ; prohibited access
39
ICMP_UNREACH_NET_PROHIB 	equ  9		     ; prohibited access
42
ICMP_UNREACH_HOST_PROHIB        equ 10              ; ditto
40
ICMP_UNREACH_HOST_PROHIB	equ 10		    ; ditto
43
ICMP_UNREACH_TOSNET             equ 11              ; bad tos for net
41
ICMP_UNREACH_TOSNET		equ 11		    ; bad tos for net
44
ICMP_UNREACH_TOSHOST            equ 12              ; bad tos for host
42
ICMP_UNREACH_TOSHOST		equ 12		    ; bad tos for host
45
ICMP_UNREACH_FILTER_PROHIB      equ 13              ; admin prohib
43
ICMP_UNREACH_FILTER_PROHIB	equ 13		    ; admin prohib
46
ICMP_UNREACH_HOST_PRECEDENCE    equ 14             ; host prec vio.
44
ICMP_UNREACH_HOST_PRECEDENCE	equ 14		   ; host prec vio.
47
ICMP_UNREACH_PRECEDENCE_CUTOFF  equ 15           ; prec cutoff
45
ICMP_UNREACH_PRECEDENCE_CUTOFF	equ 15		 ; prec cutoff
48
 
46
 
49
ICMP_SOURCEQUENCH               equ 4               ; Packet lost, slow down
47
ICMP_SOURCEQUENCH		equ 4		    ; Packet lost, slow down
50
 
48
 
51
ICMP_REDIRECT                   equ 5               ; shorter route, codes:
49
ICMP_REDIRECT			equ 5		    ; shorter route, codes:
52
ICMP_REDIRECT_NET               equ  0               ; for network
50
ICMP_REDIRECT_NET		equ  0		     ; for network
53
ICMP_REDIRECT_HOST              equ  1               ; for host
51
ICMP_REDIRECT_HOST		equ  1		     ; for host
54
ICMP_REDIRECT_TOSNET            equ  2               ; for tos and net
52
ICMP_REDIRECT_TOSNET		equ  2		     ; for tos and net
55
ICMP_REDIRECT_TOSHOST           equ  3               ; for tos and host
53
ICMP_REDIRECT_TOSHOST		equ  3		     ; for tos and host
56
 
54
 
57
ICMP_ALTHOSTADDR                equ 6               ; alternate host address
55
ICMP_ALTHOSTADDR		equ 6		    ; alternate host address
58
ICMP_ECHO                       equ  8               ; echo service
56
ICMP_ECHO			equ  8		     ; echo service
59
ICMP_ROUTERADVERT               equ  9               ; router advertisement
57
ICMP_ROUTERADVERT		equ  9		     ; router advertisement
60
ICMP_ROUTERADVERT_NORMAL        equ  0                  ; normal advertisement
58
ICMP_ROUTERADVERT_NORMAL	equ  0			; normal advertisement
61
ICMP_ROUTERADVERT_NOROUTE_COMMON equ 16         ; selective routing
59
ICMP_ROUTERADVERT_NOROUTE_COMMON equ 16 	; selective routing
62
 
60
 
63
ICMP_ROUTERSOLICIT              equ 10              ; router solicitation
61
ICMP_ROUTERSOLICIT		equ 10		    ; router solicitation
64
ICMP_TIMXCEED                   equ 11              ; time exceeded, code:
62
ICMP_TIMXCEED			equ 11		    ; time exceeded, code:
65
ICMP_TIMXCEED_INTRANS           equ 0               ; ttl==0 in transit
63
ICMP_TIMXCEED_INTRANS		equ 0		    ; ttl==0 in transit
66
ICMP_TIMXCEED_REASS             equ 1               ; ttl==0 in reass
64
ICMP_TIMXCEED_REASS		equ 1		    ; ttl==0 in reass
67
 
65
 
68
ICMP_PARAMPROB                  equ 12               ; ip header bad
66
ICMP_PARAMPROB			equ 12		     ; ip header bad
69
ICMP_PARAMPROB_ERRATPTR         equ 0            ; error at param ptr
67
ICMP_PARAMPROB_ERRATPTR 	equ 0		 ; error at param ptr
70
ICMP_PARAMPROB_OPTABSENT        equ 1            ; req. opt. absent
68
ICMP_PARAMPROB_OPTABSENT	equ 1		 ; req. opt. absent
71
ICMP_PARAMPROB_LENGTH           equ 2            ; bad length
69
ICMP_PARAMPROB_LENGTH		equ 2		 ; bad length
72
 
70
 
73
ICMP_TSTAMP                     equ 13              ; timestamp request
71
ICMP_TSTAMP			equ 13		    ; timestamp request
74
ICMP_TSTAMPREPLY                equ 14              ; timestamp reply
72
ICMP_TSTAMPREPLY		equ 14		    ; timestamp reply
75
ICMP_IREQ                       equ 15              ; information request
73
ICMP_IREQ			equ 15		    ; information request
76
ICMP_IREQREPLY                  equ 16              ; information reply
74
ICMP_IREQREPLY			equ 16		    ; information reply
77
ICMP_MASKREQ                    equ 17              ; address mask request
75
ICMP_MASKREQ			equ 17		    ; address mask request
78
ICMP_MASKREPLY                  equ 18              ; address mask reply
76
ICMP_MASKREPLY			equ 18		    ; address mask reply
79
ICMP_TRACEROUTE                 equ 30              ; traceroute
77
ICMP_TRACEROUTE 		equ 30		    ; traceroute
80
ICMP_DATACONVERR                equ 31              ; data conversion error
78
ICMP_DATACONVERR		equ 31		    ; data conversion error
81
ICMP_MOBILE_REDIRECT            equ 32              ; mobile host redirect
79
ICMP_MOBILE_REDIRECT		equ 32		    ; mobile host redirect
82
ICMP_IPV6_WHEREAREYOU           equ 33              ; IPv6 where-are-you
80
ICMP_IPV6_WHEREAREYOU		equ 33		    ; IPv6 where-are-you
83
ICMP_IPV6_IAMHERE               equ 34              ; IPv6 i-am-here
81
ICMP_IPV6_IAMHERE		equ 34		    ; IPv6 i-am-here
84
ICMP_MOBILE_REGREQUEST          equ 35              ; mobile registration req
82
ICMP_MOBILE_REGREQUEST		equ 35		    ; mobile registration req
85
ICMP_MOBILE_REGREPLY            equ 36              ; mobile registreation reply
83
ICMP_MOBILE_REGREPLY		equ 36		    ; mobile registreation reply
86
ICMP_SKIP                       equ 39              ; SKIP
84
ICMP_SKIP			equ 39		    ; SKIP
87
 
Line 85... Line 88...
85
 
88
ICMP_PHOTURIS                   equ 40              ; Photuris
86
ICMP_PHOTURIS			equ 40		    ; Photuris
89
ICMP_PHOTURIS_UNKNOWN_INDEX     equ 1                ; unknown sec index
87
ICMP_PHOTURIS_UNKNOWN_INDEX	equ 1		     ; unknown sec index
90
ICMP_PHOTURIS_AUTH_FAILED       equ 2                ; auth failed
88
ICMP_PHOTURIS_AUTH_FAILED	equ 2		     ; auth failed
91
ICMP_PHOTURIS_DECRYPT_FAILED    equ 3                ; decrypt failed
89
ICMP_PHOTURIS_DECRYPT_FAILED	equ 3		     ; decrypt failed
92
 
90
 
93
 
91
 
94
 
92
 
95
virtual at 0
93
virtual at 0
96
        ICMP_Packet:
Line 94... Line 97...
94
	ICMP_Packet:
97
        .Type           db   ?
95
	.Type		db   ?
98
        .Code           db   ?
96
	.Code		db   ?
99
        .Checksum       dw   ?
97
	.Checksum	dw   ?
100
        .Identifier     dw   ?
98
	.Identifier	dw   ?
101
        .SequenceNumber dw   ?
99
	.SequenceNumber dw   ?
102
        .Data:
100
	.Data:
103
end virtual
101
end virtual
104
 
102
 
105
 
103
 
106
; entry point
104
; entry point
107
start:
105
start:
108
; load libraries
106
; load libraries
109
        stdcall dll.Load, @IMPORT
107
	stdcall dll.Load, @IMPORT
110
        test    eax, eax
108
	test	eax, eax
111
        jnz     exit
109
	jnz	exit
112
; initialize console
110
; initialize console
113
        push    1
111
	push	1
114
        call    [con_start]
112
	call	[con_start]
115
        push    title
113
	push	title
116
        push    25
114
	push	25
117
        push    80
115
	push	80
118
        push    25
116
	push	25
119
        push    80
117
	push	80
120
        call    [con_init]
118
	call	[con_init]
121
; main loop
119
; main loop
122
        push    str1
120
	push	str1
123
        call    [con_write_asciiz]
121
	call	[con_write_asciiz]
124
main:
122
main:
125
; write prompt
123
; write prompt
126
        push    str2
124
	push	str2
127
        call    [con_write_asciiz]
125
	call	[con_write_asciiz]
128
; read string
126
; read string
129
        mov     esi, s
127
	mov	esi, s
130
        push    256
128
	push	256
131
        push    esi
129
	push	esi
132
        call    [con_gets]
130
	call	[con_gets]
133
; check for exit
131
; check for exit
134
        test    eax, eax
132
	test	eax, eax
135
        jz      done
133
	jz	done
136
        cmp     byte [esi], 10
134
	cmp	byte [esi], 10
137
        jz      done
135
	jz	done
138
; delete terminating '\n'
136
; delete terminating '\n'
139
        push    esi
137
	push	esi
140
@@:
138
@@:
141
        lodsb
139
	lodsb
142
        test    al, al
140
	test	al, al
143
        jnz     @b
141
	jnz	@b
144
        mov     byte [esi-2], al
142
	mov	byte [esi-2], al
145
        pop     esi
143
	pop	esi
146
; resolve name
144
; resolve name
147
        push    esp     ; reserve stack place
Line 145... Line 148...
145
	push	esp	; reserve stack place
148
        push    esp     ; fourth parameter
146
	push	esp	; fourth parameter
149
        push    0       ; third parameter
147
	push	0	; third parameter
150
        push    0       ; second parameter
148
	push	0	; second parameter
151
        push    esi     ; first parameter
149
	push	esi	; first parameter
152
        call    [getaddrinfo]
150
	call	[getaddrinfo]
153
        pop     esi
151
	pop	esi
154
; test for error
152
; test for error
155
        test    eax, eax
Line 153... Line 156...
153
	test	eax, eax
156
        jnz     fail
Line 154... Line 157...
154
	jnz	fail
157
 
155
 
158
; convert IP address to decimal notation
156
; convert IP address to decimal notation
159
        mov     eax, [esi+addrinfo.ai_addr]
Line 157... Line 160...
157
	mov	eax, [esi+addrinfo.ai_addr]
160
        mov     eax, [eax+sockaddr_in.sin_addr]
158
	mov	eax, [eax+sockaddr_in.sin_addr]
161
        mov     [sockaddr1.ip], eax
Line 159... Line 162...
159
	mov	[sockaddr1.ip], eax
162
        push    eax
160
	push	eax
163
        call    [inet_ntoa]
161
	call	[inet_ntoa]
164
; write result
162
; write result
165
        mov     [ip_ptr], eax
Line 163... Line 166...
163
	mov	[ip_ptr], eax
166
 
Line 164... Line 167...
164
 
167
        push    eax
165
	push	eax
168
 
Line 166... Line 169...
166
 
169
; free allocated memory
Line 167... Line 170...
167
; free allocated memory
170
        push    esi
168
	push	esi
171
        call    [freeaddrinfo]
169
	call	[freeaddrinfo]
172
 
170
 
173
        push    str4
171
	push	str4
174
        call    [con_write_asciiz]
172
	call	[con_write_asciiz]
175
 
173
 
176
        mcall   socket, AF_INET4, SOCK_RAW, IPPROTO_ICMP
174
	mcall	socket, AF_INET4, SOCK_RAW, IPPROTO_ICMP
177
        cmp     eax, -1
175
	cmp	eax, -1
178
        jz      fail2
176
	jz	fail2
179
        mov     [socketnum], eax
177
	mov	[socketnum], eax
180
 
178
 
181
        mcall   connect, [socketnum], sockaddr1, 18
179
	mcall	connect, [socketnum], sockaddr1, 18
182
 
180
 
183
        mcall   40, 1 shl 7 ; + 7
181
	mcall	40, 1 shl 7 ; + 7
184
;        call    [con_cls]
182
;        call    [con_cls]
185
 
183
 
186
        mov     [count], 4
184
	mov	[count], 4
187
 
Line 185... Line 188...
185
 
188
mainloop:
186
mainloop:
189
        push    str3
187
	push	str3
190
        call    [con_write_asciiz]
188
	call	[con_write_asciiz]
191
        push    [ip_ptr]
189
	push	[ip_ptr]
192
        call    [con_write_asciiz]
190
	call	[con_write_asciiz]
193
 
191
 
194
        mcall   26,9
192
	mcall	26,9
195
        mov     [time_reference], eax
193
	mov	[time_reference], eax
196
        mcall   send, [socketnum], icmp_packet, icmp_packet.length, 0
194
	mcall	send, [socketnum], icmp_packet, icmp_packet.length, 0
197
 
Line 195... Line 198...
195
 
198
        mcall   23, 300 ; 3 seconds time-out
Line 196... Line 199...
196
	mcall	23, 300 ; 3 seconds time-out
199
        mcall   26,9
197
	mcall	26,9
200
        neg     [time_reference]
198
	neg	[time_reference]
201
        add     [time_reference], eax
199
	add	[time_reference], eax
202
 
200
 
203
        mcall   recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
201
	mcall	recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
204
        cmp     eax, -1
Line 202... Line 205...
202
	cmp	eax, -1
205
        je      .no_response
203
	je	.no_response
206
 
204
 
207
; validate the packet
Line 205... Line 208...
205
; validate the packet
208
        lea     esi, [buffer_ptr + ICMP_Packet.Data]
206
	lea	esi, [buffer_ptr + ICMP_Packet.Data]
209
        mov     edi, icmp_packet.data
207
	mov	edi, icmp_packet.data
210
        mov     ecx, 32/4
208
	mov	ecx, 32/4
211
        repe    cmpsd
209
	repe	cmpsd
212
        jne     .miscomp
210
	jne	.miscomp
213
 
Line 211... Line 214...
211
 
214
        push    [time_reference]
212
	push	[time_reference]
215
        push    str7
213
	push	str7
216
        call    [con_printf]
214
	call	[con_printf]
217
 
215
 
218
        jmp     continue
216
	jmp	continue
219
 
217
 
220
  .miscomp:
218
  .miscomp:
221
        sub     edi, icmp_packet.data
Line 219... Line 222...
219
	sub	edi, icmp_packet.data
222
        push    edi
220
	push	edi
223
        push    str9
221
	push	str9
224
        call    [con_printf]
222
	call	[con_printf]
225
        jmp     continue
223
	jmp	continue
226
 
224
 
227
  .no_response:
225
  .no_response:
228
        push    str8
226
	push	str8
229
        call    [con_write_asciiz]
Line 227... Line 230...
227
	call	[con_write_asciiz]
230
 
228
 
231
   continue:
229
   continue:
232
        dec     [count]
230
	dec	[count]
233
        jz      done
231
	jz	done
234
        mcall   5, 100  ; wait a second
232
	mcall	5, 100	; wait a second
235
        inc     [icmp_packet.id]
233
	inc	[icmp_packet.id]
236
        jmp     mainloop
234
	jmp	mainloop
237
 
235
 
238
 
236
 
239
 
237
 
240
done:
238
done:
241
        push    str10
Line 239... Line 242...
239
	push	str10
242
        call    [con_write_asciiz]
240
	call	[con_write_asciiz]
243
        call    [con_getch2]
241
	call	[con_getch2]
244
        push    1
242
	push	1
245
        call    [con_exit]
243
	call	[con_exit]
246
exit:
244
exit:
247
        mcall   -1
245
	mcall	-1
248
 
246
 
249
fail:
247
fail:
250
        push    str5
Line 248... Line 251...
248
	push	str5
251
        call    [con_write_asciiz]
249
	call	[con_write_asciiz]
252
        jmp     done
250
	jmp	done
253
fail2:
Line 251... Line 254...
251
fail2:
254
        push    str6
252
	push	str6
255
        call    [con_write_asciiz]
253
	call	[con_write_asciiz]
256
        jmp     done
254
	jmp	done
257
 
255
 
258
 
256
 
259
; data
257
; data
260
title   db      'ICMP - test application',0
258
title	db	'ICMP - test application',0
261
str1    db      'ICMP test application v0.1',10,' for KolibriOS # 1540 or later. ',10,10,0
259
str1	db	'ICMP test application v0.1',10,' for KolibriOS # 1540 or later. ',10,10,0
262
str2    db      '> ',0
260
str2	db	'> ',0
263
str3    db      'Ping to: ',0
261
str3	db	'Ping to: ',0
264
str4    db      10,0
262
str4	db	10,0
265
str5    db      'Name resolution failed.',10,10,0
263
str5	db	'Name resolution failed.',10,10,0
266
str6    db      'Could not open socket',10,10,0
264
str6	db	'Could not open socket',10,10,0
267
str7    db      ' time= %u0ms',10,0
265
str7	db	' time= %u0ms',10,0
268
str8    db      ' timeout!',10,0
266
str8	db	' timeout!',10,0
269
str9    db      ' miscompare at offset %u',10,0
267
str9	db	' miscompare at offset %u',10,0
270
str10   db      10,10,'Press any key to exit',0
268
str10	db	10,10,'Press any key to exit',0
271
 
269
 
272
sockaddr1:
270
sockaddr1:
273
        dw AF_INET4
271
	dw AF_INET4
274
.port   dw 0
272
.port	dw 0
275
.ip     dd 0
273
.ip	dd 0
276
        rb 10
274
	rb 10
277
 
275
 
278
time_reference  dd ?
276
time_reference	dd ?
279
ip_ptr          dd ?
Line 277... Line 280...
277
ip_ptr		dd ?
280
count           dd ?
Line 278... Line 281...
278
count		dd ?
281
 
Line 279... Line 282...
279
 
282
 
280
 
283
; import
281
; import
284
align 4
282
align 4
285
@IMPORT: