/* * @(#)mods.c v1.0 Rob Thomas * mods.c - A tool to query and POP modules from a STREAM * Loosely based on some anonymous STREAMS code * The optional -c flag will attempt to POP the module closest * to the STREAM head. * usage: mods [-c] * Example: foo# mods /dev/le */ #include #include #include #include #include #include int main(int argc, char **argv) { int nmod, loop, fd, opt, pop=0; struct strioctl str; struct str_list list; while ((opt = getopt(argc, argv, "c")) != -1) { switch(opt) { case 'c': pop++; break; } } if (pop > 0) { fd = open(argv[2], O_RDWR); } else { fd = open(argv[1], O_RDWR); } if (fd < 1) { perror("open"); exit(1); } nmod = ioctl(fd, I_LIST, (caddr_t)NULL); if (nmod < 0) { perror("mod query"); exit(3); } printf("The number of modules on %s is %d\n", argv[1], nmod); list.sl_nmods = nmod; list.sl_modlist = (struct str_mlist *) malloc(nmod * sizeof(struct str_mlist)); if (ioctl(fd, I_LIST, &list) < 0) { perror("list query"); exit(5); } printf("Modules on %s:\n", argv[1]); for (loop=0; loop < nmod; loop++) { printf("mod %d = %s\n", loop, list.sl_modlist[loop].l_name); } if (pop > 0) { printf("Attempting an I_POP at the STREAM head..."); if (ioctl(fd, I_POP, 0) != 0) { perror("pop"); exit(7); } printf("\n"); } exit(0); }