1,6 → 1,6 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;; |
;; Copyright (C) KolibriOS team 2010-2013. All rights reserved. ;; |
;; Distributed under terms of the GNU General Public License ;; |
;; ;; |
;; telnet.asm - Telnet client for KolibriOS ;; |
14,6 → 14,8 |
|
format binary as "" |
|
__DEBUG__ = 0 |
__DEBUG_LEVEL__ = 1 |
BUFFERSIZE = 4096 |
|
use32 |
31,6 → 33,7 |
purge mov,add,sub |
include '../../proc32.inc' |
include '../../dll.inc' |
include '../../debug-fdo.inc' |
include '../../network.inc' |
|
; entry point |
40,8 → 43,14 |
test eax, eax |
jnz exit |
; initialize console |
invoke con_start, 1 |
invoke con_init, 80, 25, 80, 25, title |
push 1 |
call [con_start] |
push title |
push 25 |
push 80 |
push 25 |
push 80 |
call [con_init] |
|
; Check for parameters |
cmp byte[hostname], 0 |
48,16 → 57,20 |
jne resolve |
|
main: |
invoke con_cls |
call [con_cls] |
; Welcome user |
invoke con_write_asciiz, str1 |
push str1 |
call [con_write_asciiz] |
|
prompt: |
; write prompt |
invoke con_write_asciiz, str2 |
; read string (wait for input) |
push str2 |
call [con_write_asciiz] |
; read string |
mov esi, hostname |
invoke con_gets, esi, 256 |
push 256 |
push esi |
call [con_gets] |
; check for exit |
test eax, eax |
jz done |
65,9 → 78,10 |
jz done |
|
resolve: |
mov [sockaddr1.port], 23 shl 8 ; Port is in network byte order |
|
; delete terminating newline from URL and parse port, if any. |
mov [sockaddr1.port], 23 shl 8 |
|
; delete terminating '\n' |
mov esi, hostname |
@@: |
lodsb |
84,7 → 98,7 |
mov byte[esi-1], 0 |
.portloop: |
lodsb |
cmp al, ' ' |
cmp al, 0x20 |
jbe .port_done |
sub al, '0' |
jb hostname_error |
103,30 → 117,42 |
|
; resolve name |
push esp ; reserve stack place |
invoke getaddrinfo, hostname, 0, 0, esp |
push esp ; ptr to result |
push 0 ; addrinfo hints |
push 0 ; servname |
push hostname; hostname |
call [getaddrinfo] |
pop esi |
; test for error |
test eax, eax |
jnz dns_error |
|
invoke con_cls |
invoke con_write_asciiz, str3 |
invoke con_write_asciiz, hostname |
call [con_cls] |
push str3 |
call [con_write_asciiz] |
push hostname |
call [con_write_asciiz] |
|
; write results |
invoke con_write_asciiz, str8 |
push str8 |
call [con_write_asciiz] |
; mov edi, esi |
|
; convert IP address to decimal notation |
mov eax, [esi+addrinfo.ai_addr] |
mov eax, [eax+sockaddr_in.sin_addr] |
mov [sockaddr1.ip], eax |
invoke inet_ntoa, eax |
push eax |
call [inet_ntoa] |
; write result |
invoke con_write_asciiz, eax |
push eax |
call [con_write_asciiz] |
; free allocated memory |
invoke freeaddrinfo, esi |
push esi |
call [freeaddrinfo] |
|
invoke con_write_asciiz, str9 |
push str9 |
call [con_write_asciiz] |
|
mcall socket, AF_INET4, SOCK_STREAM, 0 |
cmp eax, -1 |
137,8 → 163,8 |
test eax, eax |
jnz socket_err |
|
mcall 40, EVM_STACK |
invoke con_cls |
mcall 40, 1 shl 7 ; + 7 |
call [con_cls] |
|
mcall 18, 7 |
push eax |
147,7 → 173,7 |
mcall 18, 3 |
|
mainloop: |
invoke con_get_flags |
call [con_get_flags] |
test eax, 0x200 ; con window closed? |
jnz exit |
|
155,14 → 181,17 |
cmp eax, -1 |
je closed |
|
|
DEBUGF 1, 'TELNET: got %u bytes of data !\n', eax |
|
mov esi, buffer_ptr |
lea edi, [esi+eax] |
mov byte[edi], 0 |
|
.scan_cmd: |
cmp byte[esi], 0xff ; Interpret As Command |
jne .no_cmd |
; TODO: parse options |
; for now, we will reply with 'WONT' to everything |
; TODO: parse options, for now, we will reply with 'WONT' to everything |
mov byte[esi+1], 252 ; WONT |
add esi, 3 ; a command is always 3 bytes |
jmp .scan_cmd |
171,6 → 200,8 |
cmp esi, buffer_ptr |
je .print |
|
DEBUGF 1, 'TELNET: sending data\n' |
|
push esi edi |
sub esi, buffer_ptr |
mcall send, [socketnum], buffer_ptr, , 0 |
180,7 → 211,8 |
cmp esi, edi |
jae mainloop |
|
invoke con_write_asciiz, esi |
push esi |
call [con_write_asciiz] |
|
.loop: |
lodsb |
190,23 → 222,32 |
|
|
socket_err: |
invoke con_write_asciiz, str6 |
DEBUGF 1, "TELNET: socket error %d", ebx |
push str6 |
call [con_write_asciiz] |
|
jmp prompt |
|
dns_error: |
invoke con_write_asciiz, str5 |
DEBUGF 1, "TELNET: DNS error %d", eax |
push str5 |
call [con_write_asciiz] |
|
jmp prompt |
|
hostname_error: |
invoke con_write_asciiz, str11 |
push str11 |
call [con_write_asciiz] |
jmp prompt |
|
closed: |
invoke con_write_asciiz, str12 |
push str12 |
call [con_write_asciiz] |
jmp prompt |
|
done: |
invoke con_exit, 1 |
push 1 |
call [con_exit] |
exit: |
|
mcall close, [socketnum] |
217,7 → 258,7 |
thread: |
mcall 40, 0 |
.loop: |
invoke con_getch2 |
call [con_getch2] |
mov [send_data], ax |
xor esi, esi |
inc esi |
227,7 → 268,7 |
@@: |
mcall send, [socketnum], send_data |
|
invoke con_get_flags |
call [con_get_flags] |
test eax, 0x200 ; con window closed? |
jz .loop |
mcall -1 |
257,6 → 298,11 |
.ip dd 0 |
rb 10 |
|
include_debug_strings ; ALWAYS present in data section |
|
|
|
; import |
align 4 |
@IMPORT: |
|