HPlogo X25/9000: X.25/9000 Programmer's Guide > Chapter 3  Establishing and Terminating a Socket Connection

Connection Establishment for the Client Process

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

This section discusses the system calls which the client process must make to establish an SVC with a server process. There are two mandatory steps:

  1. Create a socket using the socket() call.

  2. Make a connection request using the connect() call.

These steps are described below.

Creating a Socket

This is similar to the server process, the client process must also use the socket() call to create a BSD IPC socket (communications endpoint). The socket must be created before the connect() call is executed.

For a client, the socket() call and its parameters are identical to those used by the server when it creates a socket. See "Syntax for socket()" above.

The socket descriptor for the newly-created socket should be included in the connect() system call, and (after the connection is established) in all subsequent data transmission.

Refer to the socket(2) entry in your man pages for more information.

Requesting a Connection

The client process requests a connection with the connect() call. The server must be prepared to service a CALL INDICATION packet (with an active listen socket) when connect() is executed.

The client process specifies the X.121 address, subaddress, and protocol ID of the server with which it wants to establish an SVC with the connect() call. HP does not provide a programmatic method for obtaining this addressing information. It must be acquired from an authority associated with the remote host. When a connect() system call is issued, X.25 sends a CALL REQUEST packet with the specified addressing information.

Syntax for connect()

The connect() system call and its parameters are described below.

#include <sys/types.h>
#include <x25/x25addrstr.h>
#include <sys/socket.h>
int err;
int sd;
struct x25addrstr to_addr;
int to_addrlen;
err = connect(sd, &to_addr, to_addrlen);
sd

The socket descriptor returned by a previous socket() system call. It must use the AF_CCITT address family.

to_addr

The x25addrstr structure containing the local interface to be used in the call, as well as the X.121 address and subaddress of the remote server process with which the client process will establish an SVC.

to_addrlen

Contains the length of the x25addrstr struct (in bytes) which is pointed to by to_addr.

err

If the call successfully completes, err contains 0. If the system call encountered an error, -1 is returned in err, and errno contains the error number.

The connect() call transmits a CALL REQUEST packet and blocks the process until the connection is ready (unless you specify nonblocking mode).

If you place a call by issuing connect() on a socket which is nonblocking, your process will not block. Your request will return EINPROGRESS. This means that the process of connecting to the remote system has been initiated.

If your host system is connected to more than one X.25 interface and those interfaces do not have equal connectivity, you must specify the x25ifname field of the x25addstr structure. That field designates which interface must be used for the connection. If your system has only one interface, it is not necessary to designate the x25ifname field.

If the x25ifname field is null, the connect () call sends outbound packets to the first initialized interface by default.

NOTE: The first initialized interface is the one that is first initialized when the sub-system is restarted after all cards are stopped.

You can use the x25ifname field to control performance. Each interface used to connect to a particular network can only support a fixed number of circuits. When selecting the network interface you should also consider bandwidth, throughput, and response-time factors.

NOTE: Facilities such as call user data, or (the circuit's D bit) must be specified before issuing the connect() call. Facilities are specified with the ioctl(X25_WR_FACILITIES), and call user data is specified with ioctl(X25_WR_USER_DATA). The D bit can be set with the ioctl(X25_SEND_TYPE). These ioctl() calls are described in the following chapters.

If the client and server are using protocol IDs for address matching, prior to issuing the connect() call, the client must specify the server's protocol ID with the ioctl(X25_WR_USER_DATA) call (see “The ioctl(X25_WR_USER_DATA) Call”). The example below describes how to use ioctl(X25_WR_USER_DATA) to specify a remote protocol ID.

Example (client specifying the protocol ID)

The example below shows the system calls that a client must execute if the protocol ID is to be specified in the CALL REQUEST packet.

/* put the protocol ID in the call-user data field */
struct x25_userdata userdata;
...
userdata.x25_cud_len = 1; /* one byte for PID */
userdata.x25_cu_data[0] = 0x05; /*PID is 0x05 */
result = ioctl(s, X25_WR_USER_DATA, &userdata);
...
result = connect (s, &peeraddr, sizeof(struct x25addrstr));

Refer to the connect(2) entry in your man pages for more information.