summaryrefslogtreecommitdiff
blob: 2187882fd8af4fca3184fb8b477c4736fb8473e8 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
diff -Naur openl2tp-1.7.base/Makefile openl2tp-1.7/Makefile
--- openl2tp-1.7.base/Makefile	2010-11-10 19:12:31.000000000 +0300
+++ openl2tp-1.7/Makefile	2010-11-10 20:15:09.916132583 +0300
@@ -103,6 +103,10 @@
 			l2tp_network.c l2tp_tunnel.c l2tp_peer.c l2tp_transport.c \
 			l2tp_session.c l2tp_ppp.c \
 			l2tp_plugin.c l2tp_event.c l2tp_test.c md5.c
+
+ifeq ($(L2TP_FEATURE_LOCAL_CONF_FILE),y)
+L2TPD_SRCS.c+=		cli/cli_util.c
+endif
 ifeq ($(L2TP_FEATURE_RPC_MANAGEMENT),y)
 L2TPD_SRCS.c+=		l2tp_api.c
 endif
diff -Naur openl2tp-1.7.base/cli/Makefile openl2tp-1.7/cli/Makefile
--- openl2tp-1.7.base/cli/Makefile	2010-11-10 19:12:31.000000000 +0300
+++ openl2tp-1.7/cli/Makefile	2010-11-10 20:03:51.870627874 +0300
@@ -1,4 +1,4 @@
-CLI_SRCS.c=		cli_lib.c cli_readline.c
+CLI_SRCS.c=		cli_lib.c cli_readline.c cli_util.c
 CLI_SRCS.h=		cli_api.h cli_private.h
 CLI_SRCS_TEST.c=	cli_test.c
 
diff -Naur openl2tp-1.7.base/cli/cli_lib.c openl2tp-1.7/cli/cli_lib.c
--- openl2tp-1.7.base/cli/cli_lib.c	2008-05-08 00:44:20.000000000 +0400
+++ openl2tp-1.7/cli/cli_lib.c	2010-11-10 20:05:20.876911771 +0300
@@ -19,9 +19,6 @@
  *****************************************************************************/
 
 #include <stdio.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
 #include <asm/types.h>
 
 #include <readline/readline.h>
@@ -29,6 +26,7 @@
 
 #include "cli_api.h"
 #include "cli_private.h"
+#include "cli_util.h"
 
 
 static struct cli_node *cli_nodes;
@@ -652,7 +650,7 @@
 	struct in_addr *ip = result;
 	int ret = 0;
 
-	ret = inet_aton(val, ip);
+	ret = cli_resolveip(val, ip);
 	if (ret != 1) {
 		ret = -EINVAL;
 	} else {
diff -Naur openl2tp-1.7.base/cli/cli_util.c openl2tp-1.7/cli/cli_util.c
--- openl2tp-1.7.base/cli/cli_util.c	1970-01-01 03:00:00.000000000 +0300
+++ openl2tp-1.7/cli/cli_util.c	2010-11-10 20:09:08.158552473 +0300
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * 
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301 USA
+ *
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+/* Resolve hostname or ipaddr into struct in_addr.
+ * Returns 1 on success, 0 on failure. */
+int cli_resolveip(const char *val, struct in_addr *ip)
+{
+	int code;
+	struct addrinfo *res;
+
+	code = getaddrinfo(val, NULL, NULL, &res);
+	if (code) {
+		printf("Failed to resolve address '%s': %s\n", val, gai_strerror(code));
+		return 0;
+	}
+
+	// use the first ip address available,
+	// save it inside provided in_addr structure.
+	ip->s_addr = ((struct sockaddr_in*)(res->ai_addr))->sin_addr.s_addr;
+
+	freeaddrinfo(res);
+	return 1;
+}
+
diff -Naur openl2tp-1.7.base/cli/cli_util.h openl2tp-1.7/cli/cli_util.h
--- openl2tp-1.7.base/cli/cli_util.h	1970-01-01 03:00:00.000000000 +0300
+++ openl2tp-1.7/cli/cli_util.h	2010-11-10 20:07:47.304346301 +0300
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * 
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301 USA
+ *
+ *****************************************************************************/
+
+/* Resolve hostname or ipaddr into struct in_addr.
+ * Returns 1 on success, 0 on failure. */
+int cli_resolveip(const char *val, struct in_addr *ip);
diff -Naur openl2tp-1.7.base/l2tp_config_token.l openl2tp-1.7/l2tp_config_token.l
--- openl2tp-1.7.base/l2tp_config_token.l	2010-03-10 17:18:51.000000000 +0300
+++ openl2tp-1.7/l2tp_config_token.l	2010-11-10 20:19:08.985957657 +0300
@@ -2,9 +2,7 @@
 
 #include <sys/types.h>
 #include <sys/param.h>
-#include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/inet.h>
 #include <stdlib.h>
 #include <limits.h>
 #include <string.h>
@@ -14,6 +12,7 @@
 
 #include "l2tp_config_types.h"
 #include "l2tp_config_parse.h"
+#include "cli/cli_util.h"
 
 void yyfatal(const char *s);
 void yyerror(const char *s);
@@ -273,7 +272,7 @@
 
 {ipaddress}	{
 			struct in_addr addr;
-			if (!inet_aton(yytext, &addr))
+			if (!cli_resolveip(yytext, &addr))
 				yyfatal("invalid IP address");
 			yylval.ulnum = ntohl(addr.s_addr);
 			return(IPADDRESS);