Exemplo n.º 1
0
void ip_knocked( const char *ip, int port, struct vector *knock_stats, int prot_type ) {

	assert( ip != NULL && knock_stats != NULL );

	static int knock_no = 0;

	/* When IP is banned, it is deleted from vector. To not waste to much memory,
	shrink them to minimum size, everytime the counter knock_no hits specified number. */
	if( knock_no % SHRINK_VECTORS_EVERY_N_KNOCKS == 0 ) {
		vector_shrink_to_fit( knock_stats );
	}

	++knock_no;

	if( vector_search( pss_configuration.ip_whitelist, (void *)ip, ip_bitmask_cmp ) != -1 ) {
		return; // Ip whitelisted, ignore.
	}

	// Check if port is specified in config, if yes - take care of the IP.
	if( prot_type == P_TCP ) {

		if( vector_search( pss_configuration.tcp_trap_ports, &port, port_in_range ) != -1 ) {
			ip_knocked_handle( knock_stats, ip );
		}

	} else if( prot_type == P_UDP ) {

		if( vector_search( pss_configuration.udp_trap_ports, &port, port_in_range ) != -1 ) {
			ip_knocked_handle( knock_stats, ip );
		}

	} else {
		pss_log( "Wrong parameter passed to ip_knocked() function.\n" );
	}

}
Exemplo n.º 2
0
int vectortest(void)
{
    	VECTOR test;
        VECTOR fusetest;
	int n = 10, a = 5, b = 0, cnt = 0;
	int* thrdVal;
	test = makeVECTOR(sizeof(int), 3); //Create VECTOR. Reserve space for 3 integer elements.
        fusetest = makeVECTOR(sizeof(int), 3); //Create VECTOR. Reserve space for 3 integer elements.
        
        vectorpush(&fusetest, (void*)&a);
        vectorpush(&fusetest, (void*)&b);
        vectorpush(&fusetest, (void*)&n);
        
	//Show the VECTOR size and allocated space.
	printf("VECTOR size: %i, max: %i\n", test.size, test.maxsize);

	//Push 10 values to the VECTOR
	do
	{
		if(vectorpush(&test, &n) < 1)
		{
			printf("Error pushing element %i\n", cnt);
			exit;
		}
		n += 2;
		cnt++;
	}while(cnt < 10);

	vectorinsert(&test, &a, 5);
	vectordelete(&test, 3);
	a += 12;
	vectorinsert(&test, &a, 3);
	vectorpop(&test, &b);
	printf("Pop: %i\n", b);
	vector_read(&test, &b, 8);
	printf("Read 8: %i\n", b);
	vector_reverse(&test);
	vector_resize(&test, 20);
	cnt = 0;
	do
	{
		if(vectorpush(&test, &n) < 1)
		{
			printf("Error pushing element %i\n", cnt);
			exit;
		}
		n += 2;
		cnt++;
	}while(cnt < 5);

	//Show the new VECTOR size and allocated space.
	printf("VECTOR size: %i, max: %i\n", test.size, test.maxsize);
	cnt = 0;
	//Show every value inside the VECTOR
	do
	{
		thrdVal = (int*)&test.data[sizeof(int)*cnt];
		printf("test[%i] = %i\n", cnt,*thrdVal);
		cnt++;
	}while(cnt < test.size);

	vector_shrink_to_fit(&test);
	vector_swap(&test, &a, 9);
	vector_swap_b(&test, 1, 13);

	printf("VECTOR size: %i, max: %i\n", test.size, test.maxsize);
	cnt = 0;
	//Show every value inside the VECTOR
	do
	{
		thrdVal = (int*)&test.data[sizeof(int)*cnt];
		printf("test[%i] = %i\n", cnt,*thrdVal);
		cnt++;
	}while(cnt < test.size);
        
        printf("\n- vector fuse -\n");
        printf("VECTOR size: %i, max: %i\n", fusetest.size, fusetest.maxsize);
        printf("fusetest[0] = %i\n", *thrdVal);
        vector_fuse(&fusetest, &test);
        cnt = 0;
        printf("VECTOR size after fuse: %i, max: %i\n", fusetest.size, fusetest.maxsize);
        do{
            vector_read(&fusetest, thrdVal, cnt);
            printf("%i: %i\n", cnt, *thrdVal);
            cnt++;
        }while(cnt < fusetest.size);
        
        //Vector copy
        printf("Before copy...\n");
        cnt = 0;
        do
	{
		thrdVal = (int*)&test.data[sizeof(int)*cnt];
		printf("test[%i] = %i\n", cnt,*thrdVal);
		cnt++;
	}while(cnt < test.size);
        
        vector_copy(&test, &fusetest, 1, 4, 2);
        printf("After copy...\n");
        cnt = 0;
	do
	{
		thrdVal = (int*)&test.data[sizeof(int)*cnt];
		printf("test[%i] = %i\n", cnt,*thrdVal);
		cnt++;
	}while(cnt < test.size);
        printf("VECTOR size: %i, max: %i\n", test.size, test.maxsize);
        
        //Clean the memory
	vectorclear(&test);
	printf("VECTOR size: %i, max: %i\n", test.size, test.maxsize);
        
	return 0;
}