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

📄 wstart.c

📁 wdiag-0.10.gz ( Diagnostic source )
💻 C
字号:
/* Westell 6100 multicast data collection utility * to start the multicast stream. * * Copyright: Josh Carroll (josh.carroll@gmail.com) * 10/13/2004 * * wstart.c is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. *  * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA **/#include "wstart.h"extern wmodel_t models[];/* main program */int main(int argc, char *argv[]) {	uid_t id;	/* model number and/or broadcast passed on the command line */	int model_number = -1,i,gopt;	char *bcast = NULL;	/* packet model struct */	pmodel_t model;	/* to hold the current packet info */	wpacket_t curr_pkt;	/* for the config file */		wconf_t conf;	/* first look to see if the person has a config file. if so, use		any values specified there */	if(read_config(&conf) == 0) {		model_number = conf.model;		bcast = conf.bcast;	}	/* requires the modem type */	if( (model_number == -1 && bcast == NULL) && argv[1] == NULL) {		printf("Usage: %s -m <model> [-b <broadcast addr>]\n", argv[0]);		printf("Valid models:\n");		for(i=0; i <= MAX_MODEL_NUMBER; i++) {			printf("\t%d\t%s\n", i, pmodels[i].model_number);		}		exit(1);	}	/* use getopt to get command line arguments */	while((gopt = getopt(argc, argv, "m:b:")) != EOF) {		switch (gopt) {			case 'm':				model_number = atoi(optarg);				break;			case 'b':				bcast = malloc(sizeof(char) * strlen(optarg));				strcpy(bcast, optarg);				break;		}	}	if(model_number == -1) {		printf("Usage: %s -m <model> [-b <broadcast addr>]\n", argv[0]);		printf("Valid models:\n");		for(i=0; i <= MAX_MODEL_NUMBER; i++) {			printf("\t%d\t%s\n", i, pmodels[i].model_number);		}		/* cleanup before we exit */		wfree(bcast);		exit(1);	}	/* check for valid modem model number */	if(model_number < 0 || model_number > MAX_MODEL_NUMBER) {		printf("Invalid model type! Valid models:\n");		for(i=0; i <= MAX_MODEL_NUMBER; i++) {			printf("\t%d\t%s\n", i, pmodels[i].model_number);		}		/* cleanup before we exit */		wfree(bcast);		exit(1);	}	/* assign the model */	model = pmodels[model_number];	/* if they specified a broadcast, update the model struct	 * values to reflect the changes */	if(bcast != NULL) {		strcpy(model.broadcast_ip, bcast);		/* free the bcast buffer */		wfree(bcast);	}	/* since we are sending a raw IGMP packet, require root */	id = geteuid();	if(id != 0) {		printf("You must be root to execute this program.\n");		exit(1);	}	/* send the udp packets to init the modem */	for(i=0; i <= model.num_packets-1; i++) {		curr_pkt = model.packets[i];		send_packet(&curr_pkt,model.broadcast_ip);		/* the older westell models cannot respond when the udp		 * packets are sent too quickly, so sleep 500ms between		 * each udp packet send. newer models are compatible. */		usleep(500000);	}	/* subscribe to the multicast group */	for(i=0; i < model.num_mcasts; i++) {		multicast_subscribe(model.multicasts[i].mcast_dest,				model.multicasts[i].mcast_group);		usleep(500000);	}	return 0;}

⌨️ 快捷键说明

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