示例#1
0
文件: main.c 项目: vasubabu/WebServer
/*******************************************************************************
@purpose: START POINT
*******************************************************************************/
int main(int argc, char *argv[])
{
    switch(getStartupParams(argc, argv))
    {
    case SHOW_INTERFACES:
            printInterfaces();
            break;
    case SERVER_START:
            InitServer();
            break;
   /*case SERVER_STOP:      //TODO
            break;
    case SERVER_RESTART:
            break;*/
    case CHECK_CONFIG:
            checkConfiguration();
            break;
        case SHOW_HELP:
        case SHOW_HELP_LONG:
    default:
            printf("\tUsage:\n"
                   "\t--i    get available interfaces\n"
                   "\t--t    check configuration\n"
                   "\t--k    to start webserver\n"
                   "\t--h    print this text\n");
            return 0;
    }
}
示例#2
0
文件: cli.c 项目: draringi/gini
/*
 * Handler for the interface configuration command:
 * ifconfig add eth1 -socket socketfile -addr IP_addr  -hwaddr MAC [-gateway GW] [-mtu N]
 * ifconfig add tap0 -device dev_location -addr IP_addr -hwaddr MAC
 * ifconfig add tun0 -dstip dst_ip -dstport portnum -addr IP_addr -hwaddr MAC
 * ifconfig del eth0|tap0
 * ifconfig show [brief|verbose]
 * ifconfig up eth0|tap0
 * ifconfig down eth0|tap0
 * ifconfig mod eth0 (-gateway GW | -mtu N)
 */
void ifconfigCmd()
{
	char *next_tok;
	interface_t *iface;
	char dev_name[MAX_DNAME_LEN], con_sock[MAX_NAME_LEN], dev_type[MAX_NAME_LEN];
	uchar mac_addr[6], ip_addr[4], gw_addr[4], dst_ip[4];
	int mtu, interface, mode;
	short int dst_port;

	// set default values for optional parameters
	bzero(gw_addr, 4);
	mtu = DEFAULT_MTU;
	mode = NORMAL_LISTING;

	// we have already matched ifconfig... now parsing rest of the parameters.
	next_tok = strtok(NULL, " \n");

	if (next_tok == NULL)
	{
		printf("[ifconfigCmd]:: missing action parameter.. type help ifconfig for usage.\n");
		return;
	}
	if (!strcmp(next_tok, "add"))
	{

		next_tok = strtok(NULL, " \n");
        
		if ( (next_tok == NULL) || (findDeviceDriver(next_tok) == NULL) ) 
		{
			printf("ifconfig:: missing or invalid interface spec ..\n");
			return;
		}		

		strcpy(dev_name, next_tok);
		sscanf(dev_name, "%[a-z]", dev_type);
		interface = gAtoi(dev_name);

		if ((interface == 0) && (strcmp(dev_type, "eth") == 0))
		{
			printf("[ifconfigCmd]:: device number 0 is reserved for tap - start from 1\n");
			return;
		}

		if (strcmp(dev_type, "eth") == 0)
		{
			GET_NEXT_PARAMETER("-socket", "ifconfig:: missing -socket spec ..");
			strcpy(con_sock, next_tok);
		} else if(strcmp(dev_type, "tun") == 0)
		{
			GET_NEXT_PARAMETER("-dstip", "ifconfig:: missing -dstip spec ..");
			Dot2IP(next_tok, dst_ip);  
			GET_NEXT_PARAMETER("-dstport", "ifconfig:: missing -dstport spec ..");
			dst_port = (short int)atoi(next_tok);
		}

		GET_NEXT_PARAMETER("-addr", "ifconfig:: missing -addr spec ..");
		Dot2IP(next_tok, ip_addr);

		GET_NEXT_PARAMETER("-hwaddr", "ifconfig:: missing -hwaddr spec ..");
		Colon2MAC(next_tok, mac_addr);

		while ((next_tok = strtok(NULL, " \n")) != NULL)
			if (!strcmp("-gateway", next_tok))
			{
				next_tok = strtok(NULL, " \n");
				Dot2IP(next_tok, gw_addr);
			} else if (!strcmp("-mtu", next_tok))
			{
				next_tok = strtok(NULL, " \n");
				mtu = atoi(next_tok);
			}

		if (strcmp(dev_type, "eth") == 0)
			iface = GNETMakeEthInterface(con_sock, dev_name, mac_addr, ip_addr, mtu, 0);
		else if (strcmp(dev_type, "tap") == 0)
			iface = GNETMakeTapInterface(dev_name, mac_addr, ip_addr);
		else if (strcmp(dev_type, "tun") == 0)
			iface = GNETMakeTunInterface(dev_name, mac_addr, ip_addr, dst_ip, dst_port);
		else {
			printf("[ifconfigCmd]:: Unkown device type %s\n", dev_type);
			return;
		}

		if (iface != NULL)
		{
			verbose(2, "[configureInterfaces]:: Inserting the definition in the interface table ");
			GNETInsertInterface(iface);
			addMTUEntry(MTU_tbl, iface->interface_id, iface->device_mtu, iface->ip_addr);
			// for tap0 interface the MTU value cannot be changed. should we allow change?
		}
	}
	else if (!strcmp(next_tok, "del"))
	{
		GET_THIS_OR_THIS_PARAMETER("eth", "tap", "ifconfig:: missing interface spec ..");
		strcpy(dev_name, next_tok);
		interface = gAtoi(next_tok);
		destroyInterfaceByIndex(interface);
		deleteMTUEntry(interface);
	}
	else if (!strcmp(next_tok, "up"))
	{
		GET_THIS_OR_THIS_PARAMETER("eth", "tap", "ifconfig:: missing interface spec ..");
		strcpy(dev_name, next_tok);
		interface = gAtoi(next_tok);
		upInterface(interface);

	}
	else if (!strcmp(next_tok, "down"))
	{
		GET_THIS_OR_THIS_PARAMETER("eth", "tap", "ifconfig:: missing interface spec ..");
		strcpy(dev_name, next_tok);
		interface = gAtoi(next_tok);
		downInterface(interface);
	}
	else if (!strcmp(next_tok, "mod"))
	{
		GET_THIS_PARAMETER("eth", "ifconfig:: missing interface spec ..");
		strcpy(dev_name, next_tok);
		interface = gAtoi(next_tok);

		while ((next_tok = strtok(NULL, " \n")) != NULL)
			if (!strcmp("-gateway", next_tok))
			{
				next_tok = strtok(NULL, " \n");
				strcpy(gw_addr, next_tok);
			} else if (!strcmp("-mtu", next_tok))
			{
				next_tok = strtok(NULL, " \n");
				mtu = atoi(next_tok);
			}

		changeInterfaceMTU(interface, mtu);
	}
	else if (!strcmp(next_tok, "show"))
	{
		if ((next_tok = strtok(NULL, " \n")) != NULL)
		{
			if (strstr(next_tok, "bri") != NULL)
				mode = BRIEF_LISTING;
			else if (strstr(next_tok, "verb") != NULL)
				mode = VERBOSE_LISTING;
		} else
			mode = NORMAL_LISTING;

		printInterfaces(mode);
	}
	return;
}