Rev 6394 | Rev 6835 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6394 | Rev 6436 | ||
---|---|---|---|
Line 144... | Line 144... | ||
144 | .portloop: |
144 | .portloop: |
145 | lodsb |
145 | lodsb |
146 | cmp al, 0x20 |
146 | cmp al, 0x20 |
147 | jbe .port_done |
147 | jbe .port_done |
148 | sub al, '0' |
148 | sub al, '0' |
- | 149 | jnb @f |
|
- | 150 | mov eax, str_err_host |
|
149 | jb error_hostname |
151 | jmp error |
150 | cmp al, 9 |
152 | @@: cmp al, 9 |
- | 153 | jna @f |
|
- | 154 | mov eax, str_err_host |
|
151 | ja error_hostname |
155 | jmp error |
152 | lea ebx, [ebx*4 + ebx] |
156 | @@: lea ebx, [ebx*4 + ebx] |
153 | shl ebx, 1 |
157 | shl ebx, 1 |
154 | add ebx, eax |
158 | add ebx, eax |
155 | jmp .portloop |
159 | jmp .portloop |
Line 156... | Line 160... | ||
156 | 160 | ||
Line 166... | Line 170... | ||
166 | push esp ; reserve stack place |
170 | push esp ; reserve stack place |
167 | invoke getaddrinfo, buf_cmd, 0, 0, esp |
171 | invoke getaddrinfo, buf_cmd, 0, 0, esp |
168 | pop esi |
172 | pop esi |
169 | ; test for error |
173 | ; test for error |
170 | test eax, eax |
174 | test eax, eax |
- | 175 | jz @f |
|
171 | jnz error_resolve |
176 | mov eax, str_err_resolve |
- | 177 | jmp error |
|
- | 178 | @@: |
|
172 | ; write results |
179 | ; write results |
173 | invoke con_write_asciiz, str8 ; ' (',0 |
180 | invoke con_write_asciiz, str8 ; ' (',0 |
174 | mov eax, [esi+addrinfo.ai_addr] ; convert IP address to decimal notation |
181 | mov eax, [esi+addrinfo.ai_addr] ; convert IP address to decimal notation |
175 | mov eax, [eax+sockaddr_in.sin_addr] ; |
182 | mov eax, [eax+sockaddr_in.sin_addr] ; |
176 | mov [sockaddr1.ip], eax ; |
183 | mov [sockaddr1.ip], eax ; |
Line 179... | Line 186... | ||
179 | invoke freeaddrinfo, esi ; free allocated memory |
186 | invoke freeaddrinfo, esi ; free allocated memory |
180 | invoke con_write_asciiz, str9 ; ')',10,0 |
187 | invoke con_write_asciiz, str9 ; ')',10,0 |
181 | ; open the socket |
188 | ; open the socket |
182 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
189 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
183 | cmp eax, -1 |
190 | cmp eax, -1 |
- | 191 | jne @f |
|
- | 192 | mov eax, str_err_socket |
|
184 | je error_socket |
193 | jmp error |
185 | mov [controlsocket], eax |
194 | @@: mov [controlsocket], eax |
186 | ; connect to the server |
195 | ; connect to the server |
187 | invoke con_write_asciiz, str_connect |
196 | invoke con_write_asciiz, str_connect |
188 | mcall connect, [controlsocket], sockaddr1, 18 |
197 | mcall connect, [controlsocket], sockaddr1, 18 |
189 | cmp eax, -1 |
198 | cmp eax, -1 |
- | 199 | jne @f |
|
190 | je error_connect |
200 | mov eax, str_err_connect |
- | 201 | jmp error |
|
191 | mov [status], STATUS_CONNECTING |
202 | @@: mov [status], STATUS_CONNECTING |
192 | ; Tell the user we're waiting for the server now. |
203 | ; Tell the user we're waiting for the server now. |
193 | invoke con_write_asciiz, str_waiting |
204 | invoke con_write_asciiz, str_waiting |
Line 194... | Line 205... | ||
194 | 205 | ||
195 | ; Reset 'offset' variable, it's used by the data receiver |
206 | ; Reset 'offset' variable, it's used by the data receiver |
Line 212... | Line 223... | ||
212 | mov [timeout], eax |
223 | mov [timeout], eax |
213 | .receive_loop: |
224 | .receive_loop: |
214 | mcall 23, 50 ; Wait for event with timeout |
225 | mcall 23, 50 ; Wait for event with timeout |
215 | mcall 26, 9 |
226 | mcall 26, 9 |
216 | cmp eax, [timeout] |
227 | cmp eax, [timeout] |
- | 228 | jl @f |
|
217 | jge error_timeout |
229 | mov eax, str_err_timeout |
- | 230 | jmp error |
|
218 | mcall recv, [controlsocket], buf_buffer1, BUFFERSIZE, MSG_DONTWAIT |
231 | @@: mcall recv, [controlsocket], buf_buffer1, BUFFERSIZE, MSG_DONTWAIT |
219 | test eax, eax |
232 | test eax, eax |
220 | jnz .got_data |
233 | jnz .got_data |
221 | cmp ebx, EWOULDBLOCK |
234 | cmp ebx, EWOULDBLOCK |
- | 235 | je @f |
|
- | 236 | mov eax, str_err_recv |
|
222 | jne error_socket |
237 | jmp error |
223 | jmp .receive_loop |
238 | @@: jmp .receive_loop |
Line 224... | Line 239... | ||
224 | 239 | ||
225 | .got_data: |
240 | .got_data: |
Line 226... | Line 241... | ||
226 | mov [offset], 0 |
241 | mov [offset], 0 |
Line 448... | Line 463... | ||
448 | ret |
463 | ret |
Line 449... | Line 464... | ||
449 | 464 | ||
450 | .active: |
465 | .active: |
451 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
466 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
- | 467 | cmp eax, -1 |
|
- | 468 | jne @f |
|
452 | cmp eax, -1 |
469 | mov eax, str_err_socket |
453 | je error_socket |
470 | jmp error |
Line 454... | Line 471... | ||
454 | mov [datasocket], eax |
471 | @@: mov [datasocket], eax |
455 | 472 | ||
456 | mov ax, [acti_port_start] |
473 | mov ax, [acti_port_start] |
Line 457... | Line 474... | ||
457 | xchg al, ah |
474 | xchg al, ah |
458 | mov [sockaddr2.port], ax |
475 | mov [sockaddr2.port], ax |
- | 476 | ||
- | 477 | mcall bind, [datasocket], sockaddr2, 18 |
|
459 | 478 | cmp eax, -1 |
|
- | 479 | jne @f |
|
Line 460... | Line 480... | ||
460 | mcall bind, [datasocket], sockaddr2, 18 |
480 | mov eax, str_err_bind |
461 | cmp eax, -1 |
481 | jmp error |
- | 482 | @@: |
|
- | 483 | ||
462 | je error_socket |
484 | mcall listen, [datasocket], 1 |
- | 485 | cmp eax, -1 |
|
Line 463... | Line 486... | ||
463 | 486 | jne @f |
|
464 | mcall listen, [datasocket], 1 |
487 | mov eax, str_err_listen |
465 | cmp eax, -1 |
488 | jmp error |
466 | je error_socket |
489 | @@: |
Line 489... | Line 512... | ||
489 | lea esi, [edi - buf_buffer1] |
512 | lea esi, [edi - buf_buffer1] |
490 | mcall send, [controlsocket], buf_buffer1, , 0 |
513 | mcall send, [controlsocket], buf_buffer1, , 0 |
Line 491... | Line 514... | ||
491 | 514 | ||
492 | mcall accept, [datasocket], sockaddr2, 18 ; time to accept the awaiting connection.. |
515 | mcall accept, [datasocket], sockaddr2, 18 ; time to accept the awaiting connection.. |
- | 516 | cmp eax, -1 |
|
- | 517 | jne @f |
|
493 | cmp eax, -1 |
518 | mov eax, str_err_accept |
494 | je error_socket |
519 | jmp error |
495 | push eax |
520 | @@: push eax |
496 | mcall close, [datasocket] |
521 | mcall close, [datasocket] |
Line 497... | Line 522... | ||
497 | pop [datasocket] |
522 | pop [datasocket] |
Line 524... | Line 549... | ||
524 | jnz @r |
549 | jnz @r |
Line 525... | Line 550... | ||
525 | 550 | ||
526 | pop ecx ebx edx |
551 | pop ecx ebx edx |
Line 527... | Line -... | ||
527 | ret |
- | |
528 | - | ||
529 | error_hostname: |
- | |
530 | invoke con_set_flags, 0x0c ; print errors in red |
- | |
531 | invoke con_write_asciiz, str_err_host |
- | |
532 | jmp wait_for_keypress |
- | |
533 | - | ||
534 | error_connect: |
- | |
535 | invoke con_set_flags, 0x0c ; print errors in red |
- | |
536 | invoke con_write_asciiz, str_err_connect |
- | |
537 | jmp wait_for_keypress |
- | |
538 | - | ||
539 | error_timeout: |
- | |
540 | invoke con_set_flags, 0x0c ; print errors in red |
- | |
541 | invoke con_write_asciiz, str_err_timeout |
- | |
542 | jmp wait_for_keypress |
552 | ret |
543 | - | ||
544 | error_socket: |
- | |
545 | invoke con_set_flags, 0x0c ; print errors in red |
553 | |
546 | invoke con_write_asciiz, str_err_socket |
- | |
547 | jmp wait_for_keypress |
- | |
548 | 554 | error: |
|
- | 555 | push eax |
|
549 | error_resolve: |
556 | invoke con_set_flags, 0x0c ; print errors in red |
550 | invoke con_set_flags, 0x0c ; print errors in red |
557 | pop eax |
Line 551... | Line 558... | ||
551 | invoke con_write_asciiz, str_err_resolve |
558 | invoke con_write_asciiz, eax |
552 | jmp wait_for_keypress |
559 | jmp wait_for_keypress |
553 | 560 | ||
Line 582... | Line 589... | ||
582 | 589 | ||
583 | str_prompt db '> ',0 |
590 | str_prompt db '> ',0 |
584 | str_resolve db 'Resolving ',0 |
591 | str_resolve db 'Resolving ',0 |
585 | str_newline db 10,0 |
592 | str_newline db 10,0 |
586 | str_err_resolve db 10,'Name resolution failed.',10,0 |
593 | str_err_resolve db 10,'Name resolution failed.',10,0 |
- | 594 | str_err_socket db 10,'[75,0 socket]: Error creating a socket',10,0 |
|
- | 595 | str_err_bind db 10,'[75,2 bind]: Error binding to socket',10,0 |
|
- | 596 | str_err_listen db 10,'[75,3 listen]: Cannot accept incoming connections',10,0 |
|
- | 597 | str_err_accept db 10,'[75,5 accept]: Error accepting a connection',10,0 |
|
587 | str_err_socket db 10,'Socket error.',10,0 |
598 | str_err_recv db 10,'[75,7 recv]: Error receiving data from server',10,0 |
588 | str_err_heap db 10,'Cannot allocate memory from heap.',10,0 |
599 | str_err_heap db 10,'Cannot allocate memory from heap.',10,0 |
589 | str_err_timeout db 10,'Timeout - no response from server.',10,0 |
600 | str_err_timeout db 10,'Timeout - no response from server.',10,0 |
590 | str_err_connect db 10,'Cannot connect to the server.',10,0 |
601 | str_err_connect db 10,'[75,4 connect]: Cannot connect to the server.',10,0 |
- | 602 | str_err_host db 10,'Invalid hostname.',10,0 |
|
591 | str_err_host db 10,'Invalid hostname.',10,0 |
603 | str_err_params db 10,'Invalid parameters',10,0 |
592 | str8 db ' (',0 |
604 | str8 db ' (',0 |
593 | str9 db ')',10,0 |
605 | str9 db ')',10,0 |
594 | str_push db 'Push any key to continue.',0 |
606 | str_push db 'Push any key to continue.',0 |
595 | str_connect db 'Connecting...',10,0 |
607 | str_connect db 'Connecting...',10,0 |