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 Stream Sockets

Preparing Address Variables

Preparing Address Variables
Before you 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.
• Assign a wildcard address.
• Get the port address of the service that you want to provide.
Your client process needs to:
• Declare socket address variables.
• Get the remote host'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 for
socket addresses. For example, the following declarations are used in the
example client program:
struct sockaddr_in myaddr; /* for local socket address
*/
struct sockaddr_in peeraddr; /* for peer 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:
Chapter 2
31

Advertisement

Table of Contents
loading

Table of Contents