It looks like in my XP is something intercepting all socket function calls and change all the created sockets to nonblocking mode.

what can i do with accept when it is in nonblocking mode?

how can I check the queue with all hosts which are waiting for connection?

I tryed to test Client.sin_addr i test it with 0 but it does not work...

Please help me in my trouble:
fasm syntax:


include '%fasminc%/win32ax.inc'
sleep fix invoke Sleep,200
printf fix cinvoke pf
system fix invoke sys
INVALID_SOCKET = 0

.data

;strin variable
ServName rb 20h
ServIp rb 10h
ClientName rb 20h
ClientIp rb 10h
RemoteServName rb 20h
RemoteServIp rb 10h
ClientAsServName rb 20h
ClientAsServIp rb 10h
;structures data
wsa WSADATA
Serv sockaddr_in
Client sockaddr_in
RemoteServ sockaddr_in
ClientAsServ sockaddr_in
;digital network data
sServ dd ? ;socket
sClientAsServ dd ? ;socket
sClient dd ? ;socket
IPServ dd ? ;IP
IPClient dd ? ;IP
IPRemoteServ dd ? ;IP
ServPort dd 80 ;port
RemoteServPort dd 80 ;port
LocaClientPort dd ? ;port
RemoteClientPort dd ? ;port
;suppor data
hTHR dd ?
E db 13,10,0
hSCR dd ? ; handle to console
pf dd ? ; printf
sys dd ? ; system
crtdll dd ? ; handle to crtdll.dll
bufor rb 40h
lllll db "programista.org",0
.code

start:
invoke lstrcat,RemoteServName,lllll

CONSOLE_INIT:

invoke AllocConsole
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [hSCR],eax

LOAD_FUNC_CRT:

invoke LoadLibrary,"crtdll"
mov [crtdll],eax
invoke GetProcAddress,eax,"printf"
mov [pf],eax
invoke GetProcAddress,[crtdll],"system"
mov [sys],eax
system, "color 2a"
printf,"Tunelling Server v0.1 AGP%s",E
sleep
WSA_INIT:
invoke WSAStartup,202h,wsa
cmp eax,0
jne blad
printf,"network interface activated . . .%s",E
sleep
invoke gethostname,ServName,20h
printf,"Server name is: %s%s",ServName,E
sleep
invoke gethostbyname,ServName
virtual at eax
h hostent
end virtual
mov ebx,[h.h_addr_list]
mov ebx,[ebx]
mov ebx,[ebx]
mov [IPServ],ebx
invoke inet_ntoa,ebx
invoke lstrcat,ServIp,eax
printf,"IP: %s%s",ServIp,E
system,"ipconfig"
printf,"remote host named %s testing . . .%s",RemoteServName,E
sleep
invoke gethostbyname,RemoteServName

mov ebx,[h.h_addr_list]
mov ebx,[ebx]
mov ebx,[ebx]
mov [IPRemoteServ],ebx
invoke inet_ntoa,ebx
invoke lstrcat,RemoteServIp,eax
printf,"%s:IP %s%s",RemoteServName,RemoteServIp,E
sleep
invoke lstrcat,bufor,"ping "
invoke lstrcat,bufor,lllll
;system,bufor
mov eax,2
mov[Serv.sin_family],ax
mov[Client.sin_family],ax
mov[ClientAsServ.sin_family],ax
mov[RemoteServ.sin_family],ax
invoke htons,[ServPort]
mov [Serv.sin_port],ax

TUNELING:
invoke socket,2,1,0
mov [sServ],eax
cmp eax,INVALID_SOCKET
je blad
printf,"soket opened at:0x%x%s",[sServ],E
sleep
invoke bind,[sServ],Serv,16
cmp eax,0
jne blad
invoke listen,[sServ],8
cmp eax,0
jne blad
ACCEPT:
invoke ioctlsocket,[sServ],'f',0
invoke closesocket,[sClient]
invoke accept,[sServ],Client,16
cmp eax,INVALID_SOCKET
je ACCEPT
mov [sClient],eax
; mov eax,[Client.sin_addr] <-----this place i tryed to solve the problem
; cmp eax,0
; je ACCEPT
invoke MessageBox,0,0,0,0

