File: iplist.cpp

package info (click to toggle)
ctorrent 1.3.4.dnh3.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,116 kB
  • ctags: 1,042
  • sloc: cpp: 10,727; sh: 885; ansic: 383; makefile: 49
file content (47 lines) | stat: -rw-r--r-- 902 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "iplist.h"  // def.h
#include <string.h>

IpList IPQUEUE;

void IpList::_Emtpy()
{
  IPLIST *node = ipl_head;
  for(; ipl_head;){
    node = ipl_head;
    ipl_head = node->next;
    delete node;
  }
  count = 0;
}

int IpList::Add(const struct sockaddr_in *psin)
{
  IPLIST *node = ipl_head;
  for(; node; node = node->next)
    if(memcmp(psin, &node->address, sizeof(struct sockaddr_in)) == 0) break;

  if( node ) return -1;
  // if not exist;
  node = new IPLIST;
#ifndef WINDOWS
  if( !node ) return -1;
#endif
  count++;
  memcpy(&node->address,psin,sizeof(struct sockaddr_in));
  node->next = ipl_head;
  ipl_head = node;
  return 0;
}

int IpList::Pop(struct sockaddr_in *psin)
{
  IPLIST *node = (IPLIST*) 0;
  if(!ipl_head) return -1;
  node = ipl_head;
  ipl_head = ipl_head->next;

  count--;
  memcpy(psin, &node->address, sizeof(struct sockaddr_in));
  delete node;
  return 0;
}