Preparing Address Variables; Declaring Socket Address Variables - HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

Using Internet Datagram Sockets

Preparing Address Variables

Preparing Address Variables
Before your client process can make a request of the server process, you
must establish the correct variables and collect the information that you
need about the server process and the service provided.
The server process needs to:
• Declare socket address variables.
• Assign a wildcard address.
• Get the port address of the service that you want to provide.
The client process needs to:
• Declare socket address variables.
• Get the remote server's internet address.
• Get the port address for the service that 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_in to use the
local socket address for both processes. For example, the following
declarations are used in the example client program:
struct sockaddr_in myaddr; /* for local socket address
*/
struct sockaddr_in servaddr; /* for server socket address
*/
sockaddr_in is a special case of sockaddr and is used with the
AF_INET addressing domain. Both types are shown in this chapter, but
sockaddr_in makes it easier to manipulate the internet and port
addresses. Some of the BSD Sockets system calls are declared using a
pointer to sockaddr, but you can also use a pointer to sockaddr_in.
The sockaddr_in address structure consists of the following fields:
88
Chapter 4

Advertisement

Table of Contents
loading

Table of Contents