"Fossies" - the Fresh Open Source Software Archive 
Member "portfwd-0.29/src/proto_map.cc" (21 May 2007, 2278 Bytes) of package /linux/privat/old/portfwd-0.29.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 proto_map.cc
3
4 $Id: proto_map.cc,v 1.5 2007/05/21 18:01:58 evertonm Exp $
5 */
6
7 #include <syslog.h>
8 #include <errno.h>
9 #include "proto_map.hpp"
10 #include "forward.h"
11 #include "portfwd.h"
12
13 proto_map::proto_map(vector<int> *port_l, vector<host_map*> *map_l, struct ip_addr *actv, struct ip_addr *pasv, int user, int group, struct ip_addr listen, struct ip_addr *source)
14 {
15 port_list = port_l;
16 map_list = map_l;
17 fragile = 0; /* false */
18
19 ftp_actv = actv != NULL;
20 if (ftp_actv)
21 actv_ip = *actv;
22
23 ftp_pasv = pasv != NULL;
24 if (ftp_pasv)
25 pasv_ip = *pasv;
26
27 uid = user;
28 gid = group;
29 local_listen = listen;
30
31 if (source) {
32 local_source = *source;
33 local_src = &local_source;
34 }
35 else
36 local_src = 0;
37 }
38
39 void proto_map::set_fragile(bool b)
40 {
41 this->fragile = b;
42 }
43
44 void proto_map::show() const
45 {
46 iterator<vector<int>,int> it(*port_list);
47 it.start();
48 if (it.cont()) {
49 syslog(LOG_INFO, "%d", it.get());
50 it.next();
51 }
52 for (; it.cont(); it.next())
53 syslog(LOG_INFO, ", %d", it.get());
54
55 syslog(LOG_INFO, " /* uid: %d, gid: %d */", uid, gid);
56 syslog(LOG_INFO, " /* listen: %s */", addrtostr(&local_listen));
57
58 if (local_src)
59 syslog(LOG_INFO, " /* source: %s */", addrtostr(&local_source));
60
61 if (ftp_actv)
62 syslog(LOG_INFO, " ftp-active-mode-on %s", addrtostr(&actv_ip));
63
64 if (ftp_pasv)
65 syslog(LOG_INFO, " ftp-passive-mode-on %s", addrtostr(&pasv_ip));
66
67 syslog(LOG_INFO, "\n{");
68 iterator<vector<host_map*>,host_map*> it2(*map_list);
69 it2.start();
70 if (it2.cont()) {
71 it2.get()->show();
72 it2.next();
73 }
74 for (; it2.cont(); it2.next()) {
75 syslog(LOG_INFO, ";\n");
76 it2.get()->show();
77 }
78 syslog(LOG_INFO, "\n}\n");
79 }
80
81 void proto_map::serve(proto_t proto) const
82 {
83 if (!port_list) {
84 syslog(LOG_WARNING, "Missing port list");
85 return;
86 }
87
88 const struct ip_addr *listen = &local_listen;
89
90 switch (proto) {
91 case P_TCP:
92 tcp_forward(listen, local_src, port_list, map_list, ftp_actv ? &actv_ip : 0, ftp_pasv ? &pasv_ip : 0, uid, gid, fragile);
93 break;
94
95 case P_UDP:
96 udp_forward(listen, local_src, port_list, map_list, uid, gid);
97 break;
98
99 default:
100 syslog(LOG_ERR, "Unknown protocol identifier: %d\n", proto);
101 }
102
103 }
104
105 /* Eof: proto_map.cc */