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

📄 ss7capd.c

📁 OpenSS7 This the fourth public release of the OpenSS7 Master Package. See README in the release for
💻 C
📖 第 1 页 / 共 3 页
字号:
	fprintf(stderr, ",%u", capconf.sdl.ifsyncsrc[2]);	fprintf(stderr, ",%u", capconf.sdl.ifsyncsrc[3]);	fprintf(stderr, "\n");}voidshow_sdt_config(void){	fprintf(stderr, "\tt8: %u\n", capconf.sdt.t8);	fprintf(stderr, "\tTin: %u\n", capconf.sdt.Tin);	fprintf(stderr, "\tTie: %u\n", capconf.sdt.Tie);	fprintf(stderr, "\tT: %u\n", capconf.sdt.T);	fprintf(stderr, "\tD: %u\n", capconf.sdt.D);	fprintf(stderr, "\tTe: %u\n", capconf.sdt.Te);	fprintf(stderr, "\tDe: %u\n", capconf.sdt.De);	fprintf(stderr, "\tUe: %u\n", capconf.sdt.Ue);	fprintf(stderr, "\tN: %u\n", capconf.sdt.N);	fprintf(stderr, "\tm: %u\n", capconf.sdt.m);	fprintf(stderr, "\tb: %u\n", capconf.sdt.b);	fprintf(stderr, "\tf:");	switch (capconf.sdt.f) {	case SDT_FLAGS_ONE:		fprintf(stderr, " one\n");		break;	case SDT_FLAGS_SHARED:		fprintf(stderr, " shared\n");		break;	default:		fprintf(stderr, " %u\n", capconf.sdt.f);		break;	}}/*  *  The capture device is enabled in SDT mode.  We do no want to see so many *  FISUs and LSSUs, we are only really interested in MSUs. */intcap_config(void){	capconf.opt.pvar = SS7_PVAR_ITUT_96;	capconf.opt.popt = 0;	if (output > 1)		syslog(LOG_NOTICE, "Setting link configuration");	ctl.ic_cmd = SDL_IOCSOPTIONS;	ctl.ic_timout = 0;	ctl.ic_len = sizeof(capconf.opt);	ctl.ic_dp = (char *) &capconf.opt;	if (ioctl(cap_fd, I_STR, &ctl) < 0) {		syslog(LOG_ERR, "%s: ioctl: SDL_IOCSOPTIONS: %m", __FUNCTION__);		cap_exit(1);		return CAP_FAILURE;	}	if (output > 1)		syslog(LOG_NOTICE, "Reading link configuration");	ctl.ic_cmd = SDL_IOCGOPTIONS;	ctl.ic_timout = 0;	ctl.ic_len = sizeof(capconf.opt);	ctl.ic_dp = (char *) &capconf.opt;	if (ioctl(cap_fd, I_STR, &ctl) < 0) {		syslog(LOG_ERR, "%s: ioctl: SDL_IOCSOPTIONS: %m", __FUNCTION__);		cap_exit(1);		return CAP_FAILURE;	}	/* defaults will do */	if (output > 1)		syslog(LOG_NOTICE, "Reading link configuration");	ctl.ic_cmd = SDL_IOCGCONFIG;	ctl.ic_timout = 0;	ctl.ic_len = sizeof(capconf.sdl);	ctl.ic_dp = (char *) &capconf.sdl;	if (ioctl(cap_fd, I_STR, &ctl) < 0) {		syslog(LOG_ERR, "%s: ioctl: SDL_IOCGCONFIG: %m", __FUNCTION__);		cap_exit(1);		return CAP_FAILURE;	}	if (output > 2)		show_sdl_config();	/* these are the only two things we affect at this level */	capconf.sdl.iftype = iftype;	capconf.sdl.ifrate = ifrate;	if (output > 1)		syslog(LOG_NOTICE, "Setting link configuration");	ctl.ic_cmd = SDL_IOCSCONFIG;	ctl.ic_timout = 0;	ctl.ic_len = sizeof(capconf.sdl);	ctl.ic_dp = (char *) &capconf.sdl;	if (ioctl(cap_fd, I_STR, &ctl) < 0) {		syslog(LOG_ERR, "%s: ioctl: SDL_IOCSCONFIG: %m", __FUNCTION__);		cap_exit(1);		return CAP_FAILURE;	}	capconf.sdt.N = 16;	capconf.sdt.m = 272;	capconf.sdt.t8 = 10;	capconf.sdt.Tin = 4;	capconf.sdt.Tie = 1;	capconf.sdt.T = 64;	capconf.sdt.D = 256;	capconf.sdt.Te = 577169;	capconf.sdt.De = 9308000;	capconf.sdt.Ue = 144292000;	capconf.sdt.b = 8;	capconf.sdt.f = 0;	if (output > 1)		syslog(LOG_NOTICE, "Setting link configuration");	ctl.ic_cmd = SDT_IOCSCONFIG;	ctl.ic_timout = 0;	ctl.ic_len = sizeof(capconf.sdt);	ctl.ic_dp = (char *) &capconf.sdt;	if (ioctl(cap_fd, I_STR, &ctl) < 0) {		syslog(LOG_ERR, "%s: ioctl: SDT_IOCSCONFIG: %m", __FUNCTION__);		cap_exit(1);		return CAP_FAILURE;	}	if (output > 1)		syslog(LOG_NOTICE, "Reading link configuration");	ctl.ic_cmd = SDL_IOCGCONFIG;	ctl.ic_timout = 0;	ctl.ic_len = sizeof(capconf.sdl);	ctl.ic_dp = (char *) &capconf.sdl;	if (ioctl(cap_fd, I_STR, &ctl) < 0) {		syslog(LOG_ERR, "%s: ioctl: SDL_IOCGCONFIG: %m", __FUNCTION__);		cap_exit(1);		return CAP_FAILURE;	}	if (output > 2)		show_sdt_config();	/* defaults will do */	return CAP_SUCCESS;}/*  *  We only start the DAEDR (receive) for monitoring.  We leave the *  transmitters disabled. */intcap_monitor(void){	union SDT_primitives *d = (union SDT_primitives *) cbuf;	int ret;	ctrl.maxlen = sizeof(cbuf);	ctrl.len = sizeof(d->daedr_start_req);	ctrl.buf = cbuf;	d->daedr_start_req.sdt_primitive = SDT_DAEDR_START_REQ;	if ((ret = putmsg(cap_fd, &ctrl, NULL, RS_HIPRI)) < 0) {		syslog(LOG_ERR, "%s: putmsg: %m", __FUNCTION__);		cap_exit(1);		return CAP_FAILURE;	}#if 0	ctrl.maxlen = sizeof(cbuf);	ctrl.len = sizeof(d->daedr_start_req);	ctrl.buf = cbuf;	d->daedr_start_req.sdt_primitive = SDT_DAEDT_START_REQ;	if ((ret = putmsg(cap_fd, &ctrl, NULL, RS_HIPRI)) < 0) {		syslog(LOG_ERR, "%s: putmsg: %m", __FUNCTION__);		cap_exit(1);		return CAP_FAILURE;	}#endif	/* start requests are not acknowledged */	return CAP_SUCCESS;}intcap_disable(void){	union LMI_primitives *p = (union LMI_primitives *) cbuf;	int ret;	ctrl.maxlen = sizeof(cbuf);	ctrl.len = sizeof(p->disable_req);	ctrl.buf = cbuf;	p->disable_req.lmi_primitive = LMI_DISABLE_REQ;	if ((ret = putmsg(cap_fd, &ctrl, NULL, RS_HIPRI)) < 0) {		syslog(LOG_ERR, "%s: putmsg: %m", __FUNCTION__);		cap_exit(1);		return CAP_FAILURE;	}	/* start requests are not acknowledged */	return CAP_SUCCESS;}intcap_detach(void){	union LMI_primitives *p = (union LMI_primitives *) cbuf;	int ret;	ctrl.maxlen = sizeof(cbuf);	ctrl.len = sizeof(p->detach_req);	ctrl.buf = cbuf;	p->detach_req.lmi_primitive = LMI_DETACH_REQ;	if ((ret = putmsg(cap_fd, &ctrl, NULL, RS_HIPRI)) < 0) {		syslog(LOG_ERR, "%s: putmsg: %m", __FUNCTION__);		cap_exit(1);		return CAP_FAILURE;	}	/* start requests are not acknowledged */	return CAP_SUCCESS;}intcap_close(void){	close(cap_fd);	return CAP_SUCCESS;}intcap_start(void){	switch (link_state) {	case 0:		if (output > 2)			syslog(LOG_NOTICE, "opening link");		if (cap_open() != CAP_SUCCESS)			return CAP_FAILURE;		link_state = 1;	case 1:		if (output > 2)			syslog(LOG_NOTICE, "attaching link");		if (cap_attach() != CAP_SUCCESS)			return CAP_FAILURE;		link_state = 2;	case 2:		if (output > 2)			syslog(LOG_NOTICE, "configuring link");		if (cap_config() != CAP_SUCCESS)			return CAP_FAILURE;		link_state = 3;	case 3:		if (output > 2)			syslog(LOG_NOTICE, "enabling link");		if (cap_enable() != CAP_SUCCESS)			return CAP_FAILURE;		link_state = 4;	case 4:		if (output > 2)			syslog(LOG_NOTICE, "monitoring on link");		if (cap_monitor() != CAP_SUCCESS)			return CAP_FAILURE;		link_state = 5;	case 5:		break;	}	return CAP_SUCCESS;}intcap_stop(void){	switch (link_state) {	case 5:	case 4:		if (output > 2)			syslog(LOG_NOTICE, "disabling link");		if (cap_disable() != CAP_SUCCESS)			return CAP_FAILURE;		link_state = 3;	case 3:		link_state = 2;	case 2:		if (output > 2)			syslog(LOG_NOTICE, "detaching link");		if (cap_detach() != CAP_SUCCESS)			return CAP_FAILURE;		link_state = 1;	case 1:		if (output > 2)			syslog(LOG_NOTICE, "closing link");		if (cap_close() != CAP_SUCCESS)			return CAP_FAILURE;		link_state = 0;	}	return CAP_SUCCESS;}voidcap_enter(void){	if (nomead) {		pid_t pid;		if ((pid = fork()) < 0) {			perror("ss7cap");			exit(2);		} else if (pid != 0) {			/* parent exits */			exit(0);		}		setsid();	/* become a session leader */		/* fork once more for SVR4 */		if ((pid = fork()) < 0) {			perror("ss7cap");			exit(2);		} else if (pid != 0) {			/* parent exits */			exit(0);		}		/* release current directory */		if (chdir("/") == -1) {			perror("ss7cap");			exit(2);		}		umask(0);	/* clear file creation mask */		/* rearrange file streams */		fclose(stdin);	}	/* continue as foreground or background */	openlog("ss7capd", LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_DAEMON);	if (lnkname[0] == '\0')		snprintf(lnkname, sizeof(lnkname), "ss7cap%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);			cap_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);			cap_exit(2);		}	}	sig_catch();	output_header();	syslog(LOG_NOTICE, "Startup complete.");}voidss7cap(void){	cap_enter();	if (cap_start() == CAP_SUCCESS)		while (wait_event(10000) != CAP_FAILURE) ;	cap_stop();	cap_exit(1);}intmain(int argc, char **argv){	int c, val;	while (1) {#if defined _GNU_SOURCE		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'},			{"card",	required_argument,	NULL, 'c'},			{"span",	required_argument,	NULL, 's'},			{"slot",	required_argument,	NULL, 't'},			{"ds0a",	no_argument,		NULL, 'a'},			{"ds0",		no_argument,		NULL, '0'},			{"quiet",	no_argument,		NULL, 'q'},			{"debug",	optional_argument,	NULL, 'D'},			{"verbose",	optional_argument,	NULL, 'v'},			{"help",	no_argument,		NULL, 'h'},			{"version",	no_argument,		NULL, 'V'},			{"copying",	no_argument,		NULL, 'C'},			{"?",		no_argument,		NULL, 'H'},			{NULL,		0,			NULL,  0 }		};		/* *INDENT-ON* */		c = getopt_long(argc, argv, "dO:n:o:l:f:c:s:t:qD::v::hVC?W:", long_options,				&option_index);#else				/* defined _GNU_SOURCE */		c = getopt(argc, argv, "dO:n:o:l:f:c:s:t:qDvhVC?");#endif				/* defined _GNU_SOURCE */		if (c == -1) {			break;		}		switch (c) {		case 0:			usage(argc, argv);			exit(2);		case 'd':	/* -d, --daemon */			if (debug)				fprintf(stderr, "%s: selecting daemon mode\n", argv[0]);			nomead = 1;			break;		case 'O':	/* -O, --outpdir outpdir */			if (debug)				fprintf(stderr, "%s: setting outpdir to %s\n", argv[0], optarg);			strncpy(outpdir, optarg, sizeof(outpdir) - 1);			break;		case 'n':	/* -n, --lnkname lnkname */			if (debug)				fprintf(stderr, "%s: setting lnkname to %s\n", argv[0], optarg);			strncpy(lnkname, optarg, sizeof(lnkname) - 1);			break;		case 'o':	/* -o, --outfile outfile */			if (debug)				fprintf(stderr, "%s: setting outfile to %s\n", argv[0], optarg);			strncpy(outfile, optarg, sizeof(outfile) - 1);			break;		case 'l':	/* -l, --logfile errfile */			if (debug)				fprintf(stderr, "%s: setting errfile to %s\n", argv[0], optarg);			strncpy(errfile, optarg, sizeof(errfile) - 1);			break;		case 'f':	/* -f, --cfgfile cfgfile */			if (debug)				fprintf(stderr, "%s: setting cfgfile to %s\n", argv[0], optarg);			strncpy(cfgfile, optarg, sizeof(cfgfile) - 1);			break;		case 'e':	/* -e, --device */			if (debug)				fprintf(stderr, "%s: setting devname to %s\n", argv[0], optarg);			strncpy(devname, optarg, sizeof(devname) - 1);			break;		case 'c':	/* -c, --card */			if (debug)				fprintf(stderr, "%s: setting card to %d\n", argv[0], atoi(optarg));			card = atoi(optarg);			break;		case 's':	/* -s, --span */			if (debug)				fprintf(stderr, "%s: setting span to %d\n", argv[0], atoi(optarg));			span = atoi(optarg);			break;		case 't':	/* -t, --slot */			if (debug)				fprintf(stderr, "%s: setting slot to %d\n", argv[0], atoi(optarg));			slot = atoi(optarg);			break;		case 'a':	/* -a, --ds0a */			if (debug)				fprintf(stderr, "%s: setting interface type to ds0a\n", argv[0]);			iftype = SDL_TYPE_DS0A;			ifrate = 56000;			break;		case '0':	/* -0, --ds0 */			if (debug)				fprintf(stderr, "%s: setting interface type to ds0\n", argv[0]);			iftype = SDL_TYPE_DS0;			ifrate = 64000;			break;		case 'q':	/* -q, --quiet */			if (debug)				fprintf(stderr, "%s: suppressing normal output\n", argv[0]);			output = 0;			debug = 0;			break;		case 'D':	/* -D, --debug [LEVEL] */			if (debug)				fprintf(stderr, "%s: increasing debug verbosity\n", argv[0]);			if (optarg == NULL) {				debug += 1;				break;			}			if ((val = strtol(optarg, NULL, 0)) < 0)				goto bad_option;			debug = val;			break;		case 'v':	/* -v, --verbose */			if (debug)				fprintf(stderr, "%s: increasing output verbosity\n", argv[0]);			if (optarg == NULL) {				output += 1;				break;			}			if ((val = strtol(optarg, NULL, 0)) < 0)				goto bad_option;			output = val;			break;		case 'h':	/* -h, --help */		case 'H':	/* -H, --? */			if (debug)				fprintf(stderr, "%s: printing help message\n", argv[0]);			help(argc, argv);			exit(0);		case 'V':	/* -V, --version */			if (debug)				fprintf(stderr, "%s: printing version message\n", argv[0]);			version(argc, argv);			exit(0);		case 'C':	/* -C, --copying */			if (debug)				fprintf(stderr, "%s: printing copying message\n", argv[0]);			copying(argc, argv);			exit(0);		case '?':		default:		      bad_option:			optind--;			goto bad_nonopt;		      bad_nonopt:			if (output || debug) {				if (optind < argc) {					fprintf(stderr, "%s: illegal syntax -- ", argv[0]);					while (optind < argc)						fprintf(stderr, "%s ", argv[optind++]);					fprintf(stderr, "\n");				} else {					fprintf(stderr, "%s: missing option or argument", argv[0]);					fprintf(stderr, "\n");				}				fflush(stderr);				goto bad_usage;			      bad_usage:				usage(argc, argv);			}			exit(2);		}	}	ss7cap();	exit(4);}

⌨️ 快捷键说明

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