Link to home
Start Free TrialLog in
Avatar of FireBall
FireBall

asked on

c Remove from memory

Hello ,


I want to create a function to remove an element from IP4Map with matching ip4 but i could not succeded should any body help me ?



typedef struct IP4SYN{
     unsigned int ip4;
     unsigned int count;
	 unsigned int source_port;
	 unsigned int dest_port;
	 unsigned int dest_IP;
     long int SYN_Son;
     size_t s;
     size_t n;
} IP4SYN;

typedef struct IP4Map{
      IP4SYN * a;
      size_t s;
      size_t n;
} IP4Map;
unsigned int AddIP4ToMap(IP4Map * ip4map,unsigned int ip4,unsigned int source_port,unsigned int dest_port,unsigned int dest_IP){
       unsigned int pos =  0;
       if (ip4map->n >= ip4map->s)
       {
              ip4map->a = (IP4SYN *)krealloc( ip4map->a, ip4map->s+blocksize,GFP_NOWAIT);
              memset(&ip4map->a[ip4map->s], 0, sizeof(IP4SYN)*blocksize);
              ip4map->s += blocksize;
       }
       pos = FindIP4InMap(ip4map, ip4,source_port,dest_port,dest_IP);
       if (ip4map->n > pos)
       {
             if((ip4map->a[pos].ip4==ip4)&&(ip4map->a[pos].source_port==source_port)&&(ip4map->a[pos].dest_port==dest_port)&&(ip4map->a[pos].dest_IP==dest_IP)){
					ip4map->a[pos].SYN_Son=Zaman_MS();
					return ++ip4map->a[pos].count;  // increment counter
             }
             else  // shift entries 1 to the right from pos 
             {
                    unsigned int shift = (ip4map->n - pos)-1;
                    if (shift > 0)
                    {
                          memmove(&ip4map->a[pos+1], &ip4map->a[pos], shift);
                    }
             }
        }
        ip4map->a[pos].ip4 = ip4;
        ip4map->a[pos].source_port = source_port;
        ip4map->a[pos].dest_port = dest_port;
        ip4map->a[pos].dest_IP = dest_IP;
        ip4map->a[pos].SYN_Son = Zaman_MS();
        ip4map->a[pos].count = 1;
        ip4map->n++;
        return 1;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial