⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slmon.c

📁 OpenSS7 This the fourth public release of the OpenSS7 Master Package. See README in the release for
💻 C
📖 第 1 页 / 共 4 页
字号:
		fprintf(stdout, " tick");		break;	default:		fprintf(stdout, " [%u]", monconf.sdl.ifclock);		break;	}	fputc('\n', stdout);	fprint_time(stdout);	fprintf(stdout, " # sdl config: ifcoding:");	switch (monconf.sdl.ifcoding) {	case SDL_CODING_NONE:		fprintf(stdout, " none");		break;	case SDL_CODING_NRZ:		fprintf(stdout, " nrz");		break;	case SDL_CODING_NRZI:		fprintf(stdout, " nrzi");		break;	case SDL_CODING_AMI:		fprintf(stdout, " ami");		break;	case SDL_CODING_B6ZS:		fprintf(stdout, " b6zs");		break;	case SDL_CODING_B8ZS:		fprintf(stdout, " b8zs");		break;	case SDL_CODING_HDB3:		fprintf(stdout, " hdb3");		break;	case SDL_CODING_AAL1:		fprintf(stdout, " aal1");		break;	case SDL_CODING_AAL2:		fprintf(stdout, " aal2");		break;	case SDL_CODING_AAL5:		fprintf(stdout, " aal5");		break;	default:		fprintf(stdout, " [%u]", monconf.sdl.ifcoding);		break;	}	fputc('\n', stdout);	fprint_time(stdout);	fprintf(stdout, " # sdl config: ifframing:");	switch (monconf.sdl.ifframing) {	case SDL_FRAMING_NONE:		fprintf(stdout, " none");		break;	case SDL_FRAMING_CCS:		fprintf(stdout, " ccs");		break;	case SDL_FRAMING_CAS:		fprintf(stdout, " cas");		break;	case SDL_FRAMING_SF: /* SDL_FRAMING_D4 */		fprintf(stdout, " sf/d4");		break;	case SDL_FRAMING_ESF:		fprintf(stdout, " esf");		break;	default:		fprintf(stdout, " [%u]", monconf.sdl.ifframing);		break;	}	fputc('\n', stdout);	fprint_time(stdout);	fprintf(stdout, " # sdl config: ifblksize: %u\n", monconf.sdl.ifblksize);	fprint_time(stdout);	fprintf(stdout, " # sdl config: ifleads:");	if (monconf.sdl.ifleads & SDL_LEAD_DTR)		fprintf(stdout, " dtr");	if (monconf.sdl.ifleads & SDL_LEAD_RTS)		fprintf(stdout, " rts");	if (monconf.sdl.ifleads & SDL_LEAD_DCD)		fprintf(stdout, " dcd");	if (monconf.sdl.ifleads & SDL_LEAD_CTS)		fprintf(stdout, " cts");	if (monconf.sdl.ifleads & SDL_LEAD_DSR)		fprintf(stdout, " dsr");	fputc('\n', stdout);	fprint_time(stdout);	fprintf(stdout, " # sdl config: ifbpv: %u\n", monconf.sdl.ifbpv);	fprint_time(stdout);	fprintf(stdout, " # sdl config: ifalarms:");	if (monconf.sdl.ifalarms & SDL_ALARM_RED)		fprintf(stdout, " red");	if (monconf.sdl.ifalarms & SDL_ALARM_BLU)		fprintf(stdout, " blu");	if (monconf.sdl.ifalarms & SDL_ALARM_YEL)		fprintf(stdout, " yel");	if (monconf.sdl.ifalarms & SDL_ALARM_REC)		fprintf(stdout, " rec");	fputc('\n', stdout);	fprint_time(stdout);	fprintf(stdout, " # sdl config: ifrxlevel: %u\n", monconf.sdl.ifrxlevel);	fprint_time(stdout);	fprintf(stdout, " # sdl config: iftxlevel:");	switch (monconf.sdl.iftxlevel) {	case SDL_TXLEVEL_NONE:		fprintf(stdout, " none");		break;	case SDL_TXLEVEL_DSX_133FT:	/* SDL_TXLEVEL_CSU_0DB *//* SDL_TXLEVEL_75OHM_NM */		fprintf(stdout, " dsx(133ft)/csu(0dB)/75ohm(NM)");		break;	case SDL_TXLEVEL_DSX_266FT:	/* SDL_TXLEVEL_120OHM_NM */		fprintf(stdout, " dsx(266ft)/120ohm(NM)");		break;	case SDL_TXLEVEL_DSX_399FT:	/* SDL_TXLEVEL_75OHM_PR */		fprintf(stdout, " dsx(399ft)/75ohm(PR)");		break;	case SDL_TXLEVEL_DSX_533FT:	/* SDL_TXLEVEL_120OHM_PR */		fprintf(stdout, " dsx(533ft)/120ohm(PR)");		break;	case SDL_TXLEVEL_DSX_666FT:	/* SDL_TXLEVEL_75OHM_HRL */		fprintf(stdout, " dsx(666ft)/75ohm(HRL)");		break;	case SDL_TXLEVEL_CSU_8DB:	/* SDL_TXLEVEL_120OHM_HRL */		fprintf(stdout, " csu(8dB)/120ohm(HRL)");		break;	case SDL_TXLEVEL_CSU_15DB:		fprintf(stdout, " csu(15dB)");		break;	case SDL_TXLEVEL_CSU_23DB:		fprintf(stdout, " csu(23dB)");		break;	case SDL_TXLEVEL_MON_0DB:		fprintf(stdout, " mon(0dB)");		break;	case SDL_TXLEVEL_MON_12DB:		fprintf(stdout, " mon(12dB)");		break;	case SDL_TXLEVEL_MON_20DB:	/* SDL_TXLEVEL_MON_26DB *//* SDL_TXLEVEL_MON_30DB */		fprintf(stdout, " mon(20dB)/mon(26dB)/mon(30dB)");		break;	case SDL_TXLEVEL_MON_32DB:		fprintf(stdout, " mon(32dB)");		break;	default:		fprintf(stdout, " [%u]", monconf.sdl.iftxlevel);		break;	}	fputc('\n', stdout);	fprint_time(stdout);	fprintf(stdout, " # sdl config: ifsync: %u\n", monconf.sdl.ifsync);	fprint_time(stdout);	fprintf(stdout, " # sdl config: ifsyncsrc:");	for (i = 0; i < SDL_SYNCS; i++)		fprintf(stdout, " %u", monconf.sdl.ifsyncsrc[i]);	fputc('\n', stdout);}voidoutput_config(void){	show_sl_config();	if (output > 1)		show_sdt_config();	if (output > 1)		show_sdl_config();}intmon_config(void){	if (output > 1)		syslog(LOG_NOTICE, "Reading signalling link options");	ctl.ic_cmd = SL_IOCGOPTIONS;	ctl.ic_timout = 0;	ctl.ic_len = sizeof(monconf.opt);	ctl.ic_dp = (char *) &monconf.opt;	if (ioctl(mon_fd, I_STR, &ctl) < 0) {		syslog(LOG_ERR, "%s: ioctl: SL_IOCGOPTIONS: %m", __FUNCTION__);		mon_exit(1);		return (-1);	}	if (output > 1)		syslog(LOG_NOTICE, "Reading signalling link configuration");	ctl.ic_cmd = SL_IOCGCONFIG;	ctl.ic_timout = 0;	ctl.ic_len = sizeof(monconf.sl);	if (ioctl(mon_fd, I_STR, &ctl) < 0) {		syslog(LOG_ERR, "%s: ioctl: SL_IOCGCONFIG: %m", __FUNCTION__);		mon_exit(1);		return (-1);	}	if (output > 1)		syslog(LOG_NOTICE, "Reading signalling terminal configuration");	ctl.ic_cmd = SDT_IOCGCONFIG;	ctl.ic_timout = 0;	ctl.ic_len = sizeof(monconf.sdt);	if (ioctl(mon_fd, I_STR, &ctl) < 0) {		syslog(LOG_ERR, "%s: ioctl: SDT_IOCGCONFIG: %m", __FUNCTION__);		mon_exit(1);		return (-1);	}	if (output > 1)		syslog(LOG_NOTICE, "Reading signalling data link configuration");	ctl.ic_cmd = SDL_IOCGCONFIG;	ctl.ic_timout = 0;	ctl.ic_len = sizeof(monconf.sdl);	if (ioctl(mon_fd, I_STR, &ctl) < 0) {		syslog(LOG_ERR, "%s: ioctl: SDL_IOCGCONFIG: %m", __FUNCTION__);		mon_exit(1);		return (-1);	}	return (0);}intmon_start(void){	switch (link_state) {	case 0:		if (output > 2)			syslog(LOG_NOTICE, "opening link");		if (mon_open() != (0))			return (-1);		link_state = 1;	case 1:		if (output > 2)			syslog(LOG_NOTICE, "attaching link");		if (mon_attach() != (0))			return (-1);		link_state = 2;	case 2:		if (output > 2)			syslog(LOG_NOTICE, "getting configuration");		if (mon_config() != (0))			return (-1);		link_state = 3;	case 3:		break;	}	return (0);}intmon_stop(void){	switch (link_state) {	case 3:		link_state = 2;	case 2:		if (output > 2)			syslog(LOG_NOTICE, "detaching link");		if (mon_detach() != (0))			return (-1);		link_state = 1;	case 1:		if (output > 2)			syslog(LOG_NOTICE, "closing link");		if (mon_close() != (0))			return (-1);		link_state = 0;	case 0:		break;	}	return (0);}voidmon_enter(void){	if (nomead) {		pid_t pid;		if ((pid = fork()) < 0) {			perror("slmon");			exit(2);		} else if (pid != 0) {			/* parent exits */			exit(0);		}		setsid();	/* become a session leader */		/* for once more for SVR4 */		if ((pid = fork()) < 0) {			perror("slmon");			exit(2);		} else if (pid != 0) {			/* parent exits */			exit(0);		}		/* release current directory */		if (chdir("/") == -1) {			perror("chdir");			exit(2);		}		umask(0);	/* clear file creation mask */		/* rearrange file streams */		fclose(stdin);	}	/* continue as foreground or background */	openlog("slmon", LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_DAEMON);	if (lnkname[0] == '\0')		snprintf(lnkname, sizeof(lnkname), "slmon%d", getpid());	if (nomead || outfile[0] == '\0') {		/* initialize default filename */		if (outfile[0] == '\0')			snprintf(outfile, sizeof(outfile), "%s.out", lnkname);		snprintf(outpath, sizeof(outpath), "%s/%s", outpdir, outfile);		if (output > 1)			syslog(LOG_NOTICE, "Redirecting stdout to file %s", outpath);		fflush(stdout);		if (freopen(outpath, "a", stdout) == NULL) {			syslog(LOG_ERR, "%m");			syslog(LOG_ERR, "Could not redirect stdout to %s", outpath);			mon_exit(2);		}	}	if (nomead || errfile[0] == '\0') {		/* initialize default filename */		if (errfile[0] == '\0')			snprintf(errfile, sizeof(errfile), "%s.err", lnkname);		snprintf(errpath, sizeof(errpath), "%s/%s", outpdir, errfile);		if (output > 1)			syslog(LOG_NOTICE, "Redirecting stderr to file %s", errpath);		fflush(stderr);		if (freopen(errpath, "a", stderr) == NULL) {			syslog(LOG_ERR, "%m");			syslog(LOG_ERR, "Could not redirect stderr to %s", errpath);			mon_exit(2);		}	}	sig_catch();	output_header();	mon_config();	output_config();	syslog(LOG_NOTICE, "Startup complete.");}voidslmon(void){	mon_enter();	if (mon_start() == (0))		while (wait_event(10000) != (-1)) ;	mon_stop();	mon_exit(1);}voidcopying(int argc, char *argv[]){	if (!output)		return;	fprintf(stdout, "\\n\Copyright (c) 2001-2007  OpenSS7 Corporation <http://www.openss7.com/>\n\Copyright (c) 1997-2001  Brian F. G. Bidulock <bidulock@openss7.org>\n\\n\All Rights Reserved.\n\\n\Unauthorized distribution or duplication is prohibited.\n\\n\This software and related documentation is protected by copyright and distribut-\n\ed under licenses restricting its use,  copying, distribution and decompilation.\n\No part of this software or related documentation may  be reproduced in any form\n\by any means without the prior  written  authorization of the  copyright holder,\n\and licensors, if any.\n\\n\The recipient of this document,  by its retention and use, warrants that the re-\n\cipient  will protect this  information and  keep it confidential,  and will not\n\disclose the information contained  in this document without the written permis-\n\sion of its owner.\n\\n\The author reserves the right to revise  this software and documentation for any\n\reason,  including but not limited to, conformity with standards  promulgated by\n\various agencies, utilization of advances in the state of the technical arts, or\n\the reflection of changes  in the design of any techniques, or procedures embod-\n\ied, described, or  referred to herein.   The author  is under no  obligation to\n\provide any feature listed herein.\n\\n\As an exception to the above,  this software may be  distributed  under the  GNU\n\General Public License (GPL) Version 2,  so long as the  software is distributed\n\with, and only used for the testing of, OpenSS7 modules, drivers, and libraries.\n\\n\U.S. GOVERNMENT RESTRICTED RIGHTS.  If you are licensing this Software on behalf\n\of the  U.S. Government  (\"Government\"),  the following provisions apply to you.\n\If the Software is  supplied by the Department of Defense (\"DoD\"), it is classi-\n\fied as  \"Commercial Computer Software\"  under paragraph 252.227-7014 of the DoD\n\Supplement  to the  Federal Acquisition Regulations  (\"DFARS\") (or any successor\n\regulations) and the  Government  is acquiring  only the license rights  granted\n\herein (the license  rights customarily  provided to non-Government  users).  If\n\the Software is supplied to any unit or agency of the Government other than DoD,\n\it is classified as  \"Restricted Computer Software\" and the  Government's rights\n\in the  Software are defined in  paragraph 52.227-19 of the Federal  Acquisition\n\Regulations  (\"FAR\") (or any successor regulations) or, in the cases of NASA, in\n\paragraph  18.52.227-86 of the  NASA Supplement  to the  FAR (or  any  successor\n\regulations).\n\\n\");}voidversion(int argc, char *argv[]){	if (!output)		return;	fprintf(stdout, "\\n\%1$s:\n\    %2$s\n\    Copyright (c) 2003-2007  OpenSS7 Corporation.  All Rights Reserved.\n\\n\    Distributed by OpenSS7 Corporation under GPL Version 2,\n\    incorporated here by reference.\n\\n\    See `%1$s --copying' for copying permission.\n\\n\", argv[0], ident);}voidusage(int argc, char *argv[]){	if (!output)		return;	fprintf(stderr, "\Usage:\n\    %1$s [options] {{-p, --ppa} PPA | {-c, --clei} CLEI}\n\    %1$s {-h, --help}\n\    %1$s {-V, --version}\n\    %1$s {-C, --copying}\n\", argv[0]);}voidhelp(int argc, char *argv[]){	if (!output)		return;	fprintf(stdout, "\\n\Usage:\n\    %1$s [options] {{-p, --ppa} PPA | {-c, --clei} CLEI}\n\    %1$s {-h, --help}\n\    %1$s {-V, --version}\n\    %1$s {-C, --copying}\n\Arguments:\n\    (none)\n\General Options:\n\    -q, --quiet                                 (default: off)\n\        suppress output\n\    -v, --verbose                               (default: off)\n\        increase verbosity of output\n\Command Options:\n\    -p, --ppa PPA\n\        specify PPA of device to monitor        (default: %2$d)\n\    -c, --clei CLEI\n\        specify CLEI of device to monitor       (default: %3$s)\n\    -h, --help\n\        prints this usage information and exits\n\    -V, --version\n\        prints the version and exits\n\    -C, --copying\n\        prints the copying permissions and exits\n\Capture Options:\n\    -d, --daemon                                (default: off)\n\        run in the background as a daemon\n\    -O, --outpdir OUTPDIR                       (default: %4$s)\n\        output directory for capute and errors\n\    -n, --lnkname LNKKNAME                      (default: slmon$$)\n\        link name\n\    -o, --outfile OUTFILE                       (default: ${lnkname}.out)\n\        redirect output to outfile\n\    -l, --logfile LOGFILE                       (default: ${lnkname}.err)\n\        redirect errors to errfile\n\    -f, --cfgfile CFGFILE                       (default: slmon.conf)\n\        configuration file name\n\    -e, --defvice DEVNAME                       (defaule: %5$s)\n\        device name to open\n\", argv[0], ppa, clei, outpdir, devname);}intmain(int argc, char **argv){	int c;	int val;	while (1) {		int option_index = 0;		/* *INDENT-OFF* */		static struct option long_options[] = {			{"daemon",	no_argument,		NULL, 'd'},			{"outpdir",	required_argument,	NULL, 'O'},			{"lnkname",	required_argument,	NULL, 'n'},			{"outfile",	required_argument,	NULL, 'o'},			{"logfile",	required_argument,	NULL, 'l'},			{"cfgfile",	required_argument,	NULL, 'f'},			{"device",	required_argument,	NULL, 'e'},			{"ppa",		required_argument,	NULL, 'p'},			{"clei",	required_argument,	NULL, 'c'},			{"quiet",	no_argument,		NULL, 'q'},			{"verbose",	optional_argument,	NULL, 'v'},			{"help",	no_argument,		NULL, 'h'},			{"version",	no_argument,		NULL, 'V'},			{"copying",	no_argument,		NULL, 'C'},			{NULL,		0,			NULL,  0 }		};		/* *INDENT-ON* */		c = getopt_long(argc, argv, "dO:n:o:l:f:e:p:c:qvhVC?", long_options, &option_index);		if (c == -1)			break;		switch (c) {		case 0:			usage(argc, argv);			exit(2);		case 'd':	/* -d, --daemon */			nomead = 1;			break;		case 'O':	/* -O, --outpdir OUTPDIR */			strncpy(outpdir, optarg, sizeof(outpdir) - 1);			break;		case 'n':	/* -n, --lnkname LNKNAME */			strncpy(lnkname, optarg, sizeof(lnkname) - 1);			break;		case 'o':	/* -o, --outfile OUTFILE */			strncpy(outfile, optarg, sizeof(outfile) - 1);			break;		case 'l':	/* -l, --logfile LOGFILE */			strncpy(errfile, optarg, sizeof(errfile) - 1);			break;		case 'f':	/* -f, --cfgfile CFGFILE */			strncpy(cfgfile, optarg, sizeof(cfgfile) - 1);			break;		case 'e':	/* -e, --device */			strncpy(devname, optarg, sizeof(devname) - 1);			break;		case 'p':	/* -p, --ppa */			if (clei[0] != '\0')				goto bad_option;			if ((val = strtol(optarg, NULL, 0)) < 0)				goto bad_option;			ppa = val;			break;		case 'c':			if (ppa != 0)				goto bad_option;			strncpy(clei, optarg, sizeof(clei) - 1);			break;		case 'q':	/* -q, --quiet */			output -= output > 0 ? 1 : output;			break;		case 'v':	/* -v, --versbose */			if (optarg == NULL) {				output += 1;				break;			}			if ((val = strtol(optarg, NULL, 0)) < 0)				goto bad_option;			output = val;			break;		case 'h':	/* -h, --help */			help(argc, argv);			exit(0);		case 'V':	/* -V, --version */			version(argc, argv);			exit(0);		case 'C':	/* -C, --copying */			copying(argc, argv);			exit(0);		case '?':		default:		      bad_option:			// syntax_error:			if (optind < argc) {				fprintf(stderr, "%s: illegal syntax -- ", argv[0]);				for (; optind < argc; optind++)					fprintf(stderr, "%s ", argv[optind]);				fprintf(stderr, "\n");			}			usage(argc, argv);			exit(2);		}	}	slmon();	exit(4);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -