|
|
1.1 ! root 1: /* D.L.Buck and Associates, Inc. - 8/27/84 ! 2: * ! 3: * COPYRIGHT NOTICE: ! 4: * Copyright c 8/27/84 - An unpublished work by ! 5: * D.L.Buck and Associates, Inc. ! 6: * ! 7: * PROPRIETARY RIGHTS NOTICE: ! 8: * All rights reserved. This document and program contains ! 9: * proprietary information of D.L.Buck and Associates,Inc. ! 10: * of San Jose, California, U.S.A., embodying confidential ! 11: * information, ideas, and expressions, no part of which ! 12: * may be reproduced, or transmitted in any form or by any ! 13: * means, electronic, mechanical, or otherwise, without ! 14: * the written permission of D.L.Buck and Associates, Inc. ! 15: * ! 16: * NAME ! 17: * bscmon - BISYNC communications monitoring utility ! 18: * ! 19: * SYNOPSIS ! 20: * bscmon [-data] [-host=<hostname>] [file] ! 21: * [-dev=<devname>] ! 22: * ! 23: * DESCRIPTION ! 24: * bscmon records trace information from the BISYNC trace device ! 25: * (/dev/bsc*tr) while BISYNC communications are taking place. ! 26: * Information is recorded either in a data file for processing ! 27: * by bsctrace later, or sent to stdout for immediate processing ! 28: * by bsctrace via a pipe. ! 29: * ! 30: * ALGORITHM ! 31: * 1. open device for reading ! 32: * a. if host specified, read host configuration file for ! 33: * device name (name = /dev/<hostdev>tr). ! 34: * b. if device specified, open it. ! 35: * c. if none specified (or found in host configuration file) ! 36: * open /dev/bsctr. ! 37: * 2. open data file (if specified). stdout is default. ! 38: * 3. while not EOF, read TBUFSIZE bytes from device and put in file or ! 39: * stdout. ! 40: * 4. close device (and file, if specified). ! 41: */ ! 42: #include <sys/types.h> ! 43: #include "local.h" ! 44: #include <bsc/bsctr.h> ! 45: #include <stdio.h> ! 46: ! 47: #ifndef lint ! 48: static char sccsid[] = "@(#)bscmon.c 1.3 REL"; ! 49: #endif ! 50: ! 51: #define YES 1 ! 52: #define NO 0 ! 53: ! 54: char pathname[50] = "/usr/lib/bscbatch/"; /* path to host config file */ ! 55: void exit(); ! 56: char *strcpy(), *strcat(); ! 57: ! 58: main(argc,argv) ! 59: int argc; ! 60: char *argv[]; ! 61: { ! 62: register unsigned i; ! 63: int data = NO; /* should trace include actual data being ! 64: sent and received? */ ! 65: char devname[20]; /* contains trace device name */ ! 66: char dbuff[TBUFSIZE]; /* trace data is read in here */ ! 67: char buff[100]; ! 68: char *fgets(); /* get a line from a file */ ! 69: ! 70: FILE *fopen(); /* function opens files */ ! 71: FILE *fptr; /* file pointer for fopen */ ! 72: ! 73: int outfd; /* output file descriptor */ ! 74: int devfd; /* device file descriptor */ ! 75: ! 76: /* set default values */ ! 77: outfd = 1; /* 1 is stdout's file descriptor */ ! 78: strcpy(devname,"/dev/bsctr"); ! 79: ! 80: /* get options from command line */ ! 81: for (i=1;i<argc;++i) { ! 82: /* if [-data] specified, ! 83: * save actual data being sent and received ! 84: */ ! 85: if (strcmp(argv[i],"-data") == 0) ! 86: { data = YES; ! 87: continue; } ! 88: ! 89: /* if [-host=<hostname>] specified, get device name from ! 90: host configuration file in lib/bscbatch */ ! 91: if (strncmp(argv[i],"-host=",6) == 0) { ! 92: strcat(pathname,&argv[i][6]); ! 93: ! 94: if ((fptr = fopen(pathname,"r")) == NULL) { ! 95: fprintf(stderr, ! 96: "bscmon: <%s> has no configuration file\n", ! 97: &argv[i][6]); ! 98: exit(1); } ! 99: ! 100: while(fgets(buff,sizeof buff,fptr) != NULL) ! 101: if (strncmp(buff,"DEVICE=",7) == 0) { ! 102: buff[strlen(buff)-1] = '\0'; ! 103: sprintf(devname,"%str",&buff[7]); ! 104: } ! 105: fclose(fptr); ! 106: continue; ! 107: } ! 108: ! 109: /* if [-dev=<devname>] specified, ! 110: * get device name from argv[i] ! 111: */ ! 112: if (strncmp(argv[i],"-dev=",5) == 0) { ! 113: strcpy(devname,&argv[i][5]); ! 114: continue; } ! 115: ! 116: /* if [file] specified, open it to outptr */ ! 117: if (argv[i][0] != '-') { ! 118: /* create mode 0666 sets this file's read/write ! 119: permission for everyone */ ! 120: if ((outfd = creat(argv[i],0666)) == -1) ! 121: { fprintf(stderr, ! 122: "bscmon: can't create <%s>\n",&argv[i]); ! 123: exit(1); } ! 124: continue; ! 125: } ! 126: ! 127: /* bad parameter */ ! 128: fprintf(stderr,"bscmon: invalid parameter <%s>\n",argv[i]); ! 129: exit(1); ! 130: } ! 131: ! 132: /* open trace device */ ! 133: if ((devfd = open(devname,0)) == -1) /* '0' is read only flag */ ! 134: { fprintf(stderr,"bscmon: trace device <%s> cannot be opened\n", ! 135: devname); ! 136: exit(1); } ! 137: ! 138: if (data == YES) ! 139: ioctl(devfd,BSC_TRDATA,0); ! 140: ! 141: /* while number of bytes returned isn't 0, ! 142: * read data from trace device ! 143: */ ! 144: while ((i=read(devfd,dbuff,sizeof dbuff)) > 0) ! 145: write(outfd,dbuff,i); ! 146: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.