Exemplo n.º 1
0
static void
do_offline(const char *ifname, ipmp_handle_t handle)
{
	ifaddrlistx_t *ifaddrp, *ifaddrs;
	int retval;

	if (is_offline(ifname))
		die("interface %s is already offline\n", ifname);

	if ((retval = ipmp_offline(handle, ifname, 1)) != IPMP_SUCCESS)
		die("cannot offline %s: %s\n", ifname, mpadm_errmsg(retval));

	/*
	 * Get all the up addresses for `ifname' and bring them down.
	 */
	if (ifaddrlistx(ifname, IFF_UP, 0, &ifaddrs) == -1)
		die("cannot get addresses on %s", ifname);

	for (ifaddrp = ifaddrs; ifaddrp != NULL; ifaddrp = ifaddrp->ia_next) {
		if (!(ifaddrp->ia_flags & IFF_OFFLINE))
			warn("IFF_OFFLINE vanished on %s\n", ifaddrp->ia_name);

		if (!set_lifflags(ifaddrp->ia_name,
		    ifaddrp->ia_flags & ~IFF_UP))
			warn("cannot bring down address on %s",
			    ifaddrp->ia_name);
	}

	ifaddrlistx_free(ifaddrs);
}
Exemplo n.º 2
0
char MySniff::start()
{	
	if (status != TH_STOPPED){
		xlog_err(LEVEL9,parent,"Alert","Capture is already started");
		return -1;
	}
	
	if ((settings & XSNIFF_SETTING_IS_SET_INTERFACE) == 0){
		xlog_err(LEVEL2,parent,"Alert","Interface is not set!");
		return -1;
	}
	
	if (is_offline() == 0){
		if ((settings & XSNIFF_SETTING_IS_SET_FREQ) == 0){
			if (this->cfg_chann()!=0){
				xlog_err(LEVEL2,parent,"Alert","Can't run start without channel initialisation!");	
				return -1;
			}
		}
	}
	
	if (is_everything_set()!=0){
		xlog_err(LEVEL2,parent,"Alert","Can't start. Error: %d",is_everything_set());
		return -1;
	}
	
	if (pthread_create(&th_start_capture,NULL,main_loop,NULL) != 0){
		log_err(LEVEL1,(char *)"Can't create thread: %s",(char *)strerror(errno));
		xlog_err(LEVEL1,parent,"Alert","Can't create thread: %s",(char *)strerror(errno));
		return -1;
	}else{
		status = TH_STARTED;
		//pthread_join(th_start_capture,&value_ptr);
		
		if (is_offline() == 0){
			if (this->start_hop_freq() != 0){
				xlog_err(LEVEL2,parent,"Warning","Capture started but will listen only on current channel");
			}
		}
		
		return 0;
	}
}
Exemplo n.º 3
0
static void
undo_offline(const char *ifname, ipmp_handle_t handle)
{
	ifaddrlistx_t *ifaddrp, *ifaddrs;
	int retval;

	if (!is_offline(ifname))
		die("interface %s is not offline\n", ifname);

	/*
	 * Get all the down addresses for `ifname' and bring them up.
	 */
	if (ifaddrlistx(ifname, 0, IFF_UP, &ifaddrs) == -1)
		die("cannot get addresses for %s", ifname);

	for (ifaddrp = ifaddrs; ifaddrp != NULL; ifaddrp = ifaddrp->ia_next) {
		if (!(ifaddrp->ia_flags & IFF_OFFLINE))
			warn("IFF_OFFLINE vanished on %s\n", ifaddrp->ia_name);

		if (!set_lifflags(ifaddrp->ia_name, ifaddrp->ia_flags | IFF_UP))
			warn("cannot bring up address on %s", ifaddrp->ia_name);
	}

	ifaddrlistx_free(ifaddrs);

	/*
	 * Undo the offline.
	 */
	if ((retval = ipmp_undo_offline(handle, ifname)) != IPMP_SUCCESS) {
		die("cannot undo-offline %s: %s\n", ifname,
		    mpadm_errmsg(retval));
	}

	/*
	 * Verify whether IFF_OFFLINE is set as a sanity check.
	 */
	if (is_offline(ifname))
		warn("in.mpathd has not cleared IFF_OFFLINE on %s\n", ifname);
}
Exemplo n.º 4
0
char MySniff::cfg_chann(char *channels)
{
	int tmp;
	uint8_t default_channels[]=
	{
		1, 7, 13, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12, 0
		//1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0
	};
	
	if (is_offline() != 0){
		xlog_err(LEVEL1,parent,"Alert","Can't set channels in offline mode");
		return -1;
	}
	
	if ((settings & XSNIFF_SETTING_IS_SET_INTERFACE) == 0){
		xlog_err(LEVEL2,parent,"Alert","First you must configure interface!");
		return -1;
	}
	
	if (channels==NULL){
		if (init_default_channels(default_channels) < 0){
			xlog_err(LEVEL2,parent,"Alert","Can't init default channels");
			return -1;
		}
		
	}else{
		if (parse_own_channels(channels)<0){
			xlog_err(LEVEL2,parent,"Alert","Can't parse channels. You must enter just positive numbers (lower than 255) and comas Eg: 1,2,3,4,5");
			return -1;
		}
	}
	
	tmp=verify_freq();
	if (tmp!=0){
		if (tmp>0){
			xlog_err(LEVEL2,parent,"Alert","Unsuported channel %d (%d MHz)",get_channel(tmp-1),get_freq(tmp-1));
			return -1;
		}else{
			xlog_err(LEVEL2,parent,"Alert","Can't set channels");
			return -1;
		}
	}
		
	settings = settings | XSNIFF_SETTING_IS_SET_FREQ; 
	
	return 0;
	
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
	int i;
	time_t now = time(NULL);
	now = time(NULL);
	if (argc < 2) {
		printf("isoffline <fname...>\n");
		exit(1);
	}
	for (i=1;i<argc;i++) {
		bool offline;
		if (is_offline(argv[i], now, &offline) == -1) {
			perror(argv[i]);
			exit(1);
		}
		printf("%s\t%s\n", offline?"offline":"online ", argv[i]);
	}
	return 0;
}
Exemplo n.º 6
0
char MySniff::cfg_interface(char *name)
{
	new_dev_clean();
	set_dev_name(name);
	if (set_interface()<0){
		xlog_err(LEVEL2,parent,"Alert","This is not an supported wireless device. Check if the device is wireless and you have enabled monitor mode");
		return -1; 
	}
	
//TODO 	we should use G.freq and not default one
	
	settings = settings | XSNIFF_SETTING_IS_SET_INTERFACE; 
	
	if (is_offline() == 0){
		if (this->cfg_chann()!=0){
			xlog_err(LEVEL7,parent,"Alert","Please set custom channels before start capturing");
			//return -1;
			//!?
		}
	}
	
	return 0;
}