void UpdateManager::checkAdditionalUpdates(bool manualCheck) {
	//v4
	if(!manualCheck && SETTING(IP_UPDATE) && !SETTING(AUTO_DETECT_CONNECTION) && SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_DISABLED) {
		checkIP(false, false);
	}

	//v6
	if(!manualCheck && SETTING(IP_UPDATE6) && !SETTING(AUTO_DETECT_CONNECTION6) && SETTING(INCOMING_CONNECTIONS6) != SettingsManager::INCOMING_DISABLED) {
		checkIP(false, true);
	}

	checkLanguage();

	if(SETTING(GET_USER_COUNTRY)) {
		checkGeoUpdate();
	}
}
Exemple #2
0
static int
answer_to_connection (void *cls, struct MHD_Connection *connection,
                      const char *url, const char *method,
                      const char *version, const char *upload_data,
                      size_t *upload_data_size, void **con_cls) {

    if (!*con_cls) { // new request
        if (strcmp(method, "POST") == 0) {
            if(!checkIP(connection)) {
                logger.debug("Rejected packet from " + getIP(connection));
                return MHD_NO;
            }

            // create the persistent connection info object
            struct connection_info *con_info = new struct connection_info;
            con_info->message = nullptr;
            con_info->message_len = 0;
            con_info->valid = true;

            *con_cls = (void*)con_info;
            return MHD_YES;
        }

        logger.debug("Rejected non-POST message");
        return MHD_NO;
    }

    if (strcmp(method, "POST") == 0) {
        struct connection_info *con_info = (struct connection_info*)*con_cls;

        // if there is some data
        if (*upload_data_size != 0) {
            // process all of the data with the postprocessor
            char *newmsg = new char[con_info->message_len + *upload_data_size + 1];

            if (con_info->message) {
                strncpy(newmsg, con_info->message, con_info->message_len);
                delete[] con_info->message;
            }

            strncpy(newmsg + con_info->message_len, upload_data, *upload_data_size);
            con_info->message_len += *upload_data_size;
            newmsg[con_info->message_len] = '\0';
            con_info->message = newmsg;

            *upload_data_size = 0;
            return MHD_YES;
        } else {
            return send_page(connection, " ");
        }
    }

    return MHD_NO;
}
Exemple #3
0
int IP::checkCorrectInput(string ipadress, string mask) { // returnerar 0 ifall någon input är felaktig
	//kontrollerar IP
	int ipCheck = 0, maskCheck = 0;
	ipCheck = checkIP(ipadress);

	//kontrollerar masken

	string masken = decimalToBinary(255);



	return 1;
}
int ArpFrameSender::fillIP(char * s,unsigned char * ip)
{
	if(!checkIP(s))
		return 0;
	int j=0;
	for(int i=0;i<4;i++)
	{
		while(s[j]<'0'||s[j]>'9')
			j++;
		ip[i]=(unsigned char)atoi(s+j);//mod=256
		while(!(s[j]<'0'||s[j]>'9'))
			j++;
	}
	return 1;
}
void ipSolution(string s, int start, int left, vector<string> &solution, vector<string> &result) {
    if (left == 0 && start == s.size()) {
        // got a solution
        result.push_back(combineIP(solution));
    }
    
    if (left < 0) {
        return;
    }
    
    for (int i = start; i < start+3 && i < s.size(); i++) {
        string ip = s.substr(start, i+1-start);
        if (checkIP(ip)) {
            solution.push_back(ip);
            ipSolution(s, i+1, left-1, solution, result);
            solution.pop_back();
        } else {
            //break;
            // cout << ip << endl;
        }
    }
}
Exemple #6
0
int main()
{
  const char* x[] =
  {
    "192.168.1.1",
    "10.0.0.1.",
    "127.256.0.1",
    "iugerjiogjioe",
    "172.16,0.1",
    0
  };
  const char* m[] = 
  {
    "illegal",
    "good"
  };
  int i = 0;
 
  while(x[i] != 0) {
    printf("%s %s\n", x[i], m[checkIP(x[i])]);
    ++i;
  }
  return 0;
}
Exemple #7
0
/* Função para adicionar um contato*/
void addContact(){
	char ip[16];
	do{
		printf("Digite um IP valido para adicionar ou -1 para voltar: ");
		fflush(stdin);
		scanf("%s",ip);
		if(atoi(ip) == -1)
			return;
	}while(checkIP(ip) != 1);
	
	// Pega posiçao livre nos contatos se houver
	int freepos=0;
	while(1){
		if(freepos==MAX_CONTACTS){
			printf("Lista de Contatos Cheia, apague um contato.");
			return;
		}
		if(lista[freepos].validade == 0){
			break;
		}
		freepos++;
	}
	
	//Inicializa o contato na lista atual
	stpcpy(lista[freepos].ip,ip);
	lista[freepos].destino.sin_addr.s_addr = inet_addr(ip);
    lista[freepos].destino.sin_family = AF_INET;
    lista[freepos].destino.sin_port = htons(12350);
    lista[freepos].socket = socket(AF_INET , SOCK_STREAM , 0);
    if (lista[freepos].socket == -1){
        printf("Falha na criacao do socket para o contato, tente novamente.");
        return;
    }
	
	// Conexao com time-out baseado em http://developerweb.net/viewtopic.php?id=3196 para teste
	int res, valopt;
	long arg = 0;;
	struct timeval tv;
	fd_set myset;
	socklen_t lon;
	
	//Set socket to non-block type
	arg |= O_NONBLOCK;
	
	if(fcntl(lista[freepos].socket, F_SETFL, arg) < 0){
		perror("Erro de conexao:");
		return;
	}
	res = connect(lista[freepos].socket, (struct sockaddr *)&(lista[freepos].destino), sizeof(lista[freepos].destino));
	
	if(res < 0){
		if(errno == EINPROGRESS){
			tv.tv_sec = 8;
			tv.tv_usec = 0;
			FD_ZERO(&myset);
			FD_SET(lista[freepos].socket, &myset);
			if(select(lista[freepos].socket+1,NULL,&myset,NULL,&tv)){
				lon = sizeof(int);
				getsockopt(lista[freepos].socket, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
				if(valopt){
					printf("Erro de conexao:\n");
					return;
				}
			}
			else{
				printf("Erro de Conexao. Tempo Limite esgotado.\n");
				return;
			}
		}
		else{
			perror("Erro de conexao:");
			return;
		}
	}
	
	// Set to block type again
    if( (arg = fcntl(lista[freepos].socket, F_GETFL, NULL)) < 0){
		perror("Erro de conexao:");
		return;
	}      
	arg &= (~O_NONBLOCK);
	if( fcntl(lista[freepos].socket, F_SETFL, arg) < 0){
		perror("Erro de conexao:");
		return;
	}
	
	//Fim da conexao com time-out
	
	//Se tudo correu bem, confirma adiçao
	lista[freepos].validade = 1;
	printf("Contato de ip %s adicionado com sucesso.\n",ip);
	fprintf(logfile,"\n(%s %s) Contato de ip %s adicionado com sucesso\n",__DATE__,__TIME__,ip);
	
}
int UpStaticNet(PIPConfig IPConfig, int Index)
{

	int iRet = -1;
	if(Index == 0)
	{
		DHCPDisable(0);
		/*set ip address*/
		if(IPConfig->IPAddr){
			if(checkIP(IPConfig->IPAddr) == 0)
			{
				iRet=setLocalIP(WIREDEVICE,IPConfig->IPAddr);
				if(iRet != 0)
					fprintf(stderr, "setLocalIP failed\n");
			}
			else fprintf(stderr, "setLocalIP failed\n");
		}
		/*set netmask*/
		if(IPConfig->IPSubnetMask){
			if(checknetmask(IPConfig->IPSubnetMask) == 0)
			{
				iRet=setSubNetMask(WIREDEVICE,IPConfig->IPSubnetMask);
				if(iRet<0)
					fprintf(stderr , "set SubNetMask failed\n");
			}
			else fprintf(stderr,"setSubNetMask failed\n");
		}
		/*set gateway*/
		if(IPConfig->IPGateway){
			if(checkIP(IPConfig->IPGateway) == 0)
			{
				iRet=setDefGateway(WIREDEVICE,IPConfig->IPGateway);
				if(iRet != 0)
					fprintf(stderr , "setDefGateway failed\n");
			}
			else  fprintf(stderr , "setDefGateway failed\n");
		}
		return iRet;    
	}
	else if(Index == 1)
	{
		DHCPDisable(1);
/*        StopWPASupplicant();*/
		if(IPConfig->IPAddr){
			if(checkIP(IPConfig->IPAddr) == 0)
			{
				iRet=setLocalIP(WIFIDEVICE,IPConfig->IPAddr);
				if(iRet != 0)
					fprintf(stderr , "setLocalIP failed\n");
			}
			else fprintf(stderr , "setLocalIP failed\n");
		}

		if(IPConfig->IPSubnetMask){
			if(checknetmask(IPConfig->IPSubnetMask) == 0)
			{
				iRet=setSubNetMask(WIFIDEVICE,IPConfig->IPSubnetMask);
				if(iRet<0)
					fprintf(stderr , "setSubNetMask failed\n");
			}
			else  fprintf(stderr , "setSubNetMask failed\n");
		}

		if(IPConfig->IPGateway){
			if(checkIP(IPConfig->IPGateway) == 0)
			{
				iRet=setDefGateway(WIFIDEVICE,IPConfig->IPGateway);
				if(iRet != 0)
					fprintf(stderr , "setDefGateway failed\n");
			}
			else fprintf(stderr , "setDefGateway failed\n");  
		}
		return iRet;
	}
	return -1;              
}
void ArpFrameSender::run()
{
	cout<<"This is the program to send DIY ARP packets.Now let's make our packets......\n\n";
	cout<<"------------------------------------------------------------\n";
	if(this->openNIC()==0)//open the NIC
		return ;
	char desMac[18]="00:23:5a:6a:1b:e2";
	char srcMac[18]="00:23:54:21:49:7F";
	unsigned short opcode=2;
	char sendMac[18]="88:88:88:88:88:88";
	char sendIp[16]="172.19.44.34";
	char targetMac[18]="00:23:5a:6a:1b:e2";
	char targetIp[16]="172.19.44.136";

	int select=0;
	char buf1[16];
	char buf2[18];
AGAIN:
	while(true)
	{
		//show the info of the packet
		cout<<"------------------------------------------------------------\n";
		cout<<"This is the main info of your DIY arp packet :\n";
		cout<<"EtherDesMac="<<desMac<<" ; EtherSrcMac="<<srcMac<<endl<<"(";
		if(opcode==1)
			cout<<"request";
		else if(opcode==2)
			cout<<"reply";
		cout<<")\n";
		cout<<"ArpSenderMac="<<sendMac<<" ; ArpSenderIp="<<sendIp<<"\nArpTargetMac="<<targetMac<<" ; ArpTargetIp="<<targetIp<<endl;

		//ask for modification
		cout<<"------------------------------------------------------------\n";
		cout<<"Do you want to make any more change to the packet ?"<<endl;
		cout<<"0--no change ;\n1--desMac ;2--srcMac ;\n3--opcode ;4--sendMac ;5--sendIp ;6--targetMac ;7--targetIp\n"
			<<"Your select is :";
		cin>>select;
		if(select==0)
		{
			cout<<"DIY complete !"<<endl;
			break;
		}
		switch(select)
		{
		case 1:
			cout<<"EtherDesMac=";
			cin>>buf2;
			if(checkMac(buf2))
				copyStrBuf(desMac,buf2,18);
			else
				cout<<"The format of your input is wrong !"<<endl;
			break;
		case 2:
			cout<<"EtherSrcMac=";
			cin>>buf2;
			if(checkMac(buf2))
				copyStrBuf(srcMac,buf2,18);
			else
				cout<<"The format of your input is wrong !"<<endl;
			break;
		case 3:
			cout<<"ArpOpcode=";
			cin>>opcode;break;
		case 4:
			cout<<"ArpSendMac=";
			cin>>buf2;
			if(checkMac(buf2))
				copyStrBuf(sendMac,buf2,18);
			else
				cout<<"The format of your input is wrong !"<<endl;
			break;
		case 5:
			cout<<"ArpSendIp=";
			cin>>buf1;
			if(checkIP(buf1))
				copyStrBuf(sendIp,buf1,16);
			else
				cout<<"The format of your input is wrong !"<<endl;
			break;
		case 6:
			cout<<"ArpTargetMac=";
			cin>>buf2;
			if(checkMac(buf2))
				copyStrBuf(targetMac,buf2,18);
			else
				cout<<"The format of your input is wrong !"<<endl;
			break;
		case 7:
			cout<<"ArpTargetIp=";
			cin>>buf1;
			if(checkIP(buf1))
				copyStrBuf(targetIp,buf1,16);
			else
				cout<<"The format of your input is wrong !"<<endl;
			break;
		default:break;
		}
	}
	//fill the packet
	setEtherHeader(desMac,srcMac);
	setArp(opcode,sendMac,sendIp,targetMac,targetIp);
	//send the packet
	cout<<"------------------------------------------------------------\n"
		<<"How many arp packets would you like to send ?"<<endl<<"Packets' No.=";
	int num;
	cin>>num;
	send(num);
	cout<<"------------------------------------------------------------\n"
		<<"Would you like to send the ARP packet again ?(1--YES ;other--exit)"<<endl
		<<"Your choosen is :";
	char again='1';
	cin>>again;
	if(again=='1')
		goto AGAIN;
	closeNIC();
}
void UpdateManager::on(TimerManagerListener::Minute, uint64_t aTick) noexcept {
	if (SETTING(UPDATE_IP_HOURLY) && lastIPUpdate + 60*60*1000 < aTick) {
		checkIP(false, false);
		lastIPUpdate = aTick;
	}
}
Exemple #11
0
int main (int argc, char ** argv)
{
	
	access_caloe access;
	network_connection nc;
	int c, i, do_write = 0, warn = 1, limit=arguments;;                                                                    
	
	uint32_t cntr = 0;


	char *ip = (char *) malloc(conf_buf);
	char *end;
	uint32_t uarg[arguments], _val;
	char *ptr;
	
	strcpy(ip, def_ethb_conf);
	
	while ((c = getopt (argc, argv, "e:ywh")) != -1)
	{
		char aux[conf_buf];
		
		switch(c)
		{
		case 'e':
			strcpy(aux, optarg);
			ptr=strpbrk(aux, "/");
			*ptr=0;
			if (!strcmp(aux, "tpc"))
			{
				fprintf(stderr, "%s: Etherbone does not support tcp\n",
				              argv[0]);
				exit(1);
			}
			else if (strcmp(aux, "udp"))
			{
				fprintf(stderr, "%s: invalid protocol\"%s\"\n",
				              argv[0], aux);
				exit(1);
			}
			else if (checkIP(ptr+1))
			{
				fprintf(stderr, "%s: \"%s\" is not a valid IPv4 address\n",
				              argv[0], ptr+1);
				exit(1);
			}
			else
				strcpy(ip, optarg);
			break;
		case 'y':
			warn = 0;
			break;
		case 'w':
			do_write=1;
			break;
		case 'h':
			help(argv[0]);
			exit(1);
		}
	}

	if (optind  >= argc || optind < argc - arguments)
		help(argv[0]);

	if(optind != argc - arguments){
		uarg[arguments] = pattern;
		limit--;
	}

	/* convert the trailing hex number or numbers */
	for(i=0; i<limit; i++){
		uarg[i] = strtol(argv[optind+i], &end, abs(16*(1-i)));
		if (end && *end) {
			fprintf(stderr, "%s: \"%s\" is not a number\n",
				argv[0], argv[optind+i]);
			exit(1);
		}
	}

	if (uarg[0] & 3) {
		fprintf(stderr, "%s: address \"%s\" not multiple of 4\n",
			argv[0], argv[optind + 0]);
		exit(1);
	}

	if (warn){
		printf("\n"
		"                             - WARNING -                             "
		"\n");
		printf(
		"*- Access to a non-existent whisbone address will freeze your PC -*\n"
		"    Make sure 0x%08x is a valid address.\n"
		"    Verify that the number of positions to be tested \"%u (0x%x)\"\n"
		"    are within memory boundaries.\n\n",
		uarg[0], uarg[1], uarg[1]);
		printf(
		"*- Writing a non-valid value may cause an unpredictable behaviour -*\n"
		"    Adv: The memory should never be accessed while testing.\n"
		"         Hold WB Masters on reset while reading/writing patterns.\n");
		printf(
		"                             -----------                             "
		"\n\n");
		printf("Continue [y|n]: ");
		char proceed;
		for(;;)
		{
			scanf("%s", &proceed);
			if (proceed == 'y')
				break;
			else if (proceed == 'n')
				return 0;
			else 
				printf("Invalid option, please enter [y|n]: ");
		}
	}

	// Build an network_connection struct of access_internals
	build_network_con_caloe (ip, &nc);
	
	int last = 0, words = 0;
	for(i=uarg[0]; i < uarg[0]+uarg[1]*0x4; i+=0x4){
		if (!do_write) 
		{
			build_access_caloe(0x0, i, _val, 0, MASK_OR, is_config_int,
		                      READ, SIZE_4B, &nc, &access);
			if ((execute_caloe(&access)) < 0)
				exit(1);
			if (access.value == uarg[3]) 
			{
				if(((i-last) == 0x4) || (last == 0))
				{
					if(words == 0)
						printf("Starting at %08x we have ", i);
					words++;
				}
			} 
			else 
			{
				if (words == 1)
					printf("only one word\n");
				else if (words > 1)
				{
					printf("%u words, the last one at %08x\n", words, last);
				}
				words = 0;
			} 
			last=i;
		}
		else{
			build_access_caloe(0x0, i, uarg[3], 0, MASK_OR, is_config_int,
		                      WRITE, SIZE_4B, &nc, &access);
		    if ((execute_caloe(&access)) < 0)
				exit(1);
		}
	}
	
	if (words == 1)
		printf("only one word\n");
	else if (words > 1)
		printf("%u words, the last one at %08x\n", words, last);
	// Free access_caloe and network_connection memory
	free_access_caloe(&access);
	

	return 0;
}