I have read prior post on the forum but I came up with few specific questions about Porting Unix Socket(hereby calling it BSD socket) to Win32 Platform :

First of all, I am a native Linux C/C++ Programmer. I program in Ubuntu with GCC.
But, I usually also port my application to Win32. For that, I use the MinGW Port of GCC. I never have troubles, as I just need to compile my apps on a Windows Box with MinGW installed and I am on a go.

I don't use a IDE but a Text editor/Command Line combo.

In Linux, we have easy access to sys/socket.h, which is BSD socket library.
So, I never had trouble to program sockets on Linux.
But now, I need to port all those to Windows.
Ofcourse, I will use MinGW.
I tried to compile my simplest of the Socket Programing App on MinGW, but got the error of not having sys/socket.h.
I checked my header files in the MinGW include directory, but seriously there was no socket.h in the /sys/ directory.
Ofcourse, I could use VC++ or some other compiler and use the Winsok API(winsock.h) instead. But I dont want to use that since it will have me do a lot of conditional compiling(to make my app, platform independent) which I don't like.

Now here are my queries:
Can I just copy paste my /sys/socket.h from my Linux Box and paste it on the /sys/ of MInGW directory of the Window Box and use it at is it.
If not, what are the possible options I have so that I could use the BSD Socket(sys/socket.h) instead of WinSockets(winsock.h) apart from using any third-party libraries and header files like Boost's or ACE
Now, I read Beej's Tutorial and it says that, had I been using Cygwin, I would not experience any problem and my code will compile as it is in the Windows Box too. But personally, I prefer MinGW because it gives me freedom to use without depending from any run-time DLL.
Also, do tell me if any of you guys have written a C++ Wrapper Class of Socket which will work on Unix as well as Windows. Although, if the above problem is solved, then I would be able to use SocketCC, which is a wrapper class for Unix.

Though, it may be noted that Winsock and BSD Socket have nearly same routines, but I would prefer to use sys/socket.h since I don't wanna go in WSA() thing.

Thank You

> Can I just copy paste my /sys/socket.h from my Linux Box and paste it on the /sys/ of MInGW directory
Nope, not at all.
You also need the .lib. Since that's compiled for a different architecture and OS, chances are it wouldn't even link, and has much less chance of running.

> But personally, I prefer MinGW because it gives me freedom to use without depending from any run-time DLL.
But you also sacrifice the comfortable magic which cygwin offers to give you an environment which is far more unix-like.
It's a choice, but you need to decide on your priority.

> but I would prefer to use sys/socket.h since I don't wanna go in WSA() thing.
Unfortunately, if you want to avoid too many dependencies, there's no real getting away from having to deal with the real thing at the bottom of the call hierarchy.

> But I dont want to use that since it will have me do a lot of conditional compiling(to make my app,
> platform independent) which I don't like.
If you implement a wrapper class, then only ONE file should contain all the WSA stuff, and conditional code.

Capturing your interfaces at the right level can really make or break your portability efforts. Done well, it's a breeze. Done badly, and it's a disaster.

Comments
top draw

First of all, thank you very much for such a decent reply.

I thought GNU provide everything open source, so can I get source code of socket.h(I mean the definition file) from them and probably compile it with MinGW?

See, I may be sounding as if I am desperate to use the sys/socket.h for all my socket apps even at win32. The point is, that I am really desperate to use it.

I don't want to go to cygwin because I am in a conception/misconception that I cannot develop non-free propertied software in cygwin, Plus I will have a burden to ship cygwin.dll with every app that I make.

So, for me, cygwin is a complete no-no.

If you have any other alternative, please let me know.

From your reply, it seems the only option left is to make a wrapper class and do all the dirty work in it(like conditional compiling etc.) and then use it for both Unix and win32.

> so can I get source code of socket.h(I mean the definition file)
> from them and probably compile it with MinGW?
You might, but I'm pretty sure you'll find an OS in the way before you get down to the wires.
Then you'll be back in the same spot you're in at the moment, only at a lower level.

I found this - http://www.libsdl.org/projects/SDL_net/
I've no idea if it does what you want, but it seems to run on what you want.

I want to use the low leveled BSD socket API in windows.
I searched a lot and now I am up.
I guess conditional compiling and wrapping my class is the best I can do.
I simply(though it is not so simple) want a way to use the BSD sockets in windows without using cygwin.(as in cygwin u can create apps with restricted lisense)

This question has already been answered. Start a new discussion instead.