Telnet: code cleanup, no semantic changes.

git-svn-id: svn://kolibrios.org@5858 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2015-10-25 12:04:33 +00:00
parent cf26ff1759
commit 026a30e72b

View File

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