Take the 2-minute tour ×

I'm attempting to port a Linux application to Windows. The application isn't too complex, using all fairly standard code, with few external dependencies. The main dependencies are libelf (which compiles fine under mingw), pthreads (there appears to be a win32 version available), and sockets. The main problem is with sockets...Windows provides WinSock, but this is not 100% compatible with BSD (Berkeley) sockets as used by all *nixes. What I'm wondering is, has anybody written a wrapper on windows that exposes a BSD socket API, but calls Winsock on the backend, to ease porting?

share|improve this question
add comment

2 Answers

I would recommend using cygwin.dll . It's built for bringing over *nixes to windows including sockets, file IO, etc.

share|improve this answer
I'd like to avoid cygwin if possible, there's a ton of downsides to using it. This app compiles fine in mingw32 except for sockets, and BSD sockets are fairly similar to winsock, so my thoughts are that a wrapper converting between them wouldn't be too complex, and that this might be something that already exists –  davr Dec 21 '09 at 4:47
Yes, cygwin does come with some "baggage". The source code does implement the wrapper in question. Though you'd be surprised how close Winsock2.h is to BSD (most cases). From getting rid of compiler errors stand point, a wrapper may seem ok. But the extra layer may not be worth given how easy the port is. I did a port almost a decade a go and from what I recall it took next to no time, and mostly find/replaceAll process. MS has a guide on it, you've probably seen: msdn.microsoft.com/en-us/library/ms738562(VS.85).aspx –  MandoMando Dec 21 '09 at 16:47
add comment

For the most part, you'll just have to make sure that WSAStartup() and WSACleanup() are called at start and end, otherwise, basic BSD sockets will translate pretty well. You could create some static global variable that gets checked for each call to the socket calls, and call WSAStartup() and WSACleanup() accordingly. As for poll() ... well, it translates quite easily to select().

share|improve this answer
Thanks for the tips, I guess they are somewhat helpful. But I was more hoping someone had already written the code for me so I didn't have to implement all these small fixes to get it working. –  davr Jun 27 '10 at 4:37
add comment

Your Answer


