|
|
Power 6/32 Unix version 1.21
/* D.L.Buck and Associates, Inc. - 8/27/84
*
* COPYRIGHT NOTICE:
* Copyright c 8/27/84 - An unpublished work by
* D.L.Buck and Associates, Inc.
*
* PROPRIETARY RIGHTS NOTICE:
* All rights reserved. This document and program contains
* proprietary information of D.L.Buck and Associates,Inc.
* of San Jose, California, U.S.A., embodying confidential
* information, ideas, and expressions, no part of which
* may be reproduced, or transmitted in any form or by any
* means, electronic, mechanical, or otherwise, without
* the written permission of D.L.Buck and Associates, Inc.
*
* NAME
* bscmon - BISYNC communications monitoring utility
*
* SYNOPSIS
* bscmon [-data] [-host=<hostname>] [file]
* [-dev=<devname>]
*
* DESCRIPTION
* bscmon records trace information from the BISYNC trace device
* (/dev/bsc*tr) while BISYNC communications are taking place.
* Information is recorded either in a data file for processing
* by bsctrace later, or sent to stdout for immediate processing
* by bsctrace via a pipe.
*
* ALGORITHM
* 1. open device for reading
* a. if host specified, read host configuration file for
* device name (name = /dev/<hostdev>tr).
* b. if device specified, open it.
* c. if none specified (or found in host configuration file)
* open /dev/bsctr.
* 2. open data file (if specified). stdout is default.
* 3. while not EOF, read TBUFSIZE bytes from device and put in file or
* stdout.
* 4. close device (and file, if specified).
*/
#include <sys/types.h>
#include "local.h"
#include <bsc/bsctr.h>
#include <stdio.h>
#ifndef lint
static char sccsid[] = "@(#)bscmon.c 1.3 REL";
#endif
#define YES 1
#define NO 0
char pathname[50] = "/usr/lib/bscbatch/"; /* path to host config file */
void exit();
char *strcpy(), *strcat();
main(argc,argv)
int argc;
char *argv[];
{
register unsigned i;
int data = NO; /* should trace include actual data being
sent and received? */
char devname[20]; /* contains trace device name */
char dbuff[TBUFSIZE]; /* trace data is read in here */
char buff[100];
char *fgets(); /* get a line from a file */
FILE *fopen(); /* function opens files */
FILE *fptr; /* file pointer for fopen */
int outfd; /* output file descriptor */
int devfd; /* device file descriptor */
/* set default values */
outfd = 1; /* 1 is stdout's file descriptor */
strcpy(devname,"/dev/bsctr");
/* get options from command line */
for (i=1;i<argc;++i) {
/* if [-data] specified,
* save actual data being sent and received
*/
if (strcmp(argv[i],"-data") == 0)
{ data = YES;
continue; }
/* if [-host=<hostname>] specified, get device name from
host configuration file in lib/bscbatch */
if (strncmp(argv[i],"-host=",6) == 0) {
strcat(pathname,&argv[i][6]);
if ((fptr = fopen(pathname,"r")) == NULL) {
fprintf(stderr,
"bscmon: <%s> has no configuration file\n",
&argv[i][6]);
exit(1); }
while(fgets(buff,sizeof buff,fptr) != NULL)
if (strncmp(buff,"DEVICE=",7) == 0) {
buff[strlen(buff)-1] = '\0';
sprintf(devname,"%str",&buff[7]);
}
fclose(fptr);
continue;
}
/* if [-dev=<devname>] specified,
* get device name from argv[i]
*/
if (strncmp(argv[i],"-dev=",5) == 0) {
strcpy(devname,&argv[i][5]);
continue; }
/* if [file] specified, open it to outptr */
if (argv[i][0] != '-') {
/* create mode 0666 sets this file's read/write
permission for everyone */
if ((outfd = creat(argv[i],0666)) == -1)
{ fprintf(stderr,
"bscmon: can't create <%s>\n",&argv[i]);
exit(1); }
continue;
}
/* bad parameter */
fprintf(stderr,"bscmon: invalid parameter <%s>\n",argv[i]);
exit(1);
}
/* open trace device */
if ((devfd = open(devname,0)) == -1) /* '0' is read only flag */
{ fprintf(stderr,"bscmon: trace device <%s> cannot be opened\n",
devname);
exit(1); }
if (data == YES)
ioctl(devfd,BSC_TRDATA,0);
/* while number of bytes returned isn't 0,
* read data from trace device
*/
while ((i=read(devfd,dbuff,sizeof dbuff)) > 0)
write(outfd,dbuff,i);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.