I am porting linux app under win32 (msvc 9.0) and after finally finishing it, I’m experiencing non-default behavior on simple things as socket().
#include <winsock2.h>
#include <ws2tcpip.h>
int main(int argc, char **argv)
{
int subsock;
if ((subsock = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) {
printf("Failed to open socket (ret value = %d)\n", subsock);
}
}
This prints Failed to open socket (ret value = -1) every time. What is wrong and how to open socket on win32?
You need to call WSAStartup to initialize winsock before subsequent socket calls will succeed.
For more details:
http://msdn.microsoft.com/en-us/library/ms742213%28VS.85%29.aspx
Just request version 2.2 and be done with it.