Annotation of embedaddon/coova-chilli/src/iphash.c, revision 1.1.1.1

1.1       misho       1: /* 
                      2:  *
                      3:  * IP address pool functions.
                      4:  * Copyright (C) 2003, 2004, 2005 Mondru AB.
                      5:  * Copyright (c) 2006-2007 David Bird <david@coova.com>
                      6:  * 
                      7:  * The contents of this file may be used under the terms of the GNU
                      8:  * General Public License Version 2, provided that the above copyright
                      9:  * notice and this permission notice is included in all copies or
                     10:  * substantial portions of the software.
                     11:  * 
                     12:  */
                     13:  
                     14: #include <sys/types.h>
                     15: #include <netinet/in.h> /* in_addr */
                     16: #include <stdlib.h>     /* calloc */
                     17: #include <stdio.h>      /* sscanf */
                     18: 
                     19: #include "iphash.h"
                     20: 
                     21: /* Create new address pool hash */
                     22: int iphash_new(struct ippool_t **this, struct ippoolm_t *list, int listsize) {
                     23: 
                     24:   int i;
                     25: 
                     26:   if (!(*this = calloc(sizeof(struct ippool_t), 1))) {
                     27:     /* Failed to allocate memory for iphash */
                     28:     return -1;
                     29:   }
                     30:   
                     31:   (*this)->listsize = listsize;
                     32:   (*this)->member = list;
                     33: 
                     34:   /* Determine log2 of hashsize */
                     35:   for ((*this)->hashlog = 0; 
                     36:        ((1 << (*this)->hashlog) < listsize);
                     37:        (*this)->hashlog++);
                     38:   
                     39:   /* Determine hashsize */
                     40:   (*this)->hashsize = 1 << (*this)->hashlog; /* Fails if mask=0: All Internet*/
                     41:   (*this)->hashmask = (*this)->hashsize -1;
                     42:   
                     43:   /* Allocate hash table */
                     44:   if (!((*this)->hash = calloc(sizeof(struct ippoolm_t), (*this)->hashsize))){
                     45:     /* Failed to allocate memory for hash members in iphash */
                     46:     return -1;
                     47:   }
                     48:   
                     49:   for (i = 0; i<listsize; i++) {
                     50:     
                     51:     (*this)->member[i].inuse = 1; /* TODO */
                     52:     ippool_hashadd(*this, &(*this)->member[i]);
                     53:   }
                     54: 
                     55:   return 0;
                     56: }
                     57: 
                     58: /* Delete existing address pool */
                     59: int iphash_free(struct ippool_t *this) {
                     60:   free(this->hash);
                     61:   free(this);
                     62:   return 0; /* Always OK */
                     63: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>