Results 1 to 5 of 5

Thread: Porting problem: ******* socket code to Linux

  1. #1
    Join Date
    Feb 2006
    Beans
    26

    Porting problem: ******* socket code to Linux

    Hi guys,

    I am porting a massive framework written with MSVC++ to Linux. I'm currently trying to port some socket code over. The original code makes declarations such as SOCKET _socket etc. Looking at SOCKET in MSVC++ I found out that its a struct socket, and is equivalent to the sockaddr_in structure in Linux. Can anyone confirm this?

    Also, the original code occasionally sets a SOCKET to INVALID_SOCKET, which is defined as (SOCKET) (~0). What is this? I was wondering if I can just set the descriptor to -1 instead of this? For example:

    SOCKET _socket = INVALID_SOCKET;

    Any ideas on this? Also, Isn't ******* supposed to be POSIX compliant? I was hoping porting this would be easier.

    Thanks very much for your assistance.

  2. #2
    Join Date
    Oct 2007
    Beans
    1,914
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: Porting problem: ******* socket code to Linux

    Quote Originally Posted by mentallysilent View Post
    Any ideas on this? Also, Isn't ******* supposed to be POSIX compliant? I was hoping porting this would be easier.
    Dunno. You gotta try. BTW, Windows NT/XP *are* Posix compliant. However, you also need to program using the POSIX interface to get the advantange.

  3. #3
    Join Date
    Jul 2008
    Location
    Dublin, Ireland
    Beans
    633
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Porting problem: ******* socket code to Linux

    Quote Originally Posted by mentallysilent View Post
    The original code makes declarations such as SOCKET _socket etc. Looking at SOCKET in MSVC++ I found out that its a struct socket, and is equivalent to the sockaddr_in structure in Linux. Can anyone confirm this?
    I would suggest that you use a portable sockets lib so that you don't run into this same problem in the future. ACE, Boost, Qt, (wxWidgets?) have portable socket libraries.

  4. #4
    Join Date
    Aug 2008
    Location
    Madrid
    Beans
    52

    Re: Porting problem: ******* socket code to Linux

    Have a look here, it explains how to port a sockets app to Windows, you just need to "reverse" the info there:

    http://msdn.microsoft.com/en-us/library/ms740096(VS.85).aspx

  5. #5
    Join Date
    Oct 2005
    Location
    UK
    Beans
    242

    Re: Porting problem: ******* socket code to Linux

    I did some work like this, through much reading of MSDN and the sockets documentation I got a list of differences between Winsocks and POSIX sockets, many are minor, sign differences or type differences.

    • uses closesocket() to close a socket, instead of close().
    • uses an int for the third parameter in bind().
    • uses an int* for the third parameter in accept().
    • defines a SOCKET as unsigned int.
    • socket() returns INVALID_SOCKET(unsigned int) on error, *nix returns -1.
    • connect() returns SOCKET_ERROR(int) on error, *nix returns -1.
    • bind() returns SOCKET_ERROR(int) on error, *nix returns -1.
    • listen() returns SOCKET_ERROR(int) on error, *nix returns -1.
    • accept() returns INVALID_SOCKET(unsigned int) on error, *nix returns -1.
    • select() returns SOCKET_ERROR(int) on error, *nix returns -1.
    • send() returns SOCKET_ERROR(int) on error, *nix returns -1.
    • send() uses an int for the third parameter (length).
    • recv() returns SOCKET_ERROR(int) on error, *nix returns -1.
    • setsockopt() returns SOCKET_ERROR(int) on error, *nix returns -1.
    • uses an const char* for the fourth parameter in setsockopt().
    • ioctlsocket() instead of fcntl(), this returns SOCK_ERROR(int), *nix returns -1.
    • ioctlsocket() has the option as a u_long, fcntl() uses an int.

    Not mentioned, select() on Linux modifies the timeout value to reflect time not slept.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •