Link to home
Start Free TrialLog in
Avatar of desktop2
desktop2

asked on

bind() error 10022

s=WSASocket(AF_INET, SOCK_RAW, IPPROTO_TCP, NULL, 0,0);
memset((char *) &sockaddr, 0, sizeof(sockaddr));
sockaddr.sin_family=AF_INET;
sockaddr.sin_port=htons(2222);
sockaddr.sin_addr.s_addr=htonl(INADDR_ANY);
bind(s,(LPSOCKADDR)&sockaddr, sizeof(sockaddr)); // return error 10022 :-(

If I don't bind() socket how can I receive packets? On which port ?
Avatar of Dexstar
Dexstar

@desktop2:

10022 is defined as "WSAEINVAL", which usually means "An invalid argument was supplied.", but if you read the documentation for bind(), it says that it will return that value when "The socket is already bound to an address."

Is there more to your code than just that?

I think the problem may be in the first line, because I reviewed my socket library, and it seems to do what you're doing.  The main difference is that I am SOCK_STREAM instead of SOCK_RAW, 0 for the protocol type.  So try changing it to this line:
     s=WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0,0);

Hope that Helps,
Dex*
Avatar of desktop2

ASKER

Than it will be regular TCP connection...
What I want to do is to receive and handle all packets like SYN, ACK, RST.
It looks like I need to use RAW socket for this task.
ASKER CERTIFIED SOLUTION
Avatar of Dexstar
Dexstar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial