Show udp hdr too in debug mode

This commit is contained in:
angt
2015-12-12 13:18:56 +01:00
parent 7cc6d08d7a
commit 05de7b8109

View File

@@ -12,6 +12,8 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <arpa/inet.h>
#include <netdb.h>
@@ -509,9 +511,10 @@ static void gt_print_hdr (uint8_t *data, size_t ip_size, const char *sockname)
gt_log("%s: version=%i size=%zi proto=%zi src=%s dst=%s\n", sockname, ip_version, ip_size, ip_proto, ip_src, ip_dst);
if (ip_hdr_size<=0 || ip_proto!=6)
if (ip_hdr_size<=0)
return;
if (ip_proto==SOL_TCP) {
struct tcphdr tcp;
byte_cpy(&tcp, &data[ip_hdr_size], sizeof(tcp));
@@ -522,7 +525,7 @@ static void gt_print_hdr (uint8_t *data, size_t ip_size, const char *sockname)
tcp.th_ack = ntohl(tcp.th_ack);
tcp.th_win = ntohs(tcp.th_win);
gt_log("%s: tcp src=%i dst=%i seq=%u ack=%u win=%u %c%c%c%c%c%c\n",
gt_log("%s: tcp src=%u dst=%u seq=%u ack=%u win=%u %c%c%c%c%c%c\n",
sockname, tcp.th_sport, tcp.th_dport, tcp.th_seq, tcp.th_ack, tcp.th_win,
(tcp.th_flags&TH_FIN) ?'F':'.',
(tcp.th_flags&TH_SYN) ?'S':'.',
@@ -532,6 +535,20 @@ static void gt_print_hdr (uint8_t *data, size_t ip_size, const char *sockname)
(tcp.th_flags&TH_URG) ?'U':'.');
}
if (ip_proto==SOL_UDP) {
struct udphdr udp;
byte_cpy(&udp, &data[ip_hdr_size], sizeof(udp));
udp.uh_sport = ntohs(udp.uh_sport);
udp.uh_dport = ntohs(udp.uh_dport);
udp.uh_ulen = ntohs(udp.uh_ulen);
gt_log("%s: udp src=%u dst=%u len=%u\n",
sockname, udp.uh_sport, udp.uh_dport, udp.uh_ulen);
}
}
static int gt_setup_secretkey (struct crypto_ctx *ctx, char *keyfile)
{
const size_t size = sizeof(ctx->skey);
@@ -939,7 +956,6 @@ int main (int argc, char **argv)
if _0_(debug)
gt_print_hdr(data, ip_size, sockname);
blks[blk_write++].size = r;
blk_count++;
}