Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
*** New wrinkle - Another programmer at my work has no problem with this code. However, he appears to have a different version of WS2_32.lib than I do. My WS2_32.lib seems to be an older version than what he has. I cannot find anything online regarding versions of WS2_32.lib. Does anyone have any ideas that might shed some light on this issue? ***

C#
#include <winsock2.h>

int main(int argc, char **argv) 
{
int		ver=2, rev=2, retval;
WORD		wVersionRequested = MAKEWORD(ver,rev);
WSADATA		wsaData;
SOCKET		listen_socket;

    retval = WSAStartup(wVersionRequested,&wsaData);

// retval returns with a value of 0
// wsaData.wVersion has LOBYTE and HIBYTE = ver and rev (which are both = 2)

    listen_socket = socket(AF_INET, SOCK_STREAM, 0);

// listen_socket returns with a value of -1

    if (listen_socket == INVALID_SOCKET)
    {
        m = WSAGetLastError();
    }

// m = 10022 which is "invalid argument". 
// At this point, I am officially bewildered.
}


running on Windows 7
using Visual Studio 2008 Pro Edition
changing 3rd socket parameter from 0 to IPPROTO_TCP did not alter the outcome
This is the entire program.

Any answers, theories or wild guesses will be appreciated
Posted
Updated 1-Jul-14 10:24am
v6
Comments
[no name] 30-Jun-14 20:28pm    
Try explicitly setting the protocol.
[no name] 30-Jun-14 20:46pm    
BTW, your code works perfectly fine for me, Windows 7 & VS2010
jeron1 1-Jul-14 11:23am    
Wild guess, try adding IPPROTO_TCP as the third parameter in the socket() call.
[no name] 1-Jul-14 13:35pm    
Try a different NIC.
tom_delorenzo 1-Jul-14 16:54pm    
Not sure how to try a different NIC. Others at work had no problem with this code but do have versions of WS2_32.lib that appear to be newer than mine. Any idea if that is an avenue worth pursuing?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900