aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2020-05-27 20:01:45 +0200
committerToni Uhlig <matzeton@googlemail.com>2020-05-27 20:01:45 +0200
commitd2e92ee748f3b3e826ffcbf665adc45637ad9045 (patch)
tree994a7b54dc9cbbad364036f25412ba4c5dc519fc
parented456a32ffe6fea0cb52b5184a00a14cb0059f4a (diff)
re-enabled and improved logging of packet headers and payload
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--src/pkt.c11
-rw-r--r--src/utils.c30
-rw-r--r--src/utils.h5
3 files changed, 31 insertions, 15 deletions
diff --git a/src/pkt.c b/src/pkt.c
index 773414c..cae71de 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -219,7 +219,8 @@ void handle_packet(char * buf, unsigned bytes, int is_pcap, struct sockaddr_in *
icmp_echo_packet_t * pkt;
ping_tunnel_pkt_t * pt_pkt;
proxy_desc_t * cur;
- enum pkt_flag type_flag, pkt_flag, proxy_flag;
+ int pkt_flag;
+ enum pkt_flag type_flag, proxy_flag;
challenge_t * challenge;
proxy_flag = kProxy_flag;
@@ -271,7 +272,7 @@ void handle_packet(char * buf, unsigned bytes, int is_pcap, struct sockaddr_in *
type_flag = kProxy_flag;
}
- pkt_flag = pt_pkt->state & kFlag_mask;
+ pkt_flag = (int)pt_pkt->state & kFlag_mask;
pt_pkt->state &= ~kFlag_mask;
if (pt_pkt->state > (kNum_proto_types - 1)) {
pt_log(kLog_error, "Dropping packet with invalid state.\n");
@@ -294,6 +295,12 @@ void handle_packet(char * buf, unsigned bytes, int is_pcap, struct sockaddr_in *
pkt->type,
(pkt_flag == kUser_flag ? "yes" : "no"),
is_pcap);
+ log_sendrecv_hexstr("RECV ICMP", pkt, sizeof(*pkt));
+ log_sendrecv_hexstr("RECV PTNG", pt_pkt, sizeof(*pt_pkt));
+ if (bytes > sizeof(icmp_echo_packet_t) + sizeof(ping_tunnel_pkt_t)) {
+ log_sendrecv_hexstr("RECV PAYL", buf + sizeof(icmp_echo_packet_t) + sizeof(ping_tunnel_pkt_t),
+ bytes - sizeof(icmp_echo_packet_t) - sizeof(ping_tunnel_pkt_t));
+ }
/* This test essentially verifies that the packet comes from someone who isn't us. */
if ((pkt_flag == kUser_flag && type_flag == proxy_flag) || (pkt_flag == proxy_flag && type_flag == kUser_flag)) {
diff --git a/src/utils.c b/src/utils.c
index cba85fe..7426ce1 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -132,25 +132,35 @@ int host_to_addr(const char * hostname, uint32_t * result)
return 0;
}
-#if 0
static const char hextab[] = "0123456789ABCDEF";
-void print_hexstr(unsigned char *buf, size_t siz) {
- char *out = (char *) calloc(3, siz+1);
- unsigned char high, low;
+void log_sendrecv_hexstr(const char *prefix, void *buf, size_t siz) {
+ if (opts.log_level != kLog_sendrecv) {
+ return;
+ }
+
+ const size_t outsiz = siz * 3;
+
+ if (outsiz + 1 > BUFSIZ) {
+ pt_log(kLog_error, "Can not print hex string with size %zu: too big\n", siz);
+ return;
+ }
+
+ char out[outsiz + 1];
+ unsigned char high, low;
- for (size_t i = 0; i < siz; ++i) {
- high = (buf[i] & 0xF0) >> 4;
- low = buf[i] & 0x0F;
+ size_t i, j;
+ for (i = 0, j = 0; j < siz && i < outsiz; i += 3, ++j) {
+ high = (((unsigned char *)buf)[j] & 0xF0) >> 4;
+ low = ((unsigned char *)buf)[j] & 0x0F;
out[i ] = hextab[high];
out[i+1] = hextab[low];
out[i+2] = ' ';
}
+ out[i] = '\0';
- printf("%s\n", out);
- free(out);
+ pt_log(kLog_sendrecv, "%s[HEX]: %s\n", prefix, out);
}
-#endif
int pt_random(void)
{
diff --git a/src/utils.h b/src/utils.h
index acb5f71..b019454 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -46,6 +46,7 @@
#ifndef UTILS_H
#define UTILS_H 1
+#include <stdlib.h>
#include <stdint.h>
#include "pconfig.h"
@@ -58,9 +59,7 @@ double time_as_double(void);
int host_to_addr(const char * hostname, uint32_t * result);
-#if 0
-void print_hexstr(unsigned char *buf, size_t siz);
-#endif
+void log_sendrecv_hexstr(const char * prefix, void *buf, size_t siz);
int pt_random(void);