1 |
/* Copyright (C) 2003 Stephane Thiell |
2 |
* |
3 |
* This file is part of pxyservd (from pxys) |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or |
6 |
* modify it under the terms of the GNU General Public License |
7 |
* as published by the Free Software Foundation; either version 2 |
8 |
* of the License, or (at your option) any later version. |
9 |
* |
10 |
* This program is distributed in the hope that it will be useful, |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
* GNU General Public License for more details. |
14 |
* |
15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
* |
19 |
*/ |
20 |
#define RCSID "$Id: PXConfig.cc,v 1.3 2006/09/11 22:02:54 spale Exp $" |
21 |
|
22 |
#ifdef HAVE_CONFIG_H |
23 |
#include "config.h" |
24 |
#endif |
25 |
|
26 |
#include "PXConfig.h" |
27 |
|
28 |
#include <cassert> |
29 |
#include <cstring> |
30 |
|
31 |
PXConfig::PXConfig() |
32 |
{ |
33 |
this->opas.local_address.s_addr = INADDR_ANY; |
34 |
} |
35 |
|
36 |
PXConfig::~PXConfig() |
37 |
{ |
38 |
} |
39 |
|
40 |
bool |
41 |
PXConfig::OPASIsAllowed(const in_addr &in) const |
42 |
{ |
43 |
for (size_t i = 0; i < opas.allow.size(); i++) |
44 |
if (opas.allow[i].s_addr == in.s_addr) |
45 |
return true; |
46 |
return false; |
47 |
} |
48 |
|
49 |
in_addr |
50 |
PXConfig::GetOneFromSourcePool() const |
51 |
{ |
52 |
assert(scanner.source_pool.size() > 0); |
53 |
|
54 |
StPXMutex m(&mutex); |
55 |
return scanner.source_pool[(int)((double(rand()) |
56 |
/ double((unsigned long)RAND_MAX + 1)) |
57 |
* scanner.source_pool.size())]; |
58 |
} |
59 |
|
60 |
bool |
61 |
PXConfig::CheckNoScan(const in_addr &addr) const |
62 |
{ |
63 |
for (size_t i = 0; i < this->noscan.address.size(); i++) |
64 |
{ |
65 |
const NetworkNetmask * nn = &this->noscan.address[i]; |
66 |
if ((addr.s_addr & nn->netmask.s_addr) |
67 |
== (nn->network.s_addr & nn->netmask.s_addr)) |
68 |
return true; |
69 |
} |
70 |
return false; |
71 |
} |