HPlogo HP 9000 Networking: BSD Sockets Interface Programmer's Guide > Chapter 6 Using UNIX Domain Stream Sockets

Preparing Address Variables

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Glossary

 » Index

Before you begin to create a connection, establish the correct variables and collect the information that you need to request a connection.

Your server process needs to:

  • Declare socket address variables.

  • Get the pathname (character string) for the service you want to provide.

Your client process needs to:

  • Declare socket address variables.

  • Get the pathname (character string) for the service you want to use.

These activities are described next. Refer to the program example at the end of this chapter to see how these activities work together.

Declaring Socket Address Variables

You need to declare a variable of type struct sockaddr_un to use for socket addresses. For example, the following declarations are used in the example client program:

struct sockaddr_un myaddr; /* for local socket address  */
struct sockaddr_un peeraddr; /* for peer socket address */

sockaddr_un is a special case of sockaddr and is used with the AF_UNIX address domain .

The sockaddr_un address structure consists of the following fields:

FieldDescription
short sun_familySpecifies the address family and should always be set to AF_UNIX.
u_char sun_path[92]Specifies the pathname to which the socket is bound or will be bound (e.g. /tmp/mysocket).

The server process only needs an address for its own socket. Your client process will not need an address for its own socket.

© 1997 Hewlett-Packard Development Company, L.P.