Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Acked-by: Samuli Seppänen <samuli@openvpn.net>
Acked-by: David Sommerseth <davids@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
| ... | ... |
@@ -522,7 +522,7 @@ AC_CHECK_FUNCS([ \ |
| 522 | 522 |
chsize ftruncate execve getpeereid umask basename dirname access \ |
| 523 | 523 |
epoll_create \ |
| 524 | 524 |
]) |
| 525 |
-AC_CHECK_FUNCS([sendmsg recvmsg]) |
|
| 525 |
+AC_CHECK_FUNCS([sendmsg recvmsg inet_ntop inet_pton]) |
|
| 526 | 526 |
AC_CHECK_FUNCS( |
| 527 | 527 |
[res_init], |
| 528 | 528 |
, |
| 26 | 28 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,76 @@ |
| 0 |
+/* |
|
| 1 |
+ * OpenVPN -- An application to securely tunnel IP networks |
|
| 2 |
+ * over a single UDP port, with support for SSL/TLS-based |
|
| 3 |
+ * session authentication and key exchange, |
|
| 4 |
+ * packet encryption, packet authentication, and |
|
| 5 |
+ * packet compression. |
|
| 6 |
+ * |
|
| 7 |
+ * Copyright (C) 2011 - David Sommerseth <davids@redhat.com> |
|
| 8 |
+ * |
|
| 9 |
+ * This program is free software; you can redistribute it and/or modify |
|
| 10 |
+ * it under the terms of the GNU General Public License version 2 |
|
| 11 |
+ * as published by the Free Software Foundation. |
|
| 12 |
+ * |
|
| 13 |
+ * This program is distributed in the hope that it will be useful, |
|
| 14 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 15 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 16 |
+ * GNU General Public License for more details. |
|
| 17 |
+ * |
|
| 18 |
+ * You should have received a copy of the GNU General Public License |
|
| 19 |
+ * along with this program (see the file COPYING included with this |
|
| 20 |
+ * distribution); if not, write to the Free Software Foundation, Inc., |
|
| 21 |
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 22 |
+ */ |
|
| 23 |
+ |
|
| 24 |
+#ifdef HAVE_CONFIG_H |
|
| 25 |
+#include "config.h" |
|
| 26 |
+#elif defined(_MSC_VER) |
|
| 27 |
+#include "config-msvc.h" |
|
| 28 |
+#endif |
|
| 29 |
+ |
|
| 30 |
+#ifndef HAVE_INET_NTOP |
|
| 31 |
+ |
|
| 32 |
+#include "compat.h" |
|
| 33 |
+ |
|
| 34 |
+#ifdef WIN32 |
|
| 35 |
+ |
|
| 36 |
+#include <windows.h> |
|
| 37 |
+ |
|
| 38 |
+/* |
|
| 39 |
+ * inet_ntop() and inet_pton() wrap-implementations using |
|
| 40 |
+ * WSAAddressToString() and WSAStringToAddress() functions |
|
| 41 |
+ * |
|
| 42 |
+ * this is needed as long as we support running OpenVPN on WinXP |
|
| 43 |
+ */ |
|
| 44 |
+ |
|
| 45 |
+const char * |
|
| 46 |
+inet_ntop(int af, const void *src, char *dst, socklen_t size) |
|
| 47 |
+{
|
|
| 48 |
+ struct sockaddr_storage ss; |
|
| 49 |
+ unsigned long s = size; |
|
| 50 |
+ |
|
| 51 |
+ ZeroMemory(&ss, sizeof(ss)); |
|
| 52 |
+ ss.ss_family = af; |
|
| 53 |
+ |
|
| 54 |
+ switch(af) {
|
|
| 55 |
+ case AF_INET: |
|
| 56 |
+ ((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src; |
|
| 57 |
+ break; |
|
| 58 |
+ case AF_INET6: |
|
| 59 |
+ ((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src; |
|
| 60 |
+ break; |
|
| 61 |
+ default: |
|
| 62 |
+ return NULL; |
|
| 63 |
+ } |
|
| 64 |
+ /* cannot direclty use &size because of strict aliasing rules */ |
|
| 65 |
+ return (WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, &s) == 0)? |
|
| 66 |
+ dst : NULL; |
|
| 67 |
+} |
|
| 68 |
+ |
|
| 69 |
+#else |
|
| 70 |
+ |
|
| 71 |
+#error no emulation for inet_ntop |
|
| 72 |
+ |
|
| 73 |
+#endif |
|
| 74 |
+ |
|
| 75 |
+#endif |
| 0 | 76 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,79 @@ |
| 0 |
+/* |
|
| 1 |
+ * OpenVPN -- An application to securely tunnel IP networks |
|
| 2 |
+ * over a single UDP port, with support for SSL/TLS-based |
|
| 3 |
+ * session authentication and key exchange, |
|
| 4 |
+ * packet encryption, packet authentication, and |
|
| 5 |
+ * packet compression. |
|
| 6 |
+ * |
|
| 7 |
+ * Copyright (C) 2011 - David Sommerseth <davids@redhat.com> |
|
| 8 |
+ * |
|
| 9 |
+ * This program is free software; you can redistribute it and/or modify |
|
| 10 |
+ * it under the terms of the GNU General Public License version 2 |
|
| 11 |
+ * as published by the Free Software Foundation. |
|
| 12 |
+ * |
|
| 13 |
+ * This program is distributed in the hope that it will be useful, |
|
| 14 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 15 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 16 |
+ * GNU General Public License for more details. |
|
| 17 |
+ * |
|
| 18 |
+ * You should have received a copy of the GNU General Public License |
|
| 19 |
+ * along with this program (see the file COPYING included with this |
|
| 20 |
+ * distribution); if not, write to the Free Software Foundation, Inc., |
|
| 21 |
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 22 |
+ */ |
|
| 23 |
+ |
|
| 24 |
+#ifdef HAVE_CONFIG_H |
|
| 25 |
+#include "config.h" |
|
| 26 |
+#elif defined(_MSC_VER) |
|
| 27 |
+#include "config-msvc.h" |
|
| 28 |
+#endif |
|
| 29 |
+ |
|
| 30 |
+#ifndef HAVE_INET_PTON |
|
| 31 |
+ |
|
| 32 |
+#include "compat.h" |
|
| 33 |
+ |
|
| 34 |
+#ifdef WIN32 |
|
| 35 |
+ |
|
| 36 |
+#include <windows.h> |
|
| 37 |
+#include <string.h> |
|
| 38 |
+ |
|
| 39 |
+/* |
|
| 40 |
+ * inet_ntop() and inet_pton() wrap-implementations using |
|
| 41 |
+ * WSAAddressToString() and WSAStringToAddress() functions |
|
| 42 |
+ * |
|
| 43 |
+ * this is needed as long as we support running OpenVPN on WinXP |
|
| 44 |
+ */ |
|
| 45 |
+ |
|
| 46 |
+ |
|
| 47 |
+int |
|
| 48 |
+inet_pton(int af, const char *src, void *dst) |
|
| 49 |
+{
|
|
| 50 |
+ struct sockaddr_storage ss; |
|
| 51 |
+ int size = sizeof(ss); |
|
| 52 |
+ char src_copy[INET6_ADDRSTRLEN+1]; |
|
| 53 |
+ |
|
| 54 |
+ ZeroMemory(&ss, sizeof(ss)); |
|
| 55 |
+ /* stupid non-const API */ |
|
| 56 |
+ strncpy (src_copy, src, INET6_ADDRSTRLEN+1); |
|
| 57 |
+ src_copy[INET6_ADDRSTRLEN] = 0; |
|
| 58 |
+ |
|
| 59 |
+ if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0) {
|
|
| 60 |
+ switch(af) {
|
|
| 61 |
+ case AF_INET: |
|
| 62 |
+ *(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr; |
|
| 63 |
+ return 1; |
|
| 64 |
+ case AF_INET6: |
|
| 65 |
+ *(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr; |
|
| 66 |
+ return 1; |
|
| 67 |
+ } |
|
| 68 |
+ } |
|
| 69 |
+ return 0; |
|
| 70 |
+} |
|
| 71 |
+ |
|
| 72 |
+#else |
|
| 73 |
+ |
|
| 74 |
+#error no emulation for inet_ntop |
|
| 75 |
+ |
|
| 76 |
+#endif |
|
| 77 |
+ |
|
| 78 |
+#endif |
| ... | ... |
@@ -26,14 +26,21 @@ |
| 26 | 26 |
#define COMPAT_H |
| 27 | 27 |
|
| 28 | 28 |
#ifdef HAVE_WINSOCK2_H |
| 29 |
-/* timeval */ |
|
| 30 | 29 |
#include <winsock2.h> |
| 31 | 30 |
#endif |
| 32 | 31 |
|
| 32 |
+#ifdef HAVE_WS2TCPIP_H |
|
| 33 |
+#include <ws2tcpip.h> |
|
| 34 |
+#endif |
|
| 35 |
+ |
|
| 33 | 36 |
#ifdef HAVE_SYS_TIME_H |
| 34 | 37 |
#include <sys/time.h> |
| 35 | 38 |
#endif |
| 36 | 39 |
|
| 40 |
+#ifdef HAVE_SYS_SOCKET_H |
|
| 41 |
+#include <sys/socket.h> |
|
| 42 |
+#endif |
|
| 43 |
+ |
|
| 37 | 44 |
#ifndef HAVE_DIRNAME |
| 38 | 45 |
char * dirname(char *str); |
| 39 | 46 |
#endif /* HAVE_DIRNAME */ |
| ... | ... |
@@ -50,4 +57,12 @@ int gettimeofday (struct timeval *tv, void *tz); |
| 50 | 50 |
int daemon(int nochdir, int noclose); |
| 51 | 51 |
#endif |
| 52 | 52 |
|
| 53 |
+#ifndef HAVE_INET_NTOP |
|
| 54 |
+const char * inet_ntop(int af, const void *src, char *dst, socklen_t size); |
|
| 55 |
+#endif |
|
| 56 |
+ |
|
| 57 |
+#ifndef HAVE_INET_PTON |
|
| 58 |
+int inet_pton(int af, const char *src, void *dst); |
|
| 59 |
+#endif |
|
| 60 |
+ |
|
| 53 | 61 |
#endif /* COMPAT_H */ |
| ... | ... |
@@ -3086,61 +3086,6 @@ link_socket_write_udp_posix_sendmsg (struct link_socket *sock, |
| 3086 | 3086 |
|
| 3087 | 3087 |
#ifdef WIN32 |
| 3088 | 3088 |
|
| 3089 |
-/* |
|
| 3090 |
- * inet_ntop() and inet_pton() wrap-implementations using |
|
| 3091 |
- * WSAAddressToString() and WSAStringToAddress() functions |
|
| 3092 |
- * |
|
| 3093 |
- * this is needed as long as we support running OpenVPN on WinXP |
|
| 3094 |
- */ |
|
| 3095 |
- |
|
| 3096 |
-const char * |
|
| 3097 |
-openvpn_inet_ntop(int af, const void *src, char *dst, socklen_t size) |
|
| 3098 |
-{
|
|
| 3099 |
- struct sockaddr_storage ss; |
|
| 3100 |
- unsigned long s = size; |
|
| 3101 |
- |
|
| 3102 |
- CLEAR(ss); |
|
| 3103 |
- ss.ss_family = af; |
|
| 3104 |
- |
|
| 3105 |
- switch(af) {
|
|
| 3106 |
- case AF_INET: |
|
| 3107 |
- ((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src; |
|
| 3108 |
- break; |
|
| 3109 |
- case AF_INET6: |
|
| 3110 |
- ((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src; |
|
| 3111 |
- break; |
|
| 3112 |
- default: |
|
| 3113 |
- ASSERT (0); |
|
| 3114 |
- } |
|
| 3115 |
- /* cannot direclty use &size because of strict aliasing rules */ |
|
| 3116 |
- return (WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, &s) == 0)? |
|
| 3117 |
- dst : NULL; |
|
| 3118 |
-} |
|
| 3119 |
- |
|
| 3120 |
-int |
|
| 3121 |
-openvpn_inet_pton(int af, const char *src, void *dst) |
|
| 3122 |
-{
|
|
| 3123 |
- struct sockaddr_storage ss; |
|
| 3124 |
- int size = sizeof(ss); |
|
| 3125 |
- char src_copy[INET6_ADDRSTRLEN+1]; |
|
| 3126 |
- |
|
| 3127 |
- CLEAR(ss); |
|
| 3128 |
- /* stupid non-const API */ |
|
| 3129 |
- strncpynt(src_copy, src, INET6_ADDRSTRLEN+1); |
|
| 3130 |
- |
|
| 3131 |
- if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0) {
|
|
| 3132 |
- switch(af) {
|
|
| 3133 |
- case AF_INET: |
|
| 3134 |
- *(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr; |
|
| 3135 |
- return 1; |
|
| 3136 |
- case AF_INET6: |
|
| 3137 |
- *(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr; |
|
| 3138 |
- return 1; |
|
| 3139 |
- } |
|
| 3140 |
- } |
|
| 3141 |
- return 0; |
|
| 3142 |
-} |
|
| 3143 |
- |
|
| 3144 | 3089 |
int |
| 3145 | 3090 |
socket_recv_queue (struct link_socket *sock, int maxsize) |
| 3146 | 3091 |
{
|
| ... | ... |
@@ -266,12 +266,6 @@ char *get_win_sys_path (void); |
| 266 | 266 |
/* call self in a subprocess */ |
| 267 | 267 |
void fork_to_self (const char *cmdline); |
| 268 | 268 |
|
| 269 |
-const char *openvpn_inet_ntop(int af, const void *src, |
|
| 270 |
- char *dst, socklen_t size); |
|
| 271 |
-int openvpn_inet_pton(int af, const char *src, void *dst); |
|
| 272 |
-#define inet_ntop(af,src,dst,size) openvpn_inet_ntop(af,src,dst,size) |
|
| 273 |
-#define inet_pton(af,src,dst) openvpn_inet_pton(af,src,dst) |
|
| 274 |
- |
|
| 275 | 269 |
/* Find temporary directory */ |
| 276 | 270 |
const char *win_get_tempdir(); |
| 277 | 271 |
|