Solstice X.25 9.2 Developer's Guide

Chapter 13 Sockets Programming Example

This chapter discusses include files and structures, and provides references to example code.


Note -

The sockets-based interface is a source-compatible--not a binary-compatible--interface. Applications that used the socket interface in SunOS 4.x must be recompiled to run on SunOS 5.x. See "13.2 Compilation Instructions and Sample Programs "" for instructions on compiling programs to use the sockets-based interface on SunOS 5.0.


13.1 Include Files for User Programs

Sockets-based Solstice X.25 application programs need to have the following include statements in addition to any standard SunOS system files that may be needed:

#include <sys/iocom.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sundev/syncstat.h>
#include <netx25/x25_pk.h>
#include <netx25/x25_ctl.h>
#include <netx25/x25_ioctl.h>

This is illustrated in the sample programs provided.

13.2 Compilation Instructions and Sample Programs

To use the 7.0 socket interface, user programs should be linked against libsockx25 stored in /opt/SUNWconn/lib. Use the -L option to link the /opt/SUNWconn/lib directory into your program. A program named test can be linked against the socket library as follows:


hostname% cc -o test test.c -L/opt/SUNWconn/lib -lsockx25 -lsocket -lnsl

You can find sample programs for the 7.0 socket interface in /opt/SUNWconn/x25/samples.socket.

13.3 Structures Used by the X25_SET_FACILITY and X25_GET_FACILITY ioctl Commands

The following structures are referenced in "12.7.2 X25_SET_FACILITY/X25_GET_FACILITY ioctls".


Example 13-1 Structures Used by ioctls that Set and Get X.25 Facilities

/* Packet sizes allowed are 0 (default), 16, 32, 64,
  * 128, 256, 512, 1024,2048, 4096
  */

 typedef struct packet_size_s {
    u_short sendpktsize;   
    u_short recvpktsize;
    } PACKET_SIZE;
 /* window sizes allowed are 0:
  * (default), 1-7 (normal), 1-127 (extended)
  */

 typedef struct window_size_s {
    u_char sendwndsize;
    u_char recvwndsize;
 } WINDOW_SIZE;
 /* throughput values allowed are
  *   0 (default), 3 (75) , 4 (150), 5 (300),
  *   6 (600), 7 (1200), 8 (2400), 9 (4800),
  *   10 (9600), 11 (19200), 12 (48000)
  */

 typedef struct throughput_s {
    u_char sendthruput:4;
    u_char recvthruput:4;
 } THROUGHPUT;

 typedef struct cug_s {
    u_char cug_req;
 #define CUG_NONE 0 /* no CUG */
 #define CUG_REQ 1 /* CUG */
 #define CUG_REQ_ACS 2 /* CUG with outgoing access */
 #define CUG_BI 3 /* bilateral CUG */
    u_short cug_index;
 } CUG;

 typedef struct rpoa_s {
    u_char nrpoa;   /* number of RPOAs requested */
 #define MAX_RPOA 3
    u_short rpoa_index[MAX_RPOA]; /* rpoas;
                       nrpoa = 1 => normal format */
 } RPOA;
 /* Zero value for a field means the field is not specified; if a
  * field has zero value, that and the foll. fields are not sent.
  */

 typedef struct ete_tr_delay_s {
    u_short req_delay;
    u_short desired_delay;
    u_short max_delay;
 } ETE_TR_DELAY;

 typedef struct nui_s {
    u_char nui_len; /* NUI length */
 #define MAX_NUI 64
    u_char nui_data[MAX_NUI]    /* NUI */
 } NUI;

 typedef struct charge_info_s {
    u_char charge_len;
 #define MAX_CHARGE_INFO 64
    u_char charge_data[MAX_CHARGE_INFO];
 } CHARGE_INFO;

 typedef struct call_redir_s {
    u_char cr_reason;
    u_char cr_hostlen;
    u_char cr_host[(MAXHOSTADR+1)/2];
 } CALL_REDIR;

 typedef struct aef_s {
    u_char aef_type;
 #define AEF_NONE 0
 #define AEF_NSAP 1
 #define AEF_PARTIAL_NSAP 2
 #define AEF_NON_OSI 3
    u_char aef_len;
 #define MAX_AEF 40
    u_char aef[(MAX_AEF+1)/2];
 } AEF;

 typedef struct precedence_s {
    u_char precedence_req;   /* no precedence when = 0
                                    * else precedence level
                                    */
    u_char precedence;   /* valid when precedence_req = 1 */
 } PRECEDENCE;

 typedef struct private_fact_s {
    u_char p_len; /* total length of facilities */
 #define MAX_PRIVATE 64
    u_char p_fact[MAX_PRIVATE];
 /* facilities exactly as they
  * are present in Call Request or
  * Call Accept packets
  */
 } PRIVATE_FACT;

 typedef struct facility_s {
    u_int type;
 #define T_FACILITIES 0x00000001
 #define T_REVERSE_CHARGE 0x00000002
 #define T_FAST_SELECT_TYPE 0x00000003
 #define T_PACKET_SIZE 0x00000004
 #define T_WINDOW_SIZE 0x00000005
 #define T_THROUGHPUT 0x00000006
 #define T_CUG 0x00000007
 #define T_RPOA 0x00000008
 #define T_TR_DELAY 0x00000009
 #define T_MIN_THRU_CLASS 0x0000000a
 #define T_ETE_TR_DELAY 0x0000000b
 #define T_NUI 0x0000000c
 #define T_CHARGE_REQ 0x0000000d
 #define T_CHARGE_MU 0x0000000e
 #define T_CHARGE_SEG 0x0000000f
 #define T_CHARGE_DUR 0x00000010
 #define T_LINE_ADDR_MOD 0x00000011
 #define T_CALL_REDIR 0x00000012
 #define T_EXPEDITED 0x00000013
 #define T_CALLED_AEF 0x00000014
 #define T_CALLING_AEF 0x00000015
 #define T_STDSERVICE 0x00000016
 #define T_OSISERVICE 0x00000017
 #define T_PRECEDENCE 0x00000018
 #define T_PRIVATE 0x00000019

    union {
       u_intfacilities;/* quick way to check
                                 * if a facility is present
                                 */
 #define F_REVERSE_CHARGE 0x00000001
 #define F_FAST_SELECT_TYPE 0x00000002
 #define F_PACKET_SIZE 0x00000004
 #define F_WINDOW_SIZE 0x00000008
 #define F_THROUGHPUT 0x00000010
 #define F_MIN_THRU_CLASS 0x00000020
 #define F_CUG 0x00000040
 #define F_RPOA 0x00000080
 #define F_TR_DELAY 0x00000100
 #define F_ETE_TR_DELAY 0x00000200
 #define F_NUI 0x00000400
 #define F_CHARGE_REQ 0x00000800
 #define F_CHARGE_MU 0x00001000
 #define F_CHARGE_SEG 0x00002000
 #define F_CHARGE_DUR 0x00004000
 #define F_LINE_ADDR_MOD 0x00008000
 #define F_CALL_REDIR 0x00010000
 #define F_EXPEDITED 0x00020000
 #define F_CALLED_AEF 0x00040000
 #define F_CALLING_AEF 0x00080000
 #define F_STDSERVICE 0x00100000
 #define F_OSISERVICE 0x00200000
 #define F_PRECEDENCE 0x00400000
 #define F_PRIVATE 0x00800000
       u_char reverse_charge;
 /* permit/request reverse charge */
       u_char fast_select_type;
 #define FAST_OFF 0 /* don't use fast select */
 #define FAST_CLR_ONLY 1 /* restricted response */
 #define FAST_ACPT_CLR 2 /* unrestricted response */
                     PACKET_SIZE packet_size; /* packet sizes */
                     WINDOW_SIZE window_size; /* window sizes */
                      THROUGHPUT throughput; /* used for throughput
                            negotiation */
          THROUGHPUT min_thru_class; /* minimum throughput class */
          CUG cug; /* closed user group */
          RPOA rpoa; /* RPOA specification */
          u_short tr_delay; /* network transit delay */
          ETE_TR_DELAY ete_tr_delay; /* end-to-end transit delay */
          NUI nui; /* network user identification */
          u_char charge_req; /* request charging info */
          CHARGE_INFO charge_mu; /* charging info, monetary unit */
          CHARGE_INFO charge_seg; /* charging info, segment */
          CHARGE_INFO charge_dur; /* charging info, call duration */
          u_char line_addr_mod; /* called line addr modified */
          CALL_REDIR call_redir; /* call redirect notification */
          u_char expedited; /* expedited data negotiation */
          AEF called_aef; /* called aef */
          AEF calling_aef; /* calling aef */
          u_char osiservice; /* set when VC carries CLNP data */
          u_char stdservice; /* set for DDN services */
          PRECEDENCE prec; /* precedence for standard services */
          PRIVATE_FACT private; /* non-X.25 local/rem facilities */
       } facility;
 } FACILITY;

 /* Some convenient definitions. */
 #define f_facilities facility.facilities
 #define f_reverse_chargefacility.reverse_charge
 #define f_fast_select_typefacility.fast_select_type
 #define f_packet_size facility.packet_size
 #define f_recvpktsize facility.packet_size.recvpktsize
 #define f_sendpktsize facility.packet_size.sendpktsize
 #define f_window_size facility.window_size
 #define f_recvwndsize facility.window_size.recvwndsize
 #define f_sendwndsize facility.window_size.sendwndsize
 #define f_throughput facility.throughput
 #define f_recvthruput facility.throughput.recvthruput
 #define f_sendthruput facility.throughput.sendthruput
 #define f_min_thru_classfacility.min_thru_class
 #define f_min_recvthruputfacility.min_thru_class.recvthruput
 #define f_min_sendthruputfacility.min_thru_class.sendthruput
 #define f_cug  facility.cug
 #define f_cug_req facility.cug.cug_req
 #define f_cug_index facility.cug.cug_index
 #define f_rpoa  facility.rpoa
 #define f_nrpoa  facility.rpoa.nrpoa
 #define f_rpoa_req facility.rpoa.rpoa_req
 #define f_tr_delay facility.tr_delay
 #define f_ete_tr_delay facility.ete_tr_delay
 #define f_req_delay facility.ete_tr_delay.req_delay
 #define f_desired_delay facility.ete_tr_delay.desired_delay
 #define f_max_delay facility.ete_tr_delay.max_delay
 #define f_nui  facility.nui
 #define f_charge_req facility.charge_req
 #define f_charge_mu facility.charge_mu
 #define f_charge_seg facility.charge_seg
 #define f_charge_dur facility.charge_dur
 #define f_line_addr_mod facility.line_addr_mod
 #define f_call_redir facility.call_redir
 #define f_cr_reason facility.call_redir.cr_reason
 #define f_cr_hostlen facility.call_redir.cr_hostlen
 #define f_cr_host facility.call_redir.cr_host
 #define f_expedited facility.expedited
 #define f_called_aef facility.called_aef
 #define f_cd_aef_type facility.called_aef.aef_type
 #define f_cd_aef_len facility.called_aef.aef_len
 #define f_cd_aef facility.called_aef.aef
 #define f_calling_aef facility.calling_aef
 #define f_cg_aef_type facility.calling_aef.aef_type
 #define f_cg_aef_len facility.calling_aef.aef_len
 #define f_cg_aef facility.calling_aef.aef
 #define f_osiservice facility.osiservice
 #define f_stdservice facility.stdservice
 #define f_prec  facility.prec
 #define f_precedence_reqfacility.prec.precedence_req
 #define f_precedence facility.prec.precedence
 #define f_private facility.private