Solstice X.25 9.2 Developer's Guide

12.8 Routing ioctls

In this section, we describe the ioctls used to manage the Solstice X.25 routing function in the sockets-based interface. The Solstice X.25 routing function is described in detail in Solstice X.25 9.2 Administration Guide. The data structure used for routing is as follows:

typedef struct x25_route_s { 
   uint32_t   index;  
   u_char    r_type;
 #define     R_NONE        0
 #define     R_X121_HOST   1
 #define     R_X121_PREFIX 2
 #define     R_AEF_HOST    3
 #define     R_AEF_PREFIX  4
   CONN_ADR  x121;  
   u_char    pid_len;
 #define     MAX_PID_LEN   4  
   u_char    pid[MAX_PID_LEN];  
   AEF       aef;  
   int       linkid;  
   X25_MACADDR  mac;  
   int       use_count;  
   char      reserved[16];
 } X25_ROUTE;

The following declarations will be used in the code segments used for illustration:

int s, error;
 X25_ROUTE r;

To add a route, set the fields in the X25_ROUTE structure to desired values, and execute the X25_ADD_ROUTE ioctl as follows:

error = ioctl(s, X25_ADD_ROUTE, &r);

To obtain the routing information for a given destination address, set the destination address in the X25_ROUTE structure and execute the X25_GET_ROUTE ioctl:

error = ioctl(s, X25_GET_ROUTE, &r);

To remove a route for a given destination address, set the destination address in the X25_ROUTE structure and execute the X25_RM_ROUTE ioctl:

error = ioctl(s, N_X25_RM_ROUTE, &r);

To flush all routes out, execute the X25_FLUSH_ROUTES ioctl:

error = ioctl(s, X25_FLUSH_ROUTES);

The following code segment illustrates how one may cycle through all the routes configured in the system and obtain the parameters for each of them:

r.index = 0;
 do {  
     error = ioctl(s, X25_GET_NEXT_ROUTE, &r);  
     if (error == 0)    
         /* print the route */;
 while (error == 0);

When there are no routes left, error will be -1, and errno will be set to ENOENT.

The X25_ADD_ROUTE, X25_RM_ROUTE, and X25_FLUSH_ROUTES ioctls require superuser privilege; X25_GET_ROUTE and X25_GET_NEXT_ROUTE do not.