aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2017-12-19 21:12:55 +0100
committerToni Uhlig <matzeton@googlemail.com>2017-12-19 21:12:55 +0100
commit00e2c4e6849adc1b9cc8b9daf9069d67ff086dc3 (patch)
tree1f9df654212d9d37e178470d99d0338fc0b4a0ad /src
parent4176fdf0b64f068d123a0d960beb1eb5708f3e7b (diff)
ptunnel-ng:
* fixed missing conditionaled compile for pcap * ported to mingw64
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/options.c2
-rw-r--r--src/options.h2
-rw-r--r--src/pdesc.h2
-rw-r--r--src/pkt.h6
-rw-r--r--src/ptunnel.c31
-rw-r--r--src/ptunnel.h10
7 files changed, 27 insertions, 30 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 4e802cc..5d51807 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,12 +2,16 @@ bin_PROGRAMS = ptunnel-ng
man8_MANS = ptunnel-ng.8
ptunnel_ng_CFLAGS = -Wall
+ptunnel_ng_LDADD =
if HAVE_PCAP
ptunnel_ng_CFLAGS += -DHAVE_PCAP=1
endif
if HAVE_SELINUX
ptunnel_ng_CFLAGS += -DHAVE_SELINUX=1
endif
+if IS_WINDOWS
+ptunnel_ng_LDADD += -lws2_32
+endif
ptunnel_ng_SOURCES = \
md5.c \
diff --git a/src/options.c b/src/options.c
index 01a98db..b8487e0 100644
--- a/src/options.c
+++ b/src/options.c
@@ -504,8 +504,10 @@ int parse_options(int argc, char **argv) {
}
opts.given_dst_ip = *(uint32_t*)host_ent->h_addr_list[0];
+#ifndef WIN32
if (NULL == (opts.pid_file = fopen(opts.pid_path, "w")))
pt_log(kLog_error, "Failed to open pidfile: \"%s\", Cause: %s\n", opts.pid_path, strerror(errno));
+#endif
if (has_logfile && opts.log_path) {
pt_log(kLog_info, "Open Logfile: \"%s\"\n", opts.log_path);
diff --git a/src/options.h b/src/options.h
index 9029b6a..bdd2061 100644
--- a/src/options.h
+++ b/src/options.h
@@ -4,8 +4,10 @@
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
+#ifndef WIN32
#include <pwd.h>
#include <grp.h>
+#endif
#ifdef HAVE_SELINUX
#include <selinux/selinux.h>
#endif
diff --git a/src/pdesc.h b/src/pdesc.h
index 18751b7..9c759ef 100644
--- a/src/pdesc.h
+++ b/src/pdesc.h
@@ -2,9 +2,11 @@
#define PDESC_H 1
#include <stdint.h>
+#ifndef WIN32
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#endif
#include "pkt.h"
#include "challenge.h"
diff --git a/src/pkt.h b/src/pkt.h
index 22c039d..2376824 100644
--- a/src/pkt.h
+++ b/src/pkt.h
@@ -9,9 +9,9 @@ typedef int socklen_t;
typedef uint32_t in_addr_t;
#define ETH_ALEN 6 /* Octets in one ethernet addr */
struct ether_header {
- u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
- u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */
- u_int16_t ether_type; /* packet type ID field */
+ uint8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
+ uint8_t ether_shost[ETH_ALEN]; /* source ether addr */
+ uint16_t ether_type; /* packet type ID field */
};
#endif /* WIN32 */
diff --git a/src/ptunnel.c b/src/ptunnel.c
index b8f022c..927d440 100644
--- a/src/ptunnel.c
+++ b/src/ptunnel.c
@@ -54,13 +54,6 @@
#endif
#ifdef WIN32
-/** pthread porting to windows */
-typedef CRITICAL_SECTION pthread_mutex_t;
-typedef unsigned long pthread_t;
-#define pthread_mutex_init InitializeCriticalSectionAndSpinCount
-#define pthread_mutex_lock EnterCriticalSection
-#define pthread_mutex_unlock LeaveCriticalSection
-
#include <winsock2.h>
/* Map errno (which Winsock doesn't use) to GetLastError; include the code in the strerror */
#ifdef errno
@@ -74,7 +67,7 @@ static char * print_last_windows_error() {
memset(errorstr, 0, sizeof(errorstr));
FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, last_error, 0, errorstr, sizeof(errorstr), NULL);
- snprintf(errorstr, sizeof(errorstr), "%s (%d)", errorstr, last_error);
+ snprintf(errorstr, sizeof(errorstr), "%s (%lu)", errorstr, last_error);
return errorstr;
}
#define strerror(x) print_last_windows_error()
@@ -116,7 +109,7 @@ int main(int argc, char *argv[]) {
WSADATA wsaData;
int err;
- wVersionRequested = MAKEWORD( 2, 2 );
+ wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
@@ -216,24 +209,6 @@ int main(int argc, char *argv[]) {
}
#endif /* !WIN32 */
-#ifdef WIN32
- WORD wVersionRequested;
- WSADATA wsaData;
- int err;
-
- wVersionRequested = MAKEWORD( 2, 2 );
-
- err = WSAStartup( wVersionRequested, &wsaData );
- if ( err != 0 ) {
- return -1;
- }
-
- if ( LOBYTE( wsaData.wVersion ) != 2 ||
- HIBYTE( wsaData.wVersion ) != 2 ) {
- WSACleanup();
- return -1;
- }
-#endif /* WIN32 */
pthread_mutex_init(&chain_lock, 0);
pthread_mutex_init(&num_threads_lock, 0);
@@ -710,6 +685,7 @@ void print_statistics(xfer_stats_t *xfer, int is_continuous) {
fflush(stdout);
}
+#ifdef HAVE_PCAP
/* pcap_packet_handler:
* This is our callback function handling captured packets. We already know that the packets
* are ICMP echo or echo-reply messages, so all we need to do is strip off the ethernet header
@@ -753,6 +729,7 @@ void pcap_packet_handler(u_char *refcon, const struct pcap_pkthdr *hdr, const u_
}
q->elems++;
}
+#endif
uint16_t calc_icmp_checksum(uint16_t *data, int bytes) {
uint32_t sum;
diff --git a/src/ptunnel.h b/src/ptunnel.h
index c5a9e9b..f2b514d 100644
--- a/src/ptunnel.h
+++ b/src/ptunnel.h
@@ -74,6 +74,14 @@
#include "pdesc.h"
#include "challenge.h"
+#ifdef WIN32
+/* pthread porting to windows */
+typedef CRITICAL_SECTION pthread_mutex_t;
+typedef unsigned long pthread_t;
+#define pthread_mutex_init InitializeCriticalSectionAndSpinCount
+#define pthread_mutex_lock EnterCriticalSection
+#define pthread_mutex_unlock LeaveCriticalSection
+#endif
extern pthread_mutex_t chain_lock;
extern uint32_t num_tunnels;
extern const int icmp_receive_buf_len;
@@ -129,8 +137,10 @@ typedef struct {
/* function Prototypes */
void* pt_proxy(void *args);
+#ifdef HAVE_PCAP
void pcap_packet_handler(u_char *refcon, const struct pcap_pkthdr *hdr,
const u_char* pkt);
+#endif
void pt_forwarder(void);