1 |
pcg |
1.1 |
/* |
2 |
|
|
device.C -- include the correct low-level implementation. |
3 |
pcg |
1.10 |
Copyright (C) 2003-2008 Marc Lehmann <gvpe@schmorp.de> |
4 |
pcg |
1.1 |
|
5 |
pcg |
1.6 |
This file is part of GVPE. |
6 |
|
|
|
7 |
pcg |
1.10 |
GVPE is free software; you can redistribute it and/or modify it |
8 |
|
|
under the terms of the GNU General Public License as published by the |
9 |
|
|
Free Software Foundation; either version 3 of the License, or (at your |
10 |
|
|
option) any later version. |
11 |
|
|
|
12 |
|
|
This program is distributed in the hope that it will be useful, but |
13 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
15 |
|
|
Public License for more details. |
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU General Public License along |
18 |
|
|
with this program; if not, see <http://www.gnu.org/licenses/>. |
19 |
|
|
|
20 |
|
|
Additional permission under GNU GPL version 3 section 7 |
21 |
|
|
|
22 |
|
|
If you modify this Program, or any covered work, by linking or |
23 |
|
|
combining it with the OpenSSL project's OpenSSL library (or a modified |
24 |
|
|
version of that library), containing parts covered by the terms of the |
25 |
|
|
OpenSSL or SSLeay licenses, the licensors of this Program grant you |
26 |
|
|
additional permission to convey the resulting work. Corresponding |
27 |
|
|
Source for a non-source form of such a combination shall include the |
28 |
|
|
source code for the parts of OpenSSL used as well as that of the |
29 |
|
|
covered work. |
30 |
pcg |
1.1 |
*/ |
31 |
|
|
|
32 |
|
|
#include "config.h" |
33 |
|
|
|
34 |
|
|
#include <cstring> |
35 |
|
|
#include <cstdlib> |
36 |
|
|
|
37 |
|
|
#include "slog.h" |
38 |
|
|
#include "device.h" |
39 |
|
|
|
40 |
|
|
static void *pkt_cachep[PKTCACHESIZE]; |
41 |
|
|
static int pkt_cachen = 0; |
42 |
|
|
|
43 |
|
|
void *net_packet::operator new(size_t s) |
44 |
|
|
{ |
45 |
|
|
if (s > sizeof (data_packet)) |
46 |
|
|
{ |
47 |
pcg |
1.9 |
slog (L_ERR, _("FATAL: allocation for network packet larger than max supported packet size (%d > %d)."), |
48 |
pcg |
1.1 |
s, sizeof (data_packet)); |
49 |
|
|
abort (); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
if (pkt_cachen) |
53 |
|
|
return pkt_cachep[--pkt_cachen]; |
54 |
|
|
else |
55 |
|
|
{ |
56 |
|
|
void *p = malloc (sizeof (data_packet)); |
57 |
|
|
memset (p, 0, sizeof (data_packet)); |
58 |
|
|
return p; |
59 |
|
|
} |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
void net_packet::operator delete(void *p) |
63 |
|
|
{ |
64 |
|
|
if (p) |
65 |
|
|
{ |
66 |
|
|
if (pkt_cachen < PKTCACHESIZE) |
67 |
|
|
{ |
68 |
|
|
memset (p, 0, sizeof (data_packet)); |
69 |
|
|
pkt_cachep[pkt_cachen++] = p; |
70 |
|
|
} |
71 |
|
|
else |
72 |
|
|
free (p); |
73 |
|
|
} |
74 |
|
|
} |
75 |
|
|
|
76 |
pcg |
1.2 |
#if IFTYPE_tincd |
77 |
|
|
# include "device-tincd.C" |
78 |
|
|
#elif IFTYPE_native && IF_linux |
79 |
pcg |
1.1 |
# include "device-linux.C" |
80 |
pcg |
1.3 |
#elif IFTYPE_native && IF_cygwin |
81 |
pcg |
1.1 |
# include "device-cygwin.C" |
82 |
pcg |
1.7 |
#elif IFTYPE_native && IF_darwin |
83 |
|
|
# include "device-darwin.C" |
84 |
pcg |
1.1 |
#else |
85 |
pcg |
1.2 |
# error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
86 |
pcg |
1.1 |
#endif |
87 |
|
|
|
88 |
|
|
|