Solstice X.25 9.2 Developer's Guide

12.3.10 Accessing the Local and Remote Addresses

Once a connection is established, the calling and called sides may use the getsockname and getpeername calls to obtain the local and remote X.121 addresses:

int s, error;
 CONN_DB local;       /* local address */
 int local_len;       /* local address length */
 CONN_DB remote;      /* remote address */
 int remote_len;      /* remote address length */

 /* get local address */
 local_len = sizeof(local);
 error = getsockname(s, &local, &local_len);

 /* get remote address */
 remote_len = sizeof(remote);
 error = getpeername(s, &remote, &remote_len);

The local and remote addresses can also be obtained using the X25_RD_LOCAL_ADR and X25_RD_REMOTE_ADR ioctl calls:

int s, error;
 CONN_ADR local;       /* local address */
 CONN_ADR remote;      /* remote address */

 /* get local address */
 error = ioctl(s, X25_RD_LOCAL_ADR, &local);

 /* get remote address */
 error = ioctl(s, X25_RD_REMOTE_ADR, &remote);

Note that for getsockname and getpeername, the CONN_DB structure is used, and for the ioctl calls, the CONN_ADR structure is used. In both cases, the host field will contain the address in packed BCD format, and the hostlen field will contain the address length in BCD digits.

For the called side, the remote address will be defined only after the connection is complete. The remote address obtained using either of the above two methods will be exactly as obtained from the Incoming Call packet. After the call is established, the local address (obtained by either method) will be exactly as received in the called address field in the Incoming Call packet.

For the calling side, the remote address will be exactly as specified in the connect call. If the ANY_LINK bit was set in the hostlen field, it will be also set when it is read by the user using either of the above methods. The source address for the calling side will be either a zero-length address (indicating that the appropriate link address was used), or exactly what the user specified using the X25_WR_LOCAL_ADR ioctl call (including the SUBADR_ONLY bit if it is used).