i've got a lil' q. i haven't read any tutorial about winsock programming, i was satisfied w/ api reference. but one thing is unclear to me:

how to listen to some specific port (let it be 123) and accept the connection.

i know i have to use bind/listen/accept, but could someone provide a working code snippet ? thank you
Posted on 2002-10-03 11:22:40 by kahuna
Port_t db "123",0

.data?
wsadata WSADATA <>
sin sockaddr_in <>
sock dd ?

.code
start:

.
.
.
invoke WSAStartup,101h,ADDR wsadata
.IF eax==NULL
invoke socket,AF_INET,SOCK_STREAM,0
.IF eax!=INVALID_SOCKET
mov sock,eax
invoke atodw,ADDR Port_t
invoke htons,eax
mov sin.sin_port,ax
mov sin.sin_family,AF_INET
mov sin.sin_addr,INADDR_ANY
invoke bind,sock,ADDR sin,SIZEOF sin
.IF eax!=SOCKET_ERROR
AcceptLoop:
invoke listen,sock,SOMAXCONN
invoke accept,sock,NULL,NULL
.IF eax==INVALID_SOCKET
jmp AcceptLoop
.ENDIF
;Accept +OK
.ENDIF
.ENDIF
.ENDIF
Posted on 2002-10-04 11:18:48 by hamed_hhz



Port_t equ 123

.data?
wsadata WSADATA <>
sin sockaddr_in <>
sock dd ?

.code
start:

.
.
.
invoke WSAStartup,101h,ADDR wsadata
.IF eax==NULL
invoke socket,AF_INET,SOCK_STREAM,0
.IF eax!=INVALID_SOCKET
mov sock,eax
;invoke atodw,ADDR Port_t
invoke htons,Port
mov sin.sin_port,ax
mov sin.sin_family,AF_INET
mov sin.sin_addr,INADDR_ANY
invoke bind,sock,ADDR sin,SIZEOF sin
.IF eax!=SOCKET_ERROR
AcceptLoop:
invoke listen,sock,SOMAXCONN
invoke accept,sock,NULL,NULL
.IF eax==INVALID_SOCKET
jmp AcceptLoop
.ENDIF
;Accept +OK
.ENDIF
.ENDIF
.ENDIF



No need of atodw :)
Posted on 2002-10-04 11:36:03 by Axial
.data
Port_t db "123",0

.data?
wsadata WSADATA <>
sin sockaddr_in <>
sock dd ?

.code
start:

.
.
.
invoke WSAStartup,101h,ADDR wsadata
.IF eax==NULL
invoke socket,AF_INET,SOCK_STREAM,0
.IF eax!=INVALID_SOCKET
mov sock,eax
invoke atodw,ADDR Port_t
invoke htons,eax
mov sin.sin_port,ax
mov sin.sin_family,AF_INET
mov sin.sin_addr,INADDR_ANY
invoke bind,sock,ADDR sin,SIZEOF sin
.IF eax!=SOCKET_ERROR
AcceptLoop:
invoke listen,sock,SOMAXCONN
invoke accept,sock,NULL,NULL
.IF eax==INVALID_SOCKET
jmp AcceptLoop
.ENDIF
;Accept +OK
.ENDIF
.ENDIF
.ENDIF

it needs to atodw beacause Port_t is Text and it isn't "Port" variable.
isn't it?
:)
Posted on 2002-10-04 12:14:45 by hamed_hhz
THANK YOU GUYS ! (i'll just have to translate it to tasm syntax :))
Posted on 2002-10-04 13:27:04 by kahuna