1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/include/net/tcp.h

92 lines
2.4 KiB
C
Raw Normal View History

2016-02-04 14:37:35 +01:00
/*
* Copyright (C) 2015-2017 Simon Brummer
2016-02-04 14:37:35 +01:00
*
* 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.
*/
/**
* @defgroup net_tcp TCP
* @ingroup net
* @brief Provides TCP header and helper functions
2016-02-04 14:37:35 +01:00
*
* @{
*
* @file
* @brief TCP header and helper functions
2016-02-04 14:37:35 +01:00
*
* @author Simon Brummer <simon.brummer@posteo.de>
2016-02-04 14:37:35 +01:00
*/
#ifndef NET_TCP_H
#define NET_TCP_H
2016-02-04 14:37:35 +01:00
#include "byteorder.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
2019-08-28 15:59:16 +02:00
* @brief TCP offset value boundaries.
2017-01-31 19:22:43 +01:00
* @{
*/
2021-05-08 08:55:42 +02:00
#define TCP_HDR_OFFSET_MIN (0x05) /**< Header offset minimum value */
#define TCP_HDR_OFFSET_MAX (0x0F) /**< Header offset maximum value */
2017-01-31 19:22:43 +01:00
/** @} */
/**
* @brief TCP Option "Kind"-field defines.
2017-01-31 19:22:43 +01:00
* @{
*/
#define TCP_OPTION_KIND_EOL (0x00) /**< "End of List"-Option */
2019-08-28 15:59:16 +02:00
#define TCP_OPTION_KIND_NOP (0x01) /**< "No Operation"-Option */
2017-01-31 19:22:43 +01:00
#define TCP_OPTION_KIND_MSS (0x02) /**< "Maximum Segment Size"-Option */
/** @} */
/**
* @brief TCP option "length"-field values.
2017-01-31 19:22:43 +01:00
* @{
2016-02-04 14:37:35 +01:00
*/
2021-05-08 08:55:42 +02:00
#define TCP_OPTION_LENGTH_MIN (2U) /**< Minimum option field size in bytes */
2017-01-31 19:22:43 +01:00
#define TCP_OPTION_LENGTH_MSS (0x04) /**< MSS Option Size always 4 */
/** @} */
2016-02-04 14:37:35 +01:00
/**
* @brief TCP header definition
*/
typedef struct __attribute__((packed)) {
network_uint16_t src_port; /**< Source port, in network byte order */
network_uint16_t dst_port; /**< Destination port, in network byte order */
2019-08-28 15:59:16 +02:00
network_uint32_t seq_num; /**< Sequence number, in network byte order */
2017-01-31 19:22:43 +01:00
network_uint32_t ack_num; /**< Acknowledgement number, in network byte order */
network_uint16_t off_ctl; /**< Data Offset and control Bits in network byte order */
network_uint16_t window; /**< Window, in network byte order */
network_uint16_t checksum; /**< Checksum, in network byte order */
network_uint16_t urgent_ptr; /**< Urgent pointer, in network byte order */
2016-02-04 14:37:35 +01:00
} tcp_hdr_t;
2017-01-31 19:22:43 +01:00
/**
* @brief TCP option field helper structure
2017-01-31 19:22:43 +01:00
*/
typedef struct __attribute__((packed)) {
uint8_t kind; /**< TCP options "Kind" field */
uint8_t length; /**< TCP options "Length" field */
uint8_t value[]; /**< TCP options "Value" field */
2017-01-31 19:22:43 +01:00
} tcp_hdr_opt_t;
2017-02-07 13:41:32 +01:00
/**
* @brief Print the given TCP header to STDOUT
*
* @param[in] hdr TCP header to print
2017-02-07 13:41:32 +01:00
*/
void tcp_hdr_print(tcp_hdr_t *hdr);
2016-02-04 14:37:35 +01:00
#ifdef __cplusplus
}
#endif
#endif /* NET_TCP_H */
2016-02-04 14:37:35 +01:00
/** @} */