From 43de60daf0793063cca3a50c8df17eaec56f4d7a Mon Sep 17 00:00:00 2001 From: smlng <s@mlng.net> Date: Tue, 7 Feb 2017 13:41:32 +0100 Subject: [PATCH] net: add tcp_hdr_print --- Makefile.dep | 1 + sys/Makefile | 3 ++ sys/include/net/tcp.h | 7 +++++ sys/net/transport_layer/tcp/Makefile | 1 + sys/net/transport_layer/tcp/tcp_hdr_print.c | 33 +++++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 sys/net/transport_layer/tcp/Makefile create mode 100644 sys/net/transport_layer/tcp/tcp_hdr_print.c diff --git a/Makefile.dep b/Makefile.dep index e8732e8e13..0590f99581 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -341,6 +341,7 @@ endif ifneq (,$(filter gnrc_tcp,$(USEMODULE))) USEMODULE += inet_csum USEMODULE += random + USEMODULE += tcp USEMODULE += xtimer endif diff --git a/sys/Makefile b/sys/Makefile index 75102da229..5405e7b5f0 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -79,6 +79,9 @@ endif ifneq (,$(filter udp,$(USEMODULE))) DIRS += net/transport_layer/udp endif +ifneq (,$(filter tcp,$(USEMODULE))) + DIRS += net/transport_layer/tcp +endif ifneq (,$(filter hamming256,$(USEMODULE))) DIRS += ecc/hamming256 diff --git a/sys/include/net/tcp.h b/sys/include/net/tcp.h index 64d7739cdd..e42bb06ce5 100644 --- a/sys/include/net/tcp.h +++ b/sys/include/net/tcp.h @@ -75,6 +75,13 @@ typedef struct __attribute__((packed)) { uint8_t value[]; /**< Pointer to TCP options Value field */ } tcp_hdr_opt_t; +/** + * @brief Print the given TCP header to STDOUT + * + * @param[in] hdr TCP header to print + */ +void tcp_hdr_print(tcp_hdr_t *hdr); + #ifdef __cplusplus } #endif diff --git a/sys/net/transport_layer/tcp/Makefile b/sys/net/transport_layer/tcp/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/sys/net/transport_layer/tcp/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/net/transport_layer/tcp/tcp_hdr_print.c b/sys/net/transport_layer/tcp/tcp_hdr_print.c new file mode 100644 index 0000000000..b7dfcb50d2 --- /dev/null +++ b/sys/net/transport_layer/tcp/tcp_hdr_print.c @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2017 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * + * @author smlng <s@mlng.net> + */ + +#include <stdio.h> +#include <inttypes.h> + +#include "net/tcp.h" + +void tcp_hdr_print(tcp_hdr_t *hdr) +{ + printf(" src-port: %5" PRIu16 " dst-port: %5" PRIu16 "\n", + byteorder_ntohs(hdr->src_port), byteorder_ntohs(hdr->dst_port)); + printf(" seq-num: %10" PRIu32 " ack-num: %10" PRIu32 "\n", + byteorder_ntohl(hdr->seq_num), byteorder_ntohl(hdr->ack_num)); + printf(" off_ctl: %5" PRIu16 " window: %5" PRIu16 "\n", + byteorder_ntohs(hdr->off_ctl), byteorder_ntohs(hdr->window)); + printf(" cksum: 0x%04" PRIx16 " urgent_ptr: %5" PRIu16 "\n", + byteorder_ntohs(hdr->checksum), byteorder_ntohs(hdr->urgent_ptr)); +} +/** @} */ -- GitLab