invoke CreateThread,0,0,NewClient,0,0,0
mov [hTHR],eax
invoke closesocket,[sClient]
invoke CloseHandle,[hTHR]


FREE_ALL:

invoke WSACleanup
system,"pause"
invoke ExitProcess,0
blad:
invoke WSAGetLastError
printf,"IA ERROR: %d !!!",eax
system,"color 4c"
call FREE_ALL
system,"pause"
invoke ExitProcess,0

NewClient:
invoke inet_ntoa,[Client.sin_addr]
movzx ebx,[Client.sin_port]
printf,"succesful connected !!! %s%:x%s",eax,ebx,E
invoke ExitThread,0


.end start
Posted on 2005-01-20 08:11:28 by etn
Either change the socket to Blocking by using Select(), or keep it as NonBlocking and use Event notification via WSAEventSelect (and then WSAWaitForMultipleEvents and WSAEnumNetworkEvents inside a loop).

Second way is much nicer especially for a threaded application as you can put all your Server stuff inside one Thread, and maybe use other threads for other stuff. Especially nice to not have any Window Messages, and suits you because you have no Window :D

Happy coding :)
Posted on 2005-01-20 08:28:50 by Homer
the best 4 U! works fine:) thank You.
Posted on 2005-01-20 09:00:40 by etn


include '%fasminc%/win32ax.inc'
sleep fix invoke Sleep,200
printf fix cinvoke pf
system fix invoke sys
INVALID_SOCKET = 0

.data

;strin variable
ServName rb 20h
ServIp rb 10h
ClientName rb 20h
ClientIp rb 10h
RemoteServName rb 20h
RemoteServIp rb 10h
ClientAsServName rb 20h
ClientAsServIp rb 10h
;structures data
wsa WSADATA
Serv sockaddr_in
Client sockaddr_in
RemoteServ sockaddr_in
ClientAsServ sockaddr_in
;digital network data
sServ dd ? ;socket
sClientAsServ dd ? ;socket
sClient dd ? ;socket
IPServ dd ? ;IP
IPClient dd ? ;IP
IPRemoteServ dd ? ;IP
ServPort dd 80 ;port
RemoteServPort dd 80 ;port
LocaClientPort dd ? ;port
RemoteClientPort dd ? ;port
;suppor data
fd_s rd 68
hTHR dd ?
E db 13,10,0
hSCR dd ? ; handle to console
pf dd ? ; printf
sys dd ? ; system
crtdll dd ? ; handle to crtdll.dll
bufor rb 400h
lllll db "programista.org",0
dlug_cl dd ?
.code

start:
invoke lstrcat,RemoteServName,lllll

CONSOLE_INIT:

invoke AllocConsole
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [hSCR],eax

LOAD_FUNC_CRT:

invoke LoadLibrary,"crtdll"
mov [crtdll],eax
invoke GetProcAddress,eax,"printf"
mov [pf],eax
invoke GetProcAddress,[crtdll],"system"
mov [sys],eax
system, "color 2a"
printf,"Tunelling Server v0.1 AGP%s",E
sleep
WSA_INIT:
invoke WSAStartup,101h,wsa
cmp eax,0
jne blad
printf,"network interface activated . . .%s",E
sleep
invoke gethostname,ServName,20h
printf,"Server name is: %s%s",ServName,E
sleep
invoke gethostbyname,ServName
virtual at eax
h hostent
end virtual
mov ebx,[h.h_addr_list]
mov ebx,[ebx]
mov ebx,[ebx]
mov [IPServ],ebx
invoke inet_ntoa,ebx
invoke lstrcat,ServIp,eax
printf,"IP: %s%s",ServIp,E
system,"ipconfig"
printf,"remote host named %s testing . . .%s",RemoteServName,E
sleep
invoke gethostbyname,RemoteServName

mov ebx,[h.h_addr_list]
mov ebx,[ebx]
mov ebx,[ebx]
mov [IPRemoteServ],ebx
invoke inet_ntoa,ebx
invoke lstrcat,RemoteServIp,eax
printf,"%s:IP %s%s",RemoteServName,RemoteServIp,E
sleep
invoke lstrcat,bufor,"ping "
invoke lstrcat,bufor,lllll
;system,bufor
mov eax,2
mov[Serv.sin_family],ax
mov[Client.sin_family],ax
mov[ClientAsServ.sin_family],ax
mov[RemoteServ.sin_family],ax
invoke htons,[ServPort]
mov [Serv.sin_port],ax

TUNELING:

invoke socket,2,1,6
mov [sServ],eax
cmp eax,INVALID_SOCKET
je blad
invoke ioctlsocket,[sServ],
printf,"soket opened at:0x%x%s",[sServ],E
sleep
invoke bind,[sServ],Serv,16
cmp eax,0
jne blad
invoke listen,[sServ],8
cmp eax,0
jne blad
ACCEPT:
mov [fd_s],1
mov eax,[sServ]
mov [fd_s+4],eax
invoke select,1,fd_s,NULL,NULL,0

invoke accept,[sServ],Client,0
cmp eax,INVALID_SOCKET
je blad
mov [sClient],eax
printf,"connected!!!%s",E

;invoke getpeername,[sClient],Client,dlug_cl ;-> gives me the BUG 10014
; cmp eax,0 ; without those 3 lines it works almost fine
; jne blad ;*******************************************
movzx eax,[Client.sin_port]
invoke htons,eax
push eax
mov eax,[Client.sin_addr]
invoke inet_ntoa,eax
pop ebx
printf,"adres:%s%sport:%S%S",eax,E,ebx,E
mov [fd_s],1
mov eax,[sClient]
mov [fd_s+4],eax
goahead:
invoke select,1,fd_s,NULL,NULL,0
invoke recv,[sClient],bufor,3ffh,0
cmp eax,-1
je blad
cmp eax,0
jne skip

printf,"this is the end my only friend-The End%s",E
jmp blad
skip:
invoke _lwrite,[hSCR],bufor,eax
;printf,"%s",E

jmp goahead





invoke closesocket,[sClient]
invoke CloseHandle,[hTHR]

;invoke Sleep,200000
FREE_ALL:

invoke WSACleanup
system,"pause"
invoke ExitProcess,0
blad:
invoke WSAGetLastError
printf,"IA ERROR: %d !!!",eax
system,"color 4c"
call FREE_ALL
system,"pause"
invoke ExitProcess,0


.end start


another broblema...
what should i do?
I can not retrive IP and port number connected to peer socket...
Posted on 2005-01-25 07:58:15 by etn
#1 - getpeername doesn't get the peer's domain name string, it gets the peer's sockaddr_in structure which you already get during "accept" (see #3)

#2 - the last param of "getpeername" is the sizeof the second parameter, ie, sizeof sockaddr_in

#3 - after calling "accept", the remote peer's ip address is in the sockaddr_in structure given in the call to "accept" which in your case is called "Client", so the call to "getpeername" becomes unnecessary.

#4 - having retrieved the peer's ip address, resolve it to a name string if that's what you want by calling "gethostbyaddr"
Posted on 2005-01-26 22:29:54 by Homer
In my situation accept sucks,
it did not fill in the sockaddr_in...
why?
I don't know why....
so I tryed to get the structure by getpeername.

I do know nothin about a Client so gethostbyname is unuseful too.

how this is possible that the getpeername gives me error 10014 ?

Take care EvilHommer2k!
I'm waiting for news from You.

etn
Posted on 2005-01-27 04:27:57 by etn
10014 : The system detected an invalid pointer address in attempting to use a pointer argument of a call. This error occurs if an application passes an invalid pointer value, or if the length of the buffer is too small. For instance, if the length of an argument which is a struct sockaddr is smaller than sizeof(struct sockaddr).

Look closer at the params for getpeername.

Also, after calling accept, you should find the remote users ip in Client.sin_addr as a DWORD :)
Posted on 2005-01-29 02:18:30 by Homer