예제 #1
0
파일: dhcp.c 프로젝트: AubrCool/barebox
static void netmask_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
{
	IPaddr_t ip;

	ip = net_read_ip(popt);
	net_set_netmask(ip);
}
예제 #2
0
int main(int argc, char **argv)
{
	struct NET_CONFIG netcfg;
	int i;
	
	if (argc < 3) {
		net_get_info("eth0", &netcfg);
		return 0;
	}
	
	for (i=1; i<argc; i++)
		printf("arg[%d]=%s\n", i, argv[i]);
	
	if (!strcmp(argv[2], "up"))
		net_set_flag(argv[1], (IFF_UP | IFF_RUNNING));
	else if (!strcmp(argv[2], "down"))
		net_clr_flag(argv[1], IFF_UP);
	else if (!strcmp(argv[2], "ip")) {
		net_set_ifaddr(argv[1], inet_addr(argv[3]));
	}
	else if (!strcmp(argv[2], "netmask")) {
		net_set_netmask(argv[1], inet_addr(argv[3]));
	}
	else if (!strcmp(argv[2], "gateway")) {
		if (!strcmp(argv[1], "add")) 
			net_add_gateway(inet_addr(argv[3]));
		else
			net_del_gateway(inet_addr(argv[3]));
	}
	else if (!strcmp(argv[2], "dhcpcd")) {
		if (!strcmp(argv[3], "enable")) 
			net_enable_dhcpcd(argv[1]);
		else
			net_disable_dhcpcd(argv[1]);
	}
	else if (!strcmp(argv[1], "dns"))
		net_set_dns(argv[2]);
	else
		printf("unknown argument!\n");
	return 0;
}
예제 #3
0
파일: dhcp.c 프로젝트: cpdesign/barebox
static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
{
	unsigned char *end = popt + sizeof(*bp) + OPT_SIZE;
	int oplen;
	IPaddr_t ip;
	char str[256];

	while (popt < end && *popt != 0xff) {
		oplen = *(popt + 1);
		switch (*popt) {
		case 1:
			ip = net_read_ip(popt + 2);
			net_set_netmask(ip);
			break;
		case 3:
			ip = net_read_ip(popt + 2);
			net_set_gateway(ip);
			break;
		case 6:
			ip = net_read_ip(popt + 2);
			setenv_ip("nameserver", ip);
			break;
		case 12:
			memcpy(str, popt + 2, oplen);
			str[oplen] = 0;
			setenv("hostname", str);
			break;
		case 15:
			memcpy(str, popt + 2, oplen);
			str[oplen] = 0;
			setenv("domainname", str);
			break;
		case 17:
			memcpy(str, popt + 2, oplen);
			str[oplen] = 0;
			setenv("rootpath", str);
			break;
		case 51:
			net_copy_uint32 (&dhcp_leasetime, (uint32_t *)(popt + 2));
			break;
		case 53:	/* Ignore Message Type Option */
			break;
		case 54:
			net_copy_ip(&net_dhcp_server_ip, (popt + 2));
			break;
		case 58:	/* Ignore Renewal Time Option */
			break;
		case 59:	/* Ignore Rebinding Time Option */
			break;
		case 66:	/* Ignore TFTP server name */
			break;
		case 67:	/* vendor opt bootfile */
			/*
			 * I can't use dhcp_vendorex_proc here because I need
			 * to write into the bootp packet - even then I had to
			 * pass the bootp packet pointer into here as the
			 * second arg
			 */
			memcpy(str, popt + 2, oplen);
			str[oplen] = 0;
			if (bp->bp_file[0] == '\0') {
				/*
				 * only use vendor boot file if we didn't
				 * receive a boot file in the main non-vendor
				 * part of the packet - god only knows why
				 * some vendors chose not to use this perfectly
				 * good spot to store the boot file (join on
				 * Tru64 Unix) it seems mind bogglingly crazy
				 * to me
				 */
				printf("*** WARNING: using vendor "
					"optional boot file\n");
					setenv("bootfile", str);
			}
			break;
		default:
#ifdef CONFIG_BOOTP_VENDOREX
			if (dhcp_vendorex_proc (popt))
				break;
#endif
			debug("*** Unhandled DHCP Option in OFFER/ACK: %d\n", *popt);
			break;
		}
		popt += oplen + 2;	/* Process next option */
	}
}