(RESOLVED thanks tedd)Winsock Error Code: 10038

Started by blackwc, May 06, 2007, 05:28:56 AM

Previous topic - Next topic

blackwc

scan proc uses edi
invoke socket,AF_INET,SOCK_STREAM,0
.if eax != INVALID_SOCKET
mov sock,eax
.else
invoke MessageBox,hwnd,NULL,addr error,MB_ICONERROR
.endif

invoke WSAAsyncSelect,sock,hwnd,WM_SOCKET,FD_CONNECT
.if eax==SOCKET_ERROR
invoke MessageBox,hwnd,NULL,addr error,MB_ICONERROR
.endif

;------------------------------------
invoke GetWindowTextLength,hbox1
inc eax
invoke GetWindowText,hbox1,addr target,eax
;------------------------------------

assume edi:ptr sockaddr_in
mov [edi].sin_family, AF_INET
invoke inet_addr,addr target
mov [edi].sin_addr, eax
invoke htons,80
mov [edi].sin_port,ax

invoke connect,sock,edi,sizeof sockaddr_in
.if eax==SOCKET_ERROR
invoke WSAGetLastError
invoke dwtoa,eax,addr buffer
.if eax != WSAEWOULDBLOCK
invoke MessageBox,hwnd,addr buffer,addr error,MB_ICONERROR
.endif
.else
invoke closesocket,sock
.if eax==SOCKET_ERROR
invoke WSAGetLastError
invoke MessageBox,hwnd,addr target,addr error,MB_OK
.endif
.endif
assume edi:nothing
ret
scan endp


Right around "connect()" it returns 10038.

Which is invalid or corrupt handle, What's wrong with it?

blackwc

Any help would be greatly appreciated...

Tedd

Well you're checking for errors (good!) and displaying error message boxes (good) and then carrying on anyway (not good!!)
If there's an error, then it's not a good idea to continue - you'll only get more errors (such as 10038: WSAENOTSOCK - which means the socket handle you're giving isn't a valid socket handle.)
No snowflake in an avalanche feels responsible.

blackwc

#3
Quote from: Tedd on May 07, 2007, 07:14:15 PM
Well you're checking for errors (good!) and displaying error message boxes (good) and then carrying on anyway (not good!!)
If there's an error, then it's not a good idea to continue - you'll only get more errors (such as 10038: WSAENOTSOCK - which means the socket handle you're giving isn't a valid socket handle.)


I already have some code to stop, but I have a valid handle for the socket.


.data

sock dd ?


Why wouldn't this be valid???

Tedd

Quote from: blackwc on May 07, 2007, 09:32:58 PM
I already have some code to stop, but I have a valid handle for the socket.
Maybe you do, but what you posted here displays a messagebox, and the continues anyway. And how are you sure it's a valid socket handle?
If the code that's causing the error is different from what you posted, then please post the real version.

Quote

.data
sock dd ?

Why wouldn't this be valid???
Well that's fine, but the value stored in it may not be.


It would be more helpful if you can post the full source (trimmed down, if possible, but so it still has the problem) rather than just a function - which might be where the error appears, but may not be where it starts.
No snowflake in an avalanche feels responsible.

blackwc

Sure, no problem...

Here the WM_SOCKET message in the main dialog proc



.elseif eax == WM_COMMAND
mov eax,wParam
and eax,0FFFFh
.if eax == IDC_BUTTON1003
invoke scan
                .endif
.elseif eax == WM_SOCKET
invoke MessageBox,hwnd,NULL,NULL,MB_OK
mov eax,lParam
.if ax == FD_CONNECT
shr eax,16
.if ax == NULL
;
.else
invoke geterror
.endif
.endif


There, but I haven't even got to this point(except for the WM_COMMAND, it executes the scan proc flawlessly) because for some reason, on socket creation it is saying I have an invalid socket handle.

and then there is the scan proc....

scan proc uses edi
invoke socket,AF_INET,SOCK_STREAM,0
.if eax != INVALID_SOCKET
mov sock,eax
.else
invoke MessageBox,hwnd,eax,addr error,MB_ICONERROR
.endif

invoke WSAAsyncSelect,sock,hwnd,WM_SOCKET,FD_CONNECT
.if eax==SOCKET_ERROR
invoke MessageBox,hwnd,eax,addr error,MB_ICONERROR
.endif

;------------------------------------
invoke GetWindowTextLength,hbox1
inc eax
invoke GetWindowText,hbox1,addr target,eax
;------------------------------------

assume edi:ptr sockaddr_in
mov [edi].sin_family, AF_INET
invoke inet_addr,addr target
mov [edi].sin_addr, eax
invoke htons,80
mov [edi].sin_port,ax

invoke connect,sock,edi,sizeof sockaddr_in
.if eax==SOCKET_ERROR
invoke WSAGetLastError
.if eax != WSAEWOULDBLOCK
invoke geterror
jmp @
.endif
.else
invoke closesocket,sock
.if eax==SOCKET_ERROR
invoke geterror
jmp @
.endif
.endif
@:
assume edi:nothing
ret
scan endp



Oh.... And here is my quick geterror hack..

geterror proc uses edi
assume edi:DWORD
invoke dwtoa,eax,edi
invoke MessageBox,hwnd,edi,addr error,MB_ICONERROR
assume edi:nothing
Ret
geterror EndP




ToutEnMasm

Hello,
You must verify that you have got the good socket,it can be another socket that you haven't to deal with


.ELSEIF uMsg== WM_SOCKET
;invoke MessageBox,NULL,ADDR wanadoo,addr wanadoo,MB_OK
; instal by WSAAsyncSelect
mov edx,wParam ;socket number
.if edx != paramail.IDsock             ;is it the same ?
;Bad socket,don't made anything
jmp endWM_SOCKET
.endif
HIWORD lParam ;error code
mov edx,eax
LOWORD lParam ;events

.IF    eax == FD_CONNECT   ;The socket is successfully connected

blackwc

Quote from: ToutEnMasm on May 08, 2007, 06:28:33 PM
Hello,
You must verify that you have got the good socket,it can be another socket that you haven't to deal with


.ELSEIF uMsg== WM_SOCKET
;invoke MessageBox,NULL,ADDR wanadoo,addr wanadoo,MB_OK
; instal by WSAAsyncSelect
mov edx,wParam ;socket number
.if edx != paramail.IDsock             ;is it the same ?
;Bad socket,don't made anything
jmp endWM_SOCKET
.endif
HIWORD lParam ;error code
mov edx,eax
LOWORD lParam ;events

.IF    eax == FD_CONNECT   ;The socket is successfully connected



none of that worked... It didn't even assembled...

It said

error A2006: undefined symbol : IDsock

ToutEnMasm

Hello,
It is only a sample,you must used your own names of variables.

When connecting the socket


.data
IDsocket dd 0
.code

invoke socket, PF_INET, SOCK_STREAM,0
.if eax == INVALID_SOCKET
Winsock ShowError,SADR ("socket") ; why did the socket creation fail?
jmp FindeConnectSocket
.endif
mov paramail.IDsock,eax  ;or IDsocket


paramail.IDsock  is a structure where to place the socket number returned by the API socket,you can use another dword like IDsocket.

                                   ToutEnMasm

Winhelp

Quote
Value returned by socket

If no error occurs, socket returns a descriptor referencing the new socket. Otherwise, a value of INVALID_SOCKET is returned, and a specific error code can be retrieved by calling WSAGetLastError.


blackwc

I know all of that, but I don't think that is my problem...

I am pretty sure my problem is in the scan proc...

No errors occure in WM_SOCKET... at all... I it won't even go past the error in the scan proc to display a message box in WM_SOCKET, because it won't use the DWORD 'sock' for some reason it says it is invalid...

Tedd

Help us to help you -- post FULL code = the whole program.
No snowflake in an avalanche feels responsible.

ecube

try this code as it supports both a host or an ip, your current one only supports an ip, other than that everything looks fine at a glance.


invoke inet_addr,addr target
  .if eax==INADDR_NONE
invoke gethostbyname,addr target
cmp eax,NULL
je @Error
mov eax, [eax + 12]
mov eax, [eax]
mov eax, [eax]
.endif
mov [edi].sin_addr,eax


rest of code...

@Error:


P1

Quote from: blackwc on May 09, 2007, 06:06:41 PMI am pretty sure my problem is in the scan proc...
Because your posted code is incomplete.  Maybe your not aware of that.

Error Codes for Socket
WSANOTINITIALISED   A successful WSAStartup must occur before using this function.


Where is ...
invoke WSAStartup,101h,addr lpWSAdata

If I get my hand bit, your on your own.   :boohoo:

Regards,  P1  :8)

blackwc

Quote from: P1 on May 09, 2007, 09:54:09 PM
Quote from: blackwc on May 09, 2007, 06:06:41 PMI am pretty sure my problem is in the scan proc...
Because your posted code is incomplete.  Maybe your not aware of that.

Error Codes for Socket
WSANOTINITIALISED   A successful WSAStartup must occur before using this function.


Where is ...
invoke WSAStartup,101h,addr lpWSAdata

If I get my hand bit, your on your own.   :boohoo:

Regards,  P1  :8)

I'm sorry, I really am. I don't mean to come over as if I am biting your hands...

But all I am saying is that I am 100% positive that the error is in the scan proc... If you guys don't know that's fine... I will go through with this on my own...

by the way, My WSAStartup was successful.

P.S.

I am hesitant to post my code, it's a port scanner, but I don't want people to think I am using this for any misdeeds, mainly for myself to test my boxes, I am trying to speed this scan up as fast as I can to get it done, also enabling a port range to scan my network.

I don't really know what the law is here for port scanners, or if you consider them all that insidious.

blackwc

Quote from: E^cube on May 09, 2007, 07:15:19 PM
try this code as it supports both a host or an ip, your current one only supports an ip, other than that everything looks fine at a glance.


invoke inet_addr,addr target
  .if eax==INADDR_NONE
invoke gethostbyname,addr target
cmp eax,NULL
je @Error
mov eax, [eax + 12]
mov eax, [eax]
mov eax, [eax]
.endif
mov [edi].sin_addr,eax


rest of code...

@Error:




Thanks for the code snippet, but I already had a proc with that exact snippet, I had to clean it up for assemble though.

namely,

"mov eax, [eax + 12]"

to

mov eax, (hostent ptr [eax]).h_list