mirror of
https://github.com/OpenVPN/openvpn.git
synced 2026-05-28 04:03:29 -04:00
build: move inet_ntop(), inet_pton() emulation into compat
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>
This commit is contained in:
parent
7b49c16761
commit
f106f64b1c
8 changed files with 183 additions and 64 deletions
|
|
@ -522,7 +522,7 @@ AC_CHECK_FUNCS([ \
|
|||
chsize ftruncate execve getpeereid umask basename dirname access \
|
||||
epoll_create \
|
||||
])
|
||||
AC_CHECK_FUNCS([sendmsg recvmsg])
|
||||
AC_CHECK_FUNCS([sendmsg recvmsg inet_ntop inet_pton])
|
||||
AC_CHECK_FUNCS(
|
||||
[res_init],
|
||||
,
|
||||
|
|
|
|||
|
|
@ -22,4 +22,6 @@ libcompat_la_SOURCES = \
|
|||
compat-dirname.c \
|
||||
compat-basename.c \
|
||||
compat-gettimeofday.c \
|
||||
compat-daemon.c
|
||||
compat-daemon.c \
|
||||
compat-inet_ntop.c \
|
||||
compat-inet_pton.c
|
||||
|
|
|
|||
76
src/compat/compat-inet_ntop.c
Normal file
76
src/compat/compat-inet_ntop.c
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* OpenVPN -- An application to securely tunnel IP networks
|
||||
* over a single UDP port, with support for SSL/TLS-based
|
||||
* session authentication and key exchange,
|
||||
* packet encryption, packet authentication, and
|
||||
* packet compression.
|
||||
*
|
||||
* Copyright (C) 2011 - David Sommerseth <davids@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program (see the file COPYING included with this
|
||||
* distribution); if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#elif defined(_MSC_VER)
|
||||
#include "config-msvc.h"
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_NTOP
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
/*
|
||||
* inet_ntop() and inet_pton() wrap-implementations using
|
||||
* WSAAddressToString() and WSAStringToAddress() functions
|
||||
*
|
||||
* this is needed as long as we support running OpenVPN on WinXP
|
||||
*/
|
||||
|
||||
const char *
|
||||
inet_ntop(int af, const void *src, char *dst, socklen_t size)
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
unsigned long s = size;
|
||||
|
||||
ZeroMemory(&ss, sizeof(ss));
|
||||
ss.ss_family = af;
|
||||
|
||||
switch(af) {
|
||||
case AF_INET:
|
||||
((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src;
|
||||
break;
|
||||
case AF_INET6:
|
||||
((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src;
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
/* cannot direclty use &size because of strict aliasing rules */
|
||||
return (WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, &s) == 0)?
|
||||
dst : NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error no emulation for inet_ntop
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
79
src/compat/compat-inet_pton.c
Normal file
79
src/compat/compat-inet_pton.c
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* OpenVPN -- An application to securely tunnel IP networks
|
||||
* over a single UDP port, with support for SSL/TLS-based
|
||||
* session authentication and key exchange,
|
||||
* packet encryption, packet authentication, and
|
||||
* packet compression.
|
||||
*
|
||||
* Copyright (C) 2011 - David Sommerseth <davids@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program (see the file COPYING included with this
|
||||
* distribution); if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#elif defined(_MSC_VER)
|
||||
#include "config-msvc.h"
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_PTON
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* inet_ntop() and inet_pton() wrap-implementations using
|
||||
* WSAAddressToString() and WSAStringToAddress() functions
|
||||
*
|
||||
* this is needed as long as we support running OpenVPN on WinXP
|
||||
*/
|
||||
|
||||
|
||||
int
|
||||
inet_pton(int af, const char *src, void *dst)
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
int size = sizeof(ss);
|
||||
char src_copy[INET6_ADDRSTRLEN+1];
|
||||
|
||||
ZeroMemory(&ss, sizeof(ss));
|
||||
/* stupid non-const API */
|
||||
strncpy (src_copy, src, INET6_ADDRSTRLEN+1);
|
||||
src_copy[INET6_ADDRSTRLEN] = 0;
|
||||
|
||||
if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0) {
|
||||
switch(af) {
|
||||
case AF_INET:
|
||||
*(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr;
|
||||
return 1;
|
||||
case AF_INET6:
|
||||
*(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error no emulation for inet_ntop
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -26,14 +26,21 @@
|
|||
#define COMPAT_H
|
||||
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
/* timeval */
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WS2TCPIP_H
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DIRNAME
|
||||
char * dirname(char *str);
|
||||
#endif /* HAVE_DIRNAME */
|
||||
|
|
@ -50,4 +57,12 @@ int gettimeofday (struct timeval *tv, void *tz);
|
|||
int daemon(int nochdir, int noclose);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_NTOP
|
||||
const char * inet_ntop(int af, const void *src, char *dst, socklen_t size);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_PTON
|
||||
int inet_pton(int af, const char *src, void *dst);
|
||||
#endif
|
||||
|
||||
#endif /* COMPAT_H */
|
||||
|
|
|
|||
|
|
@ -162,6 +162,14 @@
|
|||
RelativePath=".\compat-gettimeofday.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\compat-inet_ntop.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\compat-inet_pton.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\compat-daemon.c"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -3086,61 +3086,6 @@ link_socket_write_udp_posix_sendmsg (struct link_socket *sock,
|
|||
|
||||
#ifdef WIN32
|
||||
|
||||
/*
|
||||
* inet_ntop() and inet_pton() wrap-implementations using
|
||||
* WSAAddressToString() and WSAStringToAddress() functions
|
||||
*
|
||||
* this is needed as long as we support running OpenVPN on WinXP
|
||||
*/
|
||||
|
||||
const char *
|
||||
openvpn_inet_ntop(int af, const void *src, char *dst, socklen_t size)
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
unsigned long s = size;
|
||||
|
||||
CLEAR(ss);
|
||||
ss.ss_family = af;
|
||||
|
||||
switch(af) {
|
||||
case AF_INET:
|
||||
((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src;
|
||||
break;
|
||||
case AF_INET6:
|
||||
((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src;
|
||||
break;
|
||||
default:
|
||||
ASSERT (0);
|
||||
}
|
||||
/* cannot direclty use &size because of strict aliasing rules */
|
||||
return (WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, &s) == 0)?
|
||||
dst : NULL;
|
||||
}
|
||||
|
||||
int
|
||||
openvpn_inet_pton(int af, const char *src, void *dst)
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
int size = sizeof(ss);
|
||||
char src_copy[INET6_ADDRSTRLEN+1];
|
||||
|
||||
CLEAR(ss);
|
||||
/* stupid non-const API */
|
||||
strncpynt(src_copy, src, INET6_ADDRSTRLEN+1);
|
||||
|
||||
if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0) {
|
||||
switch(af) {
|
||||
case AF_INET:
|
||||
*(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr;
|
||||
return 1;
|
||||
case AF_INET6:
|
||||
*(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
socket_recv_queue (struct link_socket *sock, int maxsize)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -266,12 +266,6 @@ char *get_win_sys_path (void);
|
|||
/* call self in a subprocess */
|
||||
void fork_to_self (const char *cmdline);
|
||||
|
||||
const char *openvpn_inet_ntop(int af, const void *src,
|
||||
char *dst, socklen_t size);
|
||||
int openvpn_inet_pton(int af, const char *src, void *dst);
|
||||
#define inet_ntop(af,src,dst,size) openvpn_inet_ntop(af,src,dst,size)
|
||||
#define inet_pton(af,src,dst) openvpn_inet_pton(af,src,dst)
|
||||
|
||||
/* Find temporary directory */
|
||||
const char *win_get_tempdir();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue