Add support for NAT in the tunneling client
[bcusdk.git] / eibd / server / b-EIBNETIPTUNNEL.h
blob7e7b52c8ebec3946414717b98e8076117cd37c6a
1 /*
2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef C_EIBNETIPTUNNEL_H
21 #define C_EIBNETIPTUNNEL_H
23 #include <stdlib.h>
24 #include "eibnettunnel.h"
26 #define EIBNETIPTUNNEL_URL "ipt:router-ip[:dest-port[:src-port[:nat-ip[:data-port]]]]]\n"
27 #define EIBNETIPTUNNEL_DOC "ipt connects with the EIBnet/IP Tunneling protocol over an EIBnet/IP gateway. The gateway must be so configured, that it routes the necessary addresses\n\n"
29 #define EIBNETIPTUNNEL_PREFIX "ipt"
30 #define EIBNETIPTUNNEL_CREATE eibnetiptunnel_Create
31 #define EIBNETIPTUNNEL_CLEANUP NULL
33 #define EIBNETIPTUNNELNAT_URL "iptn:router-ip[:dest-port[:src-port]]\n"
34 #define EIBNETIPTUNNELNAT_DOC "iptn connects with the EIBnet/IP Tunneling protocol over an EIBnet/IP gateway using the NAT mode\n\n"
36 #define EIBNETIPTUNNELNAT_PREFIX "iptn"
37 #define EIBNETIPTUNNELNAT_CREATE eibnetiptunnelnat_Create
38 #define EIBNETIPTUNNELNAT_CLEANUP NULL
41 inline Layer2Interface *
42 eibnetiptunnel_Create (const char *dev, int flags, Trace * t)
44 char *a = strdup (dev);
45 char *b;
46 char *c;
47 char *d = 0;
48 char *e;
49 int dport;
50 int dataport = -1;
51 int sport;
52 Layer2Interface *iface;
53 if (!a)
54 die ("out of memory");
55 for (b = a; *b; b++)
56 if (*b == ':')
57 break;
58 sport = 3672;
59 if (*b == ':')
61 *b = 0;
62 for (c = b + 1; *c; c++)
63 if (*c == ':')
64 break;
65 if (*c == ':')
67 *c = 0;
68 for (d = c + 1; *d; d++)
69 if (*d == ':')
70 break;
71 if (*d == ':')
73 for (e = d + 1; *e; e++)
74 if (*e == ':')
75 break;
76 if (*e == ':')
77 dataport = atoi (e + 1);
78 *e = 0;
79 d++;
81 else
82 d = 0;
84 sport = atoi (c + 1);
86 dport = atoi (b + 1);
88 else
89 dport = 3671;
91 iface = new EIBNetIPTunnel (a, dport, sport, d, dataport, flags, t);
92 free (a);
93 return iface;
96 inline Layer2Interface *
97 eibnetiptunnelnat_Create (const char *dev, int flags, Trace * t)
99 char *a = strdup (dev);
100 char *b;
101 char *c;
102 int dport;
103 int sport;
104 Layer2Interface *iface;
105 if (!a)
106 die ("out of memory");
107 for (b = a; *b; b++)
108 if (*b == ':')
109 break;
110 sport = 3672;
111 if (*b == ':')
113 *b = 0;
114 for (c = b + 1; *c; c++)
115 if (*c == ':')
116 break;
117 if (*c == ':')
119 *c = 0;
120 sport = atoi (c + 1);
122 dport = atoi (b + 1);
124 else
125 dport = 3671;
127 iface = new EIBNetIPTunnel (a, dport, sport, "0.0.0.0", -1, flags, t);
128 free (a);
129 return iface;
133 #endif