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(..)
It will depend if you use any windows specific networking functionality or if you're just using mostly the mostly BSD compatible API.
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).
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.
John Savill | Mar 04, 1999. A. Microsoft Proxy Server 2.0 uses UDP port 1745; Proxy Server 1.0 uses port 9321.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With