Trying to create a socket on windows like this:

SOCKET sock; if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) cout << "socket() error: " << errno << "\n"; 

Included in the body conditions. Conclusion:

socket () error: 34

The code is exactly like that because I wanted to maintain compatibility with Linux. Please tell me what could be wrong

  • strerror(errno) will tell you what's the matter ... - Fat-Zer
  • @ Fat-Zer writes "Result too large", is not clear. Can initialization of a context of WSA be necessary? - sddvxd
  • mda, it doesn't really tell ... really looks like there is no specific initialization ... and by the way, although the implementation of BSD sockets and similar because of small differences in 9 cases out of 10 under win have to write a separate implementation ... - Fat-Zer
  • one
    @ Fat-Zer earned after initialization - sddvxd 1:08 pm

1 answer 1

In MSDN it is written that in case of an error, the function will return INVALID_SOCKET (-1) and an error code can be obtained by calling the WSAGetLastError function.
errno is not exposed. socket is a system function and it knows nothing about errno .

And most likely there is a WSANOTINITIALISED error - the WSANOTINITIALISED is not called.