WEB开发网
开发学院网络安全防火墙 iptables 源码分析 阅读

iptables 源码分析

 2007-03-07 12:42:27 来源:WEB开发网   
核心提示: 函数为h分配空间,然后赋予相应的值,iptables 源码分析(8),要理解这个函数,还需要了解STRUCT_GETINFO结构和分配内存空间的函数alloc_handle

函数为h分配空间,然后赋予相应的值。要理解这个函数,还需要了解STRUCT_GETINFO结构和分配内存空间的函数alloc_handle。

  #define STRUCT_GETINFO struct ipt_getinfo
  /* The argument to IPT_SO_GET_INFO */
  struct ipt_getinfo
  {
  /* Which table: caller fills this in. */
  char name[IPT_TABLE_MAXNAMELEN];
  /* Kernel fills these in. */
  /* Which hook entry points are valid: bitmask */
  unsigned int valid_hooks;
  /* Hook entry points: one per netfilter hook. */
  unsigned int hook_entry[NF_IP_NUMHOOKS];
  /* Underflow points. */
  unsigned int underflow[NF_IP_NUMHOOKS];
  /* Number of entries */
  unsigned int num_entries;
  /* Size of entries. */
  unsigned int size;
  };
  /* Allocate handle of given size */
  static TC_HANDLE_T
  alloc_handle(const char *tablename, unsigned int size, unsigned int num_rules)
  {
  size_t len;
  TC_HANDLE_T h;
  len = sizeof(STRUCT_TC_HANDLE)
  + size
  + num_rules * sizeof(struct counter_map);
  if ((h = malloc(len)) == NULL) {
  errno = ENOMEM;
  return NULL;
  }
  h->changed = 0;
  h->cache_num_chains = 0;
  h->cache_chain_heads = NULL;
  h->counter_map = (void *)h
  + sizeof(STRUCT_TC_HANDLE)
  + size;
  strcpy(h->info.name, tablename);
  strcpy(h->entries.name, tablename);
  return h;
  }

上一页  3 4 5 6 7 8 9 10  下一页

Tags:iptables 源码 分析

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接