Windows networking woes

The Mingw32 environment is a great thing. It lets me develop an app for Windows on my Linux computers without even having to think about the platform differences – apart from directory separator and stuff like that.
Well, most often. Looks like the Winsock2 API is really, really far off the POSIX way of doing things. First, before even thinking about using the network, you have to issue a special init call:
WSAStartup(MAKEWORD(2,0),&wsaData);

Then, you have to worry about checking your sockets for errors. The POSIX way of this is
if ((sock = connect(…)) < 0), meaning socket numbers are positive. The Winsock2 way is:
if ((sock = connect(…)) == INVALID_SOCKET). More #ifdef ugliness.

At last, when you finally managed to get a connection established, you can try to read() or write() to it. Which gives errors. Better use recv() or send(). Both couple of functions taking almost identical parameters. I must have missed another Windows subtlety concerning this one. I can’t believe it doesn’t work.

And if you want to debug network operations, don’t bother using perror(), use WSAGetLastError(). Have fun with #ifdefs if you want debug on both platforms. I won’t elaborate on the stupid Java-like naming scheme in C files, either; it just gets on my nerves.

Oh yeah, and when you’re done, don’t forget to call the releasing stuff: WSACleanup(). Docs don’t say what happen if you don’t, but this is Windows. Better not irritate the thing.