There is a copy of this code sample in the /opt/SUNWconn/x25/samples.stats directory.
The steps for writing this kind of program are:
Include the streams and X.25 header files.
Specify the location of the X.25 devices file descriptor.
Define a structure for containing the statistics.
In the example these are per-link X.25 statistics.
Open the X.25 driver.
Define the fields required by the ioctl(s) you are using.
In the example, this is N_getlinkstats, which retrieves per link X.25 statistics.
Specify where you want to gather statistics from.
For example, N_getlinkstats requires you to give a link number.
Gather the statistics.
How you do this depends on which ioctls you are using.
Display, or otherwise make use of, the statistics that have been gathered.
/************************************************************ * Copyright 20 Apr 1995 Sun Microsystems, Inc. All Rights Reserved * * This example shows how to open X25 driver, * get X25 per_link statistics, * and display (as an example) the number of transmit and * received CALL packets. * * Many more information are available for X25 through this ioctl. * Many other ioctls permit to get : * - Global stats for : IXE, X25 packet layer protocol, LAPB, LLC2, and MLP * - Per-link stats for : X25, LAPB, LLC2 and MLP * - Per-VC stats * Some other ioctls permit to reset those statistics. * ************************************************************/ /* * General includes for streams */ #include <fcntl.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/stropts.h> #include <sys/stream.h> /* * the following includes are specific to X25 */ #include <netx25/uint.h> #include <netx25/x25_proto.h> #include <netx25/x25_control.h> /* * location of x25 device file descriptor */ #define X25_DEV "/dev/x25" /* used to open X25 device */ int x25_fd; /* * io control structure used for all stream ioctl * see STREAM programmer's guide for more information about this structure. */ struct strioctl ioc; /* * this structure to be used to collect X25 per-link stats */ struct perlinkstats x25_s; main() { /* * open x25 driver */ x25_fd = open(X25_DEV, O_RDONLY); if (x25_fd == -1) { perror("Failed to access X25 driver.\n"); exit(1); } /* * set the general info for ioctl */ ioc.ic_cmd = N_getlinkstats; ioc.ic_len = sizeof(x25_s); ioc.ic_dp = (char *) &x25_s; /* * Set the link id. * Specify the link number where to gather statistics. * (2 in that particular case) */ x25_s.linkid = 2; /* * perform the STREAMS ioctl */ if (ioctl(x25_fd, I_STR, &ioc) < 0) { perror("Failed to gather X25 per-link statistics"); exit(2); } /* * display some statistics */ printf("X25 statistics for link number 2\n"); printf("Number of CALL transmitted %10ld\n", x25_s.mon_array[cll_out_s]); printf("Number of CALL received %10ld \n", x25_s.mon_array[cll_in_s]); }