Porting Winsock to Linux Sockets

I have a program that makes some networks using Winsock, and one of our requirements now is to port our program to Linux. The only thing stopping us from doing this is Winsock.

My question is: how easy is it to port this to a Linux implementation?

Are there any pitfalls I should know about, and if I just include the appropriate header files, what things should I handle?

Thanks for any help!

I would post the code, but I cannot, unfortunately, for legal reasons. But our code uses the following:

WSAStartup(..)
WSACleanup(..)
Socket(..)
sendto(..)
recvfrom(..)
ioctlsocket(..)
setsocketopt(..)
+5
source share
4 answers

, - , Windows, API, BSD.

, - - Winsock API, , BSD , winsock ifdef ...

: http://tangentsoft.net/wskfaq/articles/bsd-compatibility.html

+6

, . #if _WIN32 WSAStartup WSACleanup ( Linux , ).

- OS- , , , .

+8

, , WSA *.

WSAStartup() → nop WSACleanup() → nop

Socket/setsockopt → socket/setsockopt

* nix , setsockopt, .

ioctlsocket → ioctl

* nix select().

---- , , Win95 winsock ----

Unfortunately, since the original socket () in Winsock was broken in some cases, you probably used WSASocket () and therefore need to convert these calls.

+3
source

Without seeing the code, it's hard to say how simple it is. But you should be able to replace winsock calls with counterparts in sys / sockets.h.

0
source

All Articles