Local IPC Address Format

A socket address in a local system is composed of three fields in the following sockaddr_un structure: length, address family, and path name. The structure is located in the <SYS\UN.H> header file:

struct sockaddr_un {
    u_char  sun_len;             /* sockaddr len including null */
    u_char  sun_family;          /* AF_OS2 or AF_UNIX */
    char    sun_path[108];       /* path name */
};
struct sockaddr_un un;

The sun_family field is set to AF_OS2 or AF_UNIX.

The sun_path field is the OS/2 Warp file and path name to be used as the address of the Local IPC socket. If the address is NULL, the bind call binds a unique local address to the socket descriptor s. Each address is a combination of address family (sun_family) and a character string (sun_path) no longer than 108 characters.

Each socket must use a unique character string as its local name to bind a name to a socket. The name in sun_path should begin with "\socket\".

For example,

struct sockaddr_un un;
int sd;
sd = socket(PF_OS2, SOCK_STREAM, 0);
memset(&un, 0, sizeof(un);

un.sun_len = sizeof(un);
un.sun_family = AF_OS2;
strcpy(un.sun_path, "\socket\XYZ", 12);
bind(sd, (struct sockaddr *)&un, sizeof(un));


[Back: Getting Started with Sockets Over Local IPC]
[Next: Sockets over NetBIOS]