aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2019-05-24 01:28:39 +0200
committerToni Uhlig <matzeton@googlemail.com>2019-05-24 01:28:39 +0200
commit1d2c692c1237f51058b91fd3086d724daf34e9f9 (patch)
tree1aac5ddd20dddef98bafe8c20f9f0244ad19ecfc
parent89486f4f9a4f5e506e48a6c10ba0e9c7e5aa9ecd (diff)
added Npcap support (fixes #14)
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--configure.ac11
-rw-r--r--src/Makefile.am7
-rw-r--r--src/ptunnel.c31
3 files changed, 44 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index 5a6af52..d1b48a7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,6 +128,16 @@ case ${pcap_enabled} in
*) AC_MSG_ERROR([Unknown option \`${pcap_enabled}\` for --disable-pcap]) ;;
esac
+dnl `--enable-npcap`: Enable npcap interface (Windows only!)
+AC_ARG_ENABLE([npcap],
+ [AS_HELP_STRING([--enable-npcap], [Enable npcap support. (Windows only; default: disabled)])],[npcap_enabled=yes],)
+npcap_enabled=$(echo ${npcap_enabled})
+case ${npcap_enabled} in
+ 1|y|yes) pcap_enabled=yes ;;
+ ''|0|n|no) pcap_enabled= ;;
+ *) AC_MSG_ERROR([Unknown option \`${npcap_enabled}\` for --enable-npcap]) ;;
+esac
+
dnl `--disable-selinux`: Enabled if found.
AC_ARG_ENABLE([selinux],
[AS_HELP_STRING([--disable-selinux], [Disable SELINUX support. (default: enabled if found)])],,[selinux_enabled=yes])
@@ -203,6 +213,7 @@ AC_SEARCH_LIBS([__android_log_vprint], [log],,,)
dnl Set automake conf vars
AM_CONDITIONAL([HAVE_PCAP], [test x"${pcap_enabled}" = xyes])
+AM_CONDITIONAL([HAVE_NPCAP], [test x"${npcap_enabled}" = xyes])
AM_CONDITIONAL([HAVE_SELINUX], [test x"${selinux_enabled}" = xyes])
AM_CONDITIONAL([IS_WINDOWS], [test x"${use_msw}" = xyes])
AM_CONDITIONAL([HAVE_ICMPFILTER], [test x"${with_icmp_filter}" = xyes])
diff --git a/src/Makefile.am b/src/Makefile.am
index 8d4787a..b39d89e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -38,12 +38,15 @@ ptunnel_ng_SOURCES = \
if IS_WINDOWS
wpcap_DEF = $(abs_srcdir)/win32/WPCAP.DEF
wpcap_IMP = $(abs_srcdir)/win32/libwpcap_implib.a
-ptunnel_ng_CFLAGS += -I$(abs_srcdir)/win32/includes
+ptunnel_ng_CFLAGS += -I$(abs_srcdir)/win32/includes -DHAVE_PCAP=1
+if HAVE_NPCAP
+ptunnel_ng_CFLAGS += -DHAVE_NPCAP=1
+endif
ptunnel_ng_LDADD += $(wpcap_IMP)
ptunnel_ng_SOURCES += $(wpcap_DEF)
$(wpcap_IMP):
- @DLLTOOL@ -k -l $(wpcap_IMP) --def $(wpcap_DEF)
+ @DLLTOOL@ -k -y $(wpcap_IMP) --def $(wpcap_DEF)
CLEANFILES += $(wpcap_IMP)
EXTTRA_DIST += $(wpcap_DEF)
diff --git a/src/ptunnel.c b/src/ptunnel.c
index 4b3816d..bdf0a6f 100644
--- a/src/ptunnel.c
+++ b/src/ptunnel.c
@@ -54,6 +54,7 @@
#endif
#ifdef WIN32
+#include <tchar.h>
#include <winsock2.h>
/* Map errno (which Winsock doesn't use) to GetLastError; include the code in the strerror */
#ifdef errno
@@ -75,6 +76,25 @@ static char * print_last_windows_error() {
#define strerror(x) print_last_windows_error()
#endif /* WIN32 */
+#ifdef HAVE_NPCAP
+static BOOL LoadNpcapDlls()
+{
+ TCHAR npcap_dir[512];
+ UINT len;
+ len = GetSystemDirectory(npcap_dir, 480);
+ if (!len) {
+ pt_log(kLog_error, "Error in GetSystemDirectory: %x", GetLastError());
+ return FALSE;
+ }
+ _tcscat_s(npcap_dir, 512, _T("\\Npcap"));
+ if (SetDllDirectory(npcap_dir) == 0) {
+ pt_log(kLog_error, "Error in SetDllDirectory: %x", GetLastError());
+ return FALSE;
+ }
+ return TRUE;
+}
+#endif
+
/* globals */
/** Lock protecting the chain of connections */
pthread_mutex_t chain_lock;
@@ -150,6 +170,11 @@ int main(int argc, char *argv[]) {
}
#endif /* WIN32 */
+#ifdef HAVE_NPCAP
+ if (!LoadNpcapDlls())
+ return -1;
+#endif
+
memset(opts.password_digest, 0, kMD5_digest_size);
/* The seq_expiry_tbl is used to prevent the remote ends from prematurely
@@ -181,9 +206,9 @@ int main(int argc, char *argv[]) {
}
#ifdef WIN32
if (!opts.pcap && !opts.udp) {
- pt_log(kLog_info, "Running ptunnel-ng on Windows in ICMP mode without WinPcap enabled is not supported and may not work!\n");
- pt_log(kLog_info, "If you encounter problems, install WinPCAP from:\n");
- pt_log(kLog_info, "https://www.winpcap.org/install/default.htm or for WIN10: https://nmap.org/npcap/windows-10.html\n");
+ pt_log(kLog_info, "Running ptunnel-ng on Windows in ICMP mode without WinPcap/Npcap enabled is not supported and may not work!\n");
+ pt_log(kLog_info, "If you encounter problems, install WinPCAP/Npcap from:\n");
+ pt_log(kLog_info, "https://www.winpcap.org/install/default.htm or Npcap for WIN10: https://nmap.org/npcap/windows-10.html\n");
pt_log(kLog_info, "After WinPCAP is installed, you can list pcap devices with: --list-pcap-devices\n");
}
#endif