[B20] porting code from Unix to Windows NT

Donald Sharp sharpd@mindspring.com
Tue Dec 1 22:17:00 GMT 1998

This problem looks like you are having some confusion about what is going
on here.  In the unix code(sun right?) some previous programmer decided 
to call a struct sockaddr_un, SOCKET.  This struct sockaddr_un is used in 
bind, and connect calls to specify who/what/how you want to talk to another
socket.  The socket itself is considered to be a int( do a man on socket ).  
This int is used to identify what actual socket the operating system has
you(you get this from the socket call ).  In the windows world they decided to
call the socket descriptor, that you get back from the socket() call SOCKET.
This is the conflict that you are seeing.  You need to take the 
typedef struct sockaddr_un SOCKET;
code, and make it something like:
typedef struct sockaddr_un SOCKADDR;
Also replacing all occurrences of SOCKET for SOCKADDR.  Test this 
code in unix world to ensure before you move back over to windows.

Also I don't think windows supports the struct sockaddr_un type.  
I would check this out.  If it doesn't I would recommend using the:
struct sockaddr_in in it's place.  If you need examples of how to use
sockets in your code, I would recommend this book:
Unix Network Programming, by W.Richards Stevens ISBN: 0-13-949876-1
It talks about these things at great length.

Don't hesitate to ask me some more questions though if you have
any more questions....

2)  Regular Sockets
At 01:57 PM 11/30/98 +0100, you wrote:
>I'm trying to port some Unix code to Windows Nt with Cygwin tools. My
>problem is that code handles sockets and I can't compile the source.
>I've put #define Win32_winsock and #include 'windows.h' in my source.
>But in my Unix code (somebody else wrote it, not me... I'm novice with
>unix ans C programming) SOCKET is defined like this :
>typedef struct sockaddr_un SOCKET;
>sockaddr_un is defined in sys/un.h like this :
> * definitions for Unix IPC domain.
>#if defined(_SOCKADDR_LEN) || defined(_KERNEL) ||
>struct sockaddr_un {
>    unsigned char sun_len;
>    sa_family_t     sun_family;
>    char sun_path[104];
>struct sockaddr_un {
>    unsigned short  sun_familly;
>    char sun_path[104];
>my unix code uses sun_path and sun_family...
>in Sockets.h (cygwin), SOCKETis defined as an unsigned int
>Did anybody have the same problem ? Can anybody help me ?
>stagiaire projet CODES (INRIA ROCQUENCOURT)
>For help on using this list (especially unsubscribing), send a message to
>"gnu-win32-request@cygnus.com" with one line of text: "help".

For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

More information about the Cygwin mailing list