flat assembler
Message board for the users of flat assembler.

Index > Windows > winsock help

Author
Thread Post new topic Reply to topic
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis
Hi, I've got one to help me with a example in masm, and so I tryed to translate it, but it doesn't work Sad Its a very basic one, open a connection to 127.0.0.1 and send a message to it...

Code:
include '%fasminc%\win32ax.inc'
.data
wsaData WSADATA
sock dd 0
sin sockaddr_in
web db '127.0.0.1',0
hello db 'hello world',0
.code
start:
invoke WSAStartup,0101h,wsaData
invoke socket,AF_INET,SOCK_STREAM,0
mov dword[sock],eax
invoke htons,25
mov word[sin.sin_port],ax
mov word[sin.sin_family],AF_INET
invoke gethostbyname,web
cmp eax,0
je notexist
mov eax,[eax+12]
mov eax,[eax]
mov eax,[eax]
mov dword[sin.sin_addr],eax
invoke lstrlen,sin
invoke connect,sock,sin,eax
invoke lstrlen,hello
invoke send,sock,hello,eax,0
invoke ExitProcess,0
notexist:
invoke MessageBox,0,'That Host Not Exist','404 Error',0
RET
.end start    
    



.... Any idea's?

_________________
LOOOL
Post 20 Feb 2005, 12:17
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis
anybody?
Post 21 Feb 2005, 19:34
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Code:
include '%fasminc%\win32ax.inc'
.data
wsaData WSADATA
sock dd 0
sin sockaddr_in
web db '127.0.0.1',0
hello db 'hello world',0
.code
start:
invoke WSAStartup,0101h,wsaData
invoke socket,AF_INET,SOCK_STREAM,0
mov dword[sock],eax
invoke htons,25
mov word[sin.sin_port],ax
mov word[sin.sin_family],AF_INET
invoke gethostbyname,web
cmp eax,0
je notexist
mov eax,[eax+12]
mov eax,[eax]
mov eax,[eax]
mov dword[sin.sin_addr],eax
invoke lstrlen,sin
invoke connect, sock,sin,eax   ; sockaddr_in is not a string!!! use sizeof.sockaddr_in instead.
invoke lstrlen,hello
invoke send, sock, hello,eax,0
invoke ExitProcess,0
notexist:
invoke MessageBox,0,'That Host Not Exist','404 Error',0
RET
.end start    
    


Also, check whether you want to use "sock" (address of the variable "sock") or "[sock]" - content of this variable, that is socket handle.

Also in most places you simply don't need "dword" prefix before the variables (like in "mov dword [sock], eax") - FASM can determine the size of the variables.

Also, please, format your source more carefully. How you expect help, if the reader can't read the source?

Regards
Post 21 Feb 2005, 20:44
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis
Thanks, it worked! nice my first winsock app, its just lol, need to know something about server now.... Very Happy

_________________
LOOOL
Post 22 Feb 2005, 18:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.