Rev 2314 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2853 | hidnplayr | 1 | |
2 | |||
3 | |||
1541 | hidnplayr | 4 | org 0x0 |
2853 | hidnplayr | 5 | ; standard header |
1541 | hidnplayr | 6 | db 'MENUET01' ; signature |
2853 | hidnplayr | 7 | dd 1 ; header version |
8 | dd start ; entry point |
||
9 | dd I_END ; initialized size |
||
10 | dd mem ; required memory |
||
11 | dd mem ; stack pointer |
||
12 | dd 0 ; parameters |
||
13 | dd 0 ; path |
||
14 | |||
1541 | hidnplayr | 15 | |
16 | |||
2853 | hidnplayr | 17 | ; useful includes |
1541 | hidnplayr | 18 | include '../macros.inc' |
19 | purge mov,add,sub |
||
20 | include '../proc32.inc' |
||
21 | include '../dll.inc' |
||
22 | |||
23 | |||
24 | |||
25 | |||
26 | |||
27 | |||
28 | |||
29 | |||
2853 | hidnplayr | 30 | |
1541 | hidnplayr | 31 | |
2853 | hidnplayr | 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 | |||
1541 | hidnplayr | 49 | |
2853 | hidnplayr | 50 | |
1541 | hidnplayr | 51 | |
2853 | hidnplayr | 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 | |||
1541 | hidnplayr | 57 | |
2853 | hidnplayr | 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 | |||
1541 | hidnplayr | 63 | |
2853 | hidnplayr | 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 | |||
1541 | hidnplayr | 68 | |
2853 | hidnplayr | 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 | |||
1541 | hidnplayr | 73 | |
2853 | hidnplayr | 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 | |||
1541 | hidnplayr | 88 | |
2853 | hidnplayr | 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 | |||
1541 | hidnplayr | 93 | |
94 | |||
95 | |||
96 | ICMP_Packet: |
||
2853 | hidnplayr | 97 | .Type db ? |
98 | .Code db ? |
||
99 | .Checksum dw ? |
||
100 | .Identifier dw ? |
||
101 | .SequenceNumber dw ? |
||
102 | .Data: |
||
103 | end virtual |
||
1541 | hidnplayr | 104 | |
105 | |||
106 | |||
107 | start: |
||
108 | ; load libraries |
||
109 | stdcall dll.Load, @IMPORT |
||
2853 | hidnplayr | 110 | test eax, eax |
111 | jnz exit |
||
112 | ; initialize console |
||
1541 | hidnplayr | 113 | push 1 |
2853 | hidnplayr | 114 | call [con_start] |
115 | push title |
||
116 | push 25 |
||
117 | push 80 |
||
118 | push 25 |
||
119 | push 80 |
||
120 | call [con_init] |
||
121 | ; main loop |
||
1541 | hidnplayr | 122 | push str1 |
2853 | hidnplayr | 123 | call [con_write_asciiz] |
124 | main: |
||
1541 | hidnplayr | 125 | ; write prompt |
126 | push str2 |
||
2853 | hidnplayr | 127 | call [con_write_asciiz] |
128 | ; read string |
||
1541 | hidnplayr | 129 | mov esi, s |
2853 | hidnplayr | 130 | push 256 |
131 | push esi |
||
132 | call [con_gets] |
||
133 | ; check for exit |
||
1541 | hidnplayr | 134 | test eax, eax |
2853 | hidnplayr | 135 | jz done |
136 | cmp byte [esi], 10 |
||
137 | jz done |
||
138 | ; delete terminating '\n' |
||
1541 | hidnplayr | 139 | push esi |
2853 | hidnplayr | 140 | @@: |
1541 | hidnplayr | 141 | lodsb |
2853 | hidnplayr | 142 | test al, al |
143 | jnz @b |
||
144 | mov byte [esi-2], al |
||
145 | pop esi |
||
146 | ; resolve name |
||
1541 | hidnplayr | 147 | push esp ; reserve stack place |
2853 | hidnplayr | 148 | push esp ; fourth parameter |
149 | push 0 ; third parameter |
||
150 | push 0 ; second parameter |
||
151 | push esi ; first parameter |
||
152 | call [getaddrinfo] |
||
153 | pop esi |
||
154 | ; test for error |
||
1541 | hidnplayr | 155 | test eax, eax |
2853 | hidnplayr | 156 | jnz fail |
157 | |||
1541 | hidnplayr | 158 | |
159 | mov eax, [esi+addrinfo.ai_addr] |
||
2853 | hidnplayr | 160 | mov eax, [eax+sockaddr_in.sin_addr] |
161 | mov [sockaddr1.ip], eax |
||
162 | push eax |
||
163 | call [inet_ntoa] |
||
164 | ; write result |
||
1541 | hidnplayr | 165 | mov [ip_ptr], eax |
2853 | hidnplayr | 166 | |
1541 | hidnplayr | 167 | |
2853 | hidnplayr | 168 | |
1541 | hidnplayr | 169 | |
170 | push esi |
||
2853 | hidnplayr | 171 | call [freeaddrinfo] |
172 | |||
1541 | hidnplayr | 173 | |
2853 | hidnplayr | 174 | call [con_write_asciiz] |
175 | |||
1541 | hidnplayr | 176 | |
2853 | hidnplayr | 177 | cmp eax, -1 |
178 | jz fail2 |
||
179 | mov [socketnum], eax |
||
180 | |||
1541 | hidnplayr | 181 | |
2853 | hidnplayr | 182 | |
1541 | hidnplayr | 183 | |
2853 | hidnplayr | 184 | ; call [con_cls] |
1541 | hidnplayr | 185 | |
186 | |||
2853 | hidnplayr | 187 | |
1541 | hidnplayr | 188 | |
189 | push str3 |
||
2853 | hidnplayr | 190 | call [con_write_asciiz] |
191 | push [ip_ptr] |
||
192 | call [con_write_asciiz] |
||
193 | |||
1541 | hidnplayr | 194 | |
2853 | hidnplayr | 195 | mov [time_reference], eax |
196 | mcall send, [socketnum], icmp_packet, icmp_packet.length, 0 |
||
197 | |||
1541 | hidnplayr | 198 | |
2853 | hidnplayr | 199 | mcall 26,9 |
200 | neg [time_reference] |
||
201 | add [time_reference], eax |
||
202 | |||
1541 | hidnplayr | 203 | |
2853 | hidnplayr | 204 | cmp eax, -1 |
205 | je .no_response |
||
206 | |||
1541 | hidnplayr | 207 | |
208 | lea esi, [buffer_ptr + ICMP_Packet.Data] |
||
2853 | hidnplayr | 209 | mov edi, icmp_packet.data |
210 | mov ecx, 32/4 |
||
211 | repe cmpsd |
||
212 | jne .miscomp |
||
213 | |||
1541 | hidnplayr | 214 | |
2853 | hidnplayr | 215 | push str7 |
216 | call [con_printf] |
||
217 | |||
1541 | hidnplayr | 218 | |
2853 | hidnplayr | 219 | |
1541 | hidnplayr | 220 | |
221 | sub edi, icmp_packet.data |
||
2853 | hidnplayr | 222 | push edi |
223 | push str9 |
||
224 | call [con_printf] |
||
225 | jmp continue |
||
226 | |||
1541 | hidnplayr | 227 | |
228 | push str8 |
||
2853 | hidnplayr | 229 | call [con_write_asciiz] |
230 | |||
1541 | hidnplayr | 231 | |
232 | dec [count] |
||
2853 | hidnplayr | 233 | jz done |
234 | mcall 5, 100 ; wait a second |
||
235 | inc [icmp_packet.id] |
||
236 | jmp mainloop |
||
237 | |||
1541 | hidnplayr | 238 | |
239 | |||
240 | |||
241 | push str10 |
||
2853 | hidnplayr | 242 | call [con_write_asciiz] |
243 | call [con_getch2] |
||
244 | push 1 |
||
245 | call [con_exit] |
||
246 | exit: |
||
1541 | hidnplayr | 247 | mcall -1 |
2853 | hidnplayr | 248 | |
1541 | hidnplayr | 249 | |
250 | push str5 |
||
2853 | hidnplayr | 251 | call [con_write_asciiz] |
252 | jmp done |
||
253 | fail2: |
||
1541 | hidnplayr | 254 | push str6 |
2853 | hidnplayr | 255 | call [con_write_asciiz] |
256 | jmp done |
||
257 | |||
1541 | hidnplayr | 258 | |
259 | |||
260 | title db 'ICMP - test application',0 |
||
2853 | hidnplayr | 261 | str1 db 'ICMP test application v0.1',10,' for KolibriOS # 1540 or later. ',10,10,0 |
262 | str2 db '> ',0 |
||
263 | str3 db 'Ping to: ',0 |
||
264 | str4 db 10,0 |
||
265 | str5 db 'Name resolution failed.',10,10,0 |
||
266 | str6 db 'Could not open socket',10,10,0 |
||
267 | str7 db ' time= %u0ms',10,0 |
||
268 | str8 db ' timeout!',10,0 |
||
269 | str9 db ' miscompare at offset %u',10,0 |
||
270 | str10 db 10,10,'Press any key to exit',0 |
||
271 | |||
1541 | hidnplayr | 272 | |
273 | dw AF_INET4 |
||
2853 | hidnplayr | 274 | .port dw 0 |
275 | .ip dd 0 |
||
276 | rb 10 |
||
277 | |||
1541 | hidnplayr | 278 | |
2853 | hidnplayr | 279 | ip_ptr dd ? |
280 | count dd ? |
||
281 | |||
1541 | hidnplayr | 282 | |
283 | |||
284 | align 4 |
||
285 | @IMPORT: |
||
286 | |||
287 | |||
288 | import network, \ |
||
2853 | hidnplayr | 289 | getaddrinfo, 'getaddrinfo', \ |
290 | freeaddrinfo, 'freeaddrinfo', \ |
||
291 | inet_ntoa, 'inet_ntoa' |
||
292 | |||
1541 | hidnplayr | 293 | |
2853 | hidnplayr | 294 | con_start, 'START', \ |
295 | con_init, 'con_init', \ |
||
296 | con_write_asciiz, 'con_write_asciiz', \ |
||
297 | con_printf, 'con_printf', \ |
||
298 | con_exit, 'con_exit', \ |
||
299 | con_gets, 'con_gets',\ |
||
300 | con_cls, 'con_cls',\ |
||
301 | con_getch2, 'con_getch2',\ |
||
302 | con_set_cursor_pos, 'con_set_cursor_pos' |
||
303 | |||
1541 | hidnplayr | 304 | |
2853 | hidnplayr | 305 | |
1541 | hidnplayr | 306 | |
2853 | hidnplayr | 307 | db 0 ; code |
308 | dw 0 ; |
||
309 | .id dw 0x0000 ; identifier |
||
310 | .seq dw 0x0001 ; sequence number |
||
311 | .data db 'abcdefghijklmnopqrstuvwxyz012345678' |
||
312 | .length = $ - icmp_packet |
||
1541 | hidnplayr | 313 | |
314 | |||
315 | |||
316 | |||
2853 | hidnplayr | 317 | |
1541 | hidnplayr | 318 | |
2853 | hidnplayr | 319 | align 4 |
320 | rb 4096 ; stack |
||
321 | mem: |
||
1541 | hidnplayr | 322 |