Hey folks,

I can't seem to get this code to work. It is simply supposed to connect to a telnet server and display the first line it gets in a message box.
The Final Product is supposed to work like telnet, only that every line it receives is written to a listbox, and special commands are send to the telnet server.
PS: The progi establishes the connection but doesn't show the recv data.



.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
include \masm32\include\wsock32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\wsock32.lib

DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

.data
sin sockaddr_in <>
wsadata WSADATA <>
host db "host.domain.com",0
port dd 23
ErrorMsg db "An Error occured",0
ErrorCapt db "Error",0
DlgName db "test",0

.data?
hInstance HINSTANCE ?
sock dd ?
hMemory dd ?
buffer dd ?
available_data dd ?
actual_data_read dd ?

.const
IDC_APPLY equ 3001
WM_SOCKET equ WM_USER+100
.code
start:
invoke GetModuleHandle,NULL
mov hInstance, eax
invoke DialogBoxParam,hInstance,addr DlgName,NULL,addr DlgProc,NULL
invoke ExitProcess,eax

DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.IF uMsg==WM_SOCKET
mov eax,lParam
.IF ax==FD_CONNECT
shr eax,16
.IF ax==NULL
.ENDIF
.ELSEIF ax==FD_READ
shr eax,16
.IF ax==NULL
invoke ioctlsocket, socket, FIONREAD, addr available_data
.IF eax==NULL
invoke GlobalAlloc, GHND, available_data
mov hMemory,eax
invoke GlobalLock, eax
mov buffer,eax
invoke recv, sock, buffer, available_data, 0
mov actual_data_read, eax
invoke MessageBox,NULL,addr buffer,addr ErrorCapt,MB_OK or MB_ICONWARNING
invoke GlobalUnlock, buffer
invoke GlobalFree, hMemory
.ENDIF
.ENDIF
.ELSEIF ax==FD_CLOSE
shr eax,16
.IF ax==NULL
.ENDIF
.ENDIF
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
mov edx,wParam
shr edx,16
.IF dx==BN_CLICKED
.IF ax==IDC_APPLY
invoke WSAStartup,101h,addr wsadata
.IF eax != NULL
invoke MessageBox,NULL,addr ErrorMsg,addr ErrorCapt,MB_OK or MB_ICONWARNING
.ELSE
invoke socket,AF_INET,SOCK_STREAM,0
.IF eax != INVALID_SOCKET
mov sock,eax
mov sin.sin_family, AF_INET
invoke htons, port
mov sin.sin_port,ax
invoke gethostbyname,addr host
mov eax,[eax+12]
mov eax,[eax]
mov eax,[eax]
mov sin.sin_addr,eax
invoke WSAAsyncSelect, sock, hWin,WM_SOCKET, FD_CONNECT+FD_READ+FD_CLOSE
invoke connect,sock,addr sin,sizeof sin
.ELSE
invoke MessageBox,NULL,addr ErrorMsg,addr ErrorCapt,MB_OK or MB_ICONWARNING
.ENDIF
.ENDIF
.ENDIF
.ENDIF
.ELSEIF uMsg==WM_INITDIALOG

.ELSEIF uMsg==WM_CLOSE
invoke closesocket,sock
invoke WSACleanup
invoke EndDialog,hWin,NULL

.ENDIF
ret
DlgProc endp
end start


Thanks in advance
Olli
Posted on 2002-03-21 08:32:22 by Olli


invoke ioctlsocket, socket, FIONREAD, addr available_data


You didn't call your socket handle 'socket', but 'sock'. when you use 'socket' it will probably assemble with the address of the function socket as parameter which is not what you want.

I tried your code changing that line and it received data but got stuck on the messagebox.. Using my wshook tool I can see the data received (see screenshot below).

Thomas

edit:P.S. the data you receive *is* correct, I get the same using windows' telnet, but the server is waiting for your response before it shows more.
Posted on 2002-03-21 09:25:35 by Thomas
ok, i got that done it works. Now i got another Problem and i really can't figure out how to do it. I read through a whole bunch of source code. But no way. So the problem is:
when i logon to my server with telnet i get this:

---Welcome on SuSE Linux 7.3---

login: _

But i don't get this text over my program. So maybe u can help me to get this work and tell me how to login on my server via my program.
(The code for it is above)

Thanks in Advance,
Olli
Posted on 2002-03-21 12:27:58 by Olli
I think you should give the server a reply to those initial values showed in my first screenshot, before the server will ask your login.
However I don't know much about the telnet protocol so you'll have to look that up yourself. Have a look at www.rfc-editor.org.
When I connect to the same server using telnet (via wshook), I get the same initial values as with your program, but the telnet client also sends a lot, even though I didn't type a word:

Thomas
Posted on 2002-03-21 12:38:36 by Thomas
Pressed enter too soon, here's the screenshot:
Posted on 2002-03-21 12:39:26 by Thomas
Thanks again Thomas,

I might not be the smartest, but I learned something about winsock and telnet. I've seen in the source code for http clients that I have to send a request by a line starting with get.
Ok so i checked the rfc but i'm to much a newbie to understand this. I just don't get a request together i could even try something with. I'm sorry. Maybe there is someone out there who could give me a link for a code snippet how to establish a connection with an telnet server.

Thanks in Advance,
Olli
Posted on 2002-03-21 13:58:57 by Olli
Done. :)

Telnet Sever thread

Good example (but a little confusing) of how to setup a telnet server on a windows machine...

If you get your code to work I'd appreciate it if you could post it :) Never too much network code sources

Sliver
Posted on 2002-03-21 17:54:29 by Sliver
Don't forget to look into terminal emulation.

HTTP doesn't use terminal emulation so all you have to do is send a GET request.
Posted on 2002-03-21 23:48:52 by eet_1024
It's me again,

i don't get it. I read through the rfc's that might give me some information. But i don't know how to realize them in code.
Actually my program is something like a telnet terminal, right ?
Just that it receives normal text and send commands over button clicks. I really need ur help again because i don't understand this telnet protocol.

Edit:
I found this file in the internet, maybe someone could translate it so a newbie like me undestands it.
http://cs.felk.cvut.cz/~marekr2/telnet.asm

I think in the beginning of the code the author assignes numeric codes to the commands like in the rfc's. But i don't understand how he establishes a telnet connection and than handles the data flow.
Posted on 2002-03-22 05:58:31 by Olli
Yes i made it,

for all of us interested in it, u just have to echo the data stream u get from the server to the server. that's it. that gets the connection.
Posted on 2002-03-23 09:45:30 by Olli
Here is a first screenshot. I'm sending all the data streams manually yet and i'm not scanning for LF + CR yet.
Just so u know what it looks like. If someone wants the code mail me. The Final code is gonna be posted here once i finish the whole program. I still need some time for the terminal emulation yet.
Posted on 2002-03-23 13:25:45 by Olli