<commit_before>#include "tcpr.h"

#include <netinet/in.h>
#include <netinet/tcp.h>

#define CLOSING_FLAGS (TCPR_HAVE_PEER_ACK | TCPR_HAVE_PEER_FIN \
			| TCPR_HAVE_ACK | TCPR_HAVE_FIN)

static uint32_t shorten(uint32_t n)
{
	return (n >> 16) + (n & 0xffff);
}

int tcpr_handle_segment_from_peer(struct tcpr_state *state, struct tcphdr *tcp,
					size_t size)
{
	uint32_t sum = tcp->th_sum ^ 0xffff;
	uint8_t *end = (uint8_t *)((uint32_t *)tcp + tcp->th_off);
	uint8_t *option = (uint8_t *)(tcp + 1);
	uint8_t *tmp;
	int flags = 0;

	while (option < end && *option != TCPOPT_EOL)
		switch (*option) {
		case TCPOPT_NOP:
			option++;
			break;
		case TCPOPT_MAXSEG:
			state->peer_mss = (uint16_t)option[2] << 8 | option[1];
			state->flags |= TCPR_HAVE_PEER_MSS;
			option += option[1];
			break;
		case TCPOPT_WINDOW:
			state->peer_ws = option[2];
			state->flags |= TCPR_HAVE_PEER_WS;
			option += option[1];
			break;
		case TCPOPT_TIMESTAMP:
			option += option[1];
			break;
		default:
			tcp->th_sum = 0;
			for (tmp = option + option[1]; option != tmp; option++)
				*option = TCPOPT_NOP;
			break;<commit_msg>Compute saved MSS correctly from option.<commit_after>#include "tcpr.h"

#include <netinet/in.h>
#include <netinet/tcp.h>

#define CLOSING_FLAGS (TCPR_HAVE_PEER_ACK | TCPR_HAVE_PEER_FIN \
			| TCPR_HAVE_ACK | TCPR_HAVE_FIN)

static uint32_t shorten(uint32_t n)
{
	return (n >> 16) + (n & 0xffff);
}

int tcpr_handle_segment_from_peer(struct tcpr_state *state, struct tcphdr *tcp,
					size_t size)
{
	uint32_t sum = tcp->th_sum ^ 0xffff;
	uint8_t *end = (uint8_t *)((uint32_t *)tcp + tcp->th_off);
	uint8_t *option = (uint8_t *)(tcp + 1);
	uint8_t *tmp;
	int flags = 0;

	while (option < end && *option != TCPOPT_EOL)
		switch (*option) {
		case TCPOPT_NOP:
			option++;
			break;
		case TCPOPT_MAXSEG:
			state->peer_mss = (uint16_t)option[3] << 8 | option[2];
			state->flags |= TCPR_HAVE_PEER_MSS;
			option += option[1];
			break;
		case TCPOPT_WINDOW:
			state->peer_ws = option[2];
			state->flags |= TCPR_HAVE_PEER_WS;
			option += option[1];
			break;
		case TCPOPT_TIMESTAMP:
			option += option[1];
			break;
		default:
			tcp->th_sum = 0;
			for (tmp = option + option[1]; option != tmp; option++)
				*option = TCPOPT_NOP;
			break;
{'fraction_non_alphanumeric': 0.14551083591331268, 'fraction_numerical': 0.026536930561698365, 'mean_word_length': 3.9067245119305856, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1380965', 'n_tokens_mistral': 1063, 'n_tokens_neox': 941, 'n_words': 202}