Sun Java Solaris Communities My SDN Account Join SDN
 
Article

Listing the Names and Order of STREAMS Modules

 
By Rajesh Ramchandani, August 2001  

This note contains a sample program that will enable you to list the names and order of all STREAMS modules pushed on top of a particular device.

This information is for STREAMS device drivers and module developers, and system administrators.

Introduction


In certain circumstances, it is important for Solaris device driver and module developers to identify the names and order of all STREAMS modules that are pushed on top of a particular device. Presently, no command exists to readily obtain this data. However, the following example provides developers with the sample code necessary to generate this information for any particular stream.

Example Code
/* list_mods.c */

#include <stdio.h>
#include <stdlib.h>
#include <sys/stropts.h>

#include <sys/bufmod.h>
#include <fcntl.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>

#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/stropts.h> /* I_LIST */

int printmod(int fd)
{
        struct str_list mod_list;
        struct str_mlist *mlist;
        int mods;
        int msize;
        int i;
        int rc = 0;

        if((mods = ioctl(fd, I_LIST, 0)) < 0){
                perror("I_LIST ioctl");
                return mods;
        }

        if(mods == 0) {
                printf("No modulesn");
                return rc;
        }

        printf("%d modules: ", mods);

        msize = mods * sizeof(struct str_mlist);
        mlist = (struct str_mlist *)calloc(mods, 
          sizeof(struct str_mlist));
        if(mlist == 0){
                printf("malloc failuren");
                return (-1);
        }
        mod_list.sl_modlist = mlist;
        mod_list.sl_nmods = mods;
        if((rc = ioctl(fd, I_LIST, &mod_list)) < 0) {
                perror("I_LIST ioctl fetch");
        } else {
                rc = mods;
                for(i = 0; i < mods; i++) {
                     printf("%s, ", 
                       mod_list.sl_modlist[i].l_name);
                }
                putchar('n');
        }
        return rc;
}


main() 
{
        int fd;
        int val;


        if((fd = open("/dev/hme", O_RDWR)) < 0) {
                perror("open");
                exit(1);
        }

        if (ioctl(fd, I_PUSH, "pfmod") < 0) {
                perror("PUSH");
        }

        if (ioctl(fd, I_PUSH, "bufmod") < 0) {
                perror("PUSH");
        }

        if(( val = printmod(fd)) < 0 ) {
                perror("printmod");
        }
}

strconf(1) and strchg(1) can be used to alter or query the configuration of the stream associated with the user's standard input. The strchg command pushes modules on and pops modules off the stream. The strconf command queries the configuration of the stream. Only the superuser or owner of a STREAMS device may alter the configuration of that stream. This tool provides a programmatic way of listing and modifying the streams given any open devices' file descriptor.

Back to Top