Esempio n. 1
0
static void vde_ip_check(const unsigned char *buf,int rnx) 
{
	struct header *ph=(struct header *) buf;
	register int i,j,vlan=0;
	char addr[256];
	union body *pb;

	pb=(union body *)(ph+1);
	if (ph->proto[0]==0x81 && ph->proto[1]==0x00) { /*VLAN*/
		vlan=((pb->vlan.priovlan[0] << 8) + pb->vlan.priovlan[1]) & 0xfff;
		pb=(union body *)(((char *)pb)+4);
	}
	if (ph->proto[0]==0x08 && ph->proto[1]==0x00 && 
			pb->v4.version == 0x45) {
		/*v4 */ 
		i=hash4(pb->v4.ip4src);
		j=(i+MAX_IP-1)%MAX_IP;
		while (1) {
			/* most frequent case first */
			if (memcmp(pb->v4.ip4src,ip4list[i],4) == 0)
				break;
			else if (memcmp(ip4list[i],nulladdr,4) == 0) {
				memcpy(ip4list[i],pb->v4.ip4src,4);
				syslog(LOG_INFO,"user %s Real-IP %s has got VDE-IP4 %s on vlan %d",callerpwd->pw_name,host,inet_ntop(AF_INET,ip4list[i],addr,256),vlan);
				/*new ipv4*/
				break;
			} else if (i==j) {
				syslog(LOG_ERR,"IPv4 table full. Exiting\n");
				/*full table*/
				exit(-1);
			} else 
				i= (i+1)%MAX_IP;
		}
	}
	else if (ph->proto[0]==0x86 && ph->proto[1]==0xdd && 
			pb->v4.version == 0x60) {
		/* v6 */
		i=hash6(pb->v6.ip6src);
		j=(i+MAX_IP-1)%MAX_IP;
		while (1) {
			/* most frequent case first */
			if (memcmp(pb->v6.ip6src,ip6list[i],16) == 0)
				break;
			else if (memcmp(ip6list[i],nulladdr,16) == 0) {
				memcpy(ip6list[i],pb->v6.ip6src,16);
				syslog(LOG_INFO,"user %s Real-IP %s has got VDE-IP6 %s on vlan %d",callerpwd->pw_name,host,inet_ntop(AF_INET6,ip6list[i],addr,256),vlan);
				/*new ipv6*/
				break;
			} else if (i==j) {
				syslog(LOG_ERR,"IPv6 table full. Exiting\n");
				/*full table*/
				exit(-1);
			} else 
				i= (i+1)%MAX_IP;
		}
	}
}
Esempio n. 2
0
int main()
{	int n,m,i,j,q,num,flag=0,falsecases=0;
	float probfalse;
	unsigned int x,y,z;
	scanf("%d",&m);
	n=14.43*m+1;
	for(i=0;i<m;i++)
	{	scanf("%d",&numarr[i]);
		x=murmurhash3_32(numarr[i],n);
		y=fnv1(numarr[i],n);
		z=jenkins_hash(numarr[i],n);
		bitarr[x]=1;
		bitarr[y]=1;
		bitarr[z]=1;
		bitarr[hash4(x,y,z)]=1;
		bitarr[hash5(x,y,z)]=1;
		bitarr[hash6(x,y,z)]=1;
		bitarr[hash7(x,y,z)]=1;
		bitarr[hash8(x,y,z)]=1;
		bitarr[hash9(x,y,z)]=1;
		bitarr[hash10(x,y,z)]=1;
	}
	//printf("Enter no. of queries: ");
	scanf("%d",&q);
	for(i=0;i<q;i++)
	{	//printf("Enter value to check: ");
		scanf("%d",&num);
		x=murmurhash3_32(num,n);
		y=fnv1(num,n);
		z=jenkins_hash(num,n);
		if(bitarr[x]==1 && bitarr[y]==1 && bitarr[z]==1 && bitarr[hash4(x,y,z)]==1 && bitarr[hash5(x,y,z)]==1 && bitarr[hash6(x,y,z)]==1 && bitarr[hash7(x,y,z)]==1 && bitarr[hash8(x,y,z)]==1 && bitarr[hash9(x,y,z)]==1 && bitarr[hash10(x,y,z)]==1)
			found++;
		else
			notfound++;	//printf("Element not in set\n");
	}
	printf("NUMBER OF FLASE OUTPUTS: %d\n",falsecases);
	probfalse=(falsecases*100)/q;
	printf("PROBABILITY OF FLASE OUTPUTS: %.2f %\n",probfalse);
	printf("No. actually there: %d\nNo. actually not there: %d\n",found,notfound);
	return 0;
}