Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting Winsock to Linux Sockets

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

My question is: How easy can I port this over to a Linux implementation?

Are there any pitfalls I should be aware of, and if I simply include the appropriate header files, what sort of things will I have to be sure to handle?

Thanks for any help!

I'd post code but I can't unfortunately due to legal reasons. But, our code does use the following:

WSAStartup(..)
WSACleanup(..)
Socket(..)
sendto(..)
recvfrom(..)
ioctlsocket(..)
setsocketopt(..)
like image 931
Mike Bailey Avatar asked Jan 06 '11 16:01

Mike Bailey


People also ask

Can Winsock run in Linux?

It will depend if you use any windows specific networking functionality or if you're just using mostly the mostly BSD compatible API.

How Winsock is different from Unix socket?

All the usage of the functions in the unix sockets like socket, bind, connect, accept, sned and recv are all the same with WinSock. I think the major difference between WinSock and BSD socket is that WinSock provide the Asynchronous Mode ,Overlapped I/O and IOCP (only for Windows 200x).

Is Winsock UDP or TCP?

Raw sockets allow an application to communicate through protocols other than TCP and UDP such as ICMP. Raw sockets are supported on the AF_INET and AF_INET6 address families with some limitations. This section covers extensions to Winsock that are specific to TCP/IP protocols.

What is Winsock port?

John Savill | Mar 04, 1999. A. Microsoft Proxy Server 2.0 uses UDP port 1745; Proxy Server 1.0 uses port 9321.


1 Answers

Based on that list of functions, things should more or less just work. Add #if _WIN32 around the calls to WSAStartup and WSACleanup (the linux equivalent is to not do anything, the sockets library is initialized automatically).

You also might need some OS-dependent code when setting socket options, some of them are the same, some aren't, and the types might be different.

like image 154
Ben Voigt Avatar answered Oct 02 '22 20:10

Ben Voigt