Exemple #1
0
int main(int argc, char **argv)
{
	int ret;

	if (!strcmp(argv[1], "down")) {
		enable_eth("eth0", 0);
		return 0;
	} else if (!strcmp(argv[1], "up")) {
		enable_eth("eth0", 1);
		return 0;
	}

	ret = get_netlink_status("eth0");
	printf("link status = %d\n", ret);

	return 0;
}
static void check_time_and_control_eth(struct ps_info *ps, int eth_if, int force_on)
{
	int hit_date=0, hit_time=0;
	unsigned int start, end, current;
	time_t tm;
	struct tm tm_time;

	if (force_on) {
		hit_date = 1;		
		hit_time = 1;			
	}	

	time(&tm);
	memcpy(&tm_time, localtime(&tm), sizeof(tm_time));

	DEBUG_PRINT(" tm_wday=%d, tm_hour=%d, tm_min=%d\n",
		tm_time.tm_wday, tm_time.tm_hour, tm_time.tm_min);

	switch(tm_time.tm_wday) {
		case 0:
			if (ps->date & ECO_SUNDAY_MASK)
				hit_date = 1;
			break;
		case 1:
			if (ps->date & ECO_MONDAY_MASK)
				hit_date = 1;
			break;
		case 2:
			if (ps->date & ECO_TUESDAY_MASK)
				hit_date = 1;
			break;
		case 3:
			if (ps->date & ECO_WEDNESDAY_MASK)
				hit_date = 1;
			break;
		case 4:
			if (ps->date & ECO_THURSDAY_MASK)
				hit_date = 1;
			break;
		case 5:
			if (ps->date & ECO_FRIDAY_MASK)
				hit_date = 1;
			break;
		case 6:
			if (ps->date & ECO_SATURDAY_MASK)
				hit_date = 1;
			break;
	}

	start = ps->fTime;
	end   = ps->tTime;
	current = tm_time.tm_hour * 60 + tm_time.tm_min;
	DEBUG_PRINT("start=%d, end=%d, current=%d\n", start, end, current);

	if (end >= start) {
		if ((current >= start) && (current < end))
			hit_time = 1;
	}
	else {
		if ((current >= start) || (current < end))
			hit_time = 1;
	}

	DEBUG_PRINT("[%s] pre_enable_state=%d, hit_date=%d, hit_time=%d\n",
		eth_if_name[eth_if], pre_eth_enable_state[eth_if], hit_date, hit_time);

	if (!pre_eth_enable_state[eth_if] && hit_date && hit_time) {
		enable_eth(eth_if);
		pre_eth_enable_state[eth_if] = 1;
	}
	else if (pre_eth_enable_state[eth_if] && (!hit_date || !hit_time)) {
		disable_eth(eth_if);
		pre_eth_enable_state[eth_if] = 0;
	}
}