<commit_before>#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "protocol.h"
#include "netconfig.h"
#include "util.h"

#define header_size 13

const char* rdp_flag_names[] = {
    "NO-TYPE",    "ACK",             "SYN",         "ACK/SYN",
    "FIN",        "ACK/FIN",         "SYN/FIN",     "ACK/SYN/FIN",
    "RST",        "ACK/RST",         "SYN/RST",     "ACK/SYN/RST",
    "FIN/RST",    "ACK/FIN/RST",     "SYN/FIN/RST", "SYN/ACK/FIN/RST",
    "DAT",        "ACK/DAT",         "SYN/DAT",     "ACK/SYN/DAT",
    "FIN/DAT",    "ACK/FIN/DAT",     "SYN/FIN/DAT", "ACK/SYN/FIN/DAT",
    "RST/DAT",    "ACK/RST/DAT",     "SYN/RST/DAT", "ACK/SYN/RST/DAT",
    "FIN/RST/DAT","ACK/FIN/RST/DAT", "SYN/FIN/RST", "SYN/ACK/FIN/RST/DAT"
};

unint16_t  flags;
unint16_t  seq_number;
unint16_t  ack_number;
unint16_t  window_size;
unint16_t  payload_size;
char* payload;

unint16_t rdp_packaged_size(const unint16_t  payload_size) {
    return payload_size + header_size;
}

void rdp_package(
    char* buffer,
    const unint16_t  flags,
    const unint16_t  seq_number,
    const unint16_t  ack_number,
    const unint16_t  size,
    const char* payload
) {
    // Get total packet size
    unint16_t  length = rdp_packaged_size(payload_size);
    char* _magic_ = "CSC361";
    // Zero the buffer
    rdp_zero(buffer, size + 1);
    // Serialize
    memcpy(buffer + 0, _magic_,      6);
    memcpy(buffer + 6,  &flags,      1);
    memcpy(buffer + 7,  &seq_number, 2);
    memcpy(buffer + 9,  &ack_number, 2);
    memcpy(buffer + 11, size,        2);
    if(flags & rdp_DAT) {
        memcpy(buffer + header_size, payload, length);
    }
}

int rdp_parse(char* buffer) {

    char _magic_[7];
    rdp_zero(_magic_, 7);
    flags        = 0;
    seq_number   = 0;
    ack_number   = 0;
    window_size  = 0;
    payload_size = 0;

    // Deserialize
    memcpy(_magic_,       buffer + 0,  6);
    memcpy(&flags,        buffer + 6,  1);
    memcpy(&seq_number,   buffer + 7,  2);<commit_msg>autogenerated commit<commit_after>#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "protocol.h"
#include "netconfig.h"
#include "util.h"

#define header_size 13

const char* rdp_flag_names[] = {
    "NO-TYPE",    "ACK",             "SYN",         "ACK/SYN",
    "FIN",        "ACK/FIN",         "SYN/FIN",     "ACK/SYN/FIN",
    "RST",        "ACK/RST",         "SYN/RST",     "ACK/SYN/RST",
    "FIN/RST",    "ACK/FIN/RST",     "SYN/FIN/RST", "SYN/ACK/FIN/RST",
    "DAT",        "ACK/DAT",         "SYN/DAT",     "ACK/SYN/DAT",
    "FIN/DAT",    "ACK/FIN/DAT",     "SYN/FIN/DAT", "ACK/SYN/FIN/DAT",
    "RST/DAT",    "ACK/RST/DAT",     "SYN/RST/DAT", "ACK/SYN/RST/DAT",
    "FIN/RST/DAT","ACK/FIN/RST/DAT", "SYN/FIN/RST", "SYN/ACK/FIN/RST/DAT"
};

unint16_t  flags;
unint16_t  seq_number;
unint16_t  ack_number;
unint16_t  window_size;
unint16_t  payload_size;
char* payload;

unint16_t rdp_packaged_size(const unint16_t  payload_size) {
    return payload_size + header_size;
}

void rdp_package(
    char* buffer,
    const unint16_t  flags,
    const unint16_t  seq_number,
    const unint16_t  ack_number,
    const unint16_t  size,
    const char* payload
) {
    // Get total packet size
    unint16_t  length = rdp_packaged_size(payload_size);
    char* _magic_ = "CSC361";
    // Zero the buffer
    rdp_zero(buffer, size + 1);
    // Serialize
    memcpy(buffer + 0, _magic_,      6);
    memcpy(buffer + 6,  &flags,      1);
    memcpy(buffer + 7,  &seq_number, 2);
    memcpy(buffer + 9,  &ack_number, 2);
    memcpy(buffer + 11, &size,       2);
    if(flags & rdp_DAT) {
        memcpy(buffer + header_size, payload, length);
    }
}

int rdp_parse(char* buffer) {

    char _magic_[7];
    rdp_zero(_magic_, 7);
    flags        = 0;
    seq_number   = 0;
    ack_number   = 0;
    window_size  = 0;
    payload_size = 0;

    // Deserialize
    memcpy(_magic_,       buffer + 0,  6);
    memcpy(&flags,        buffer + 6,  1);
    memcpy(&seq_number,   buffer + 7,  2);
{'fraction_non_alphanumeric': 0.155133649762678, 'fraction_numerical': 0.02697976517611791, 'mean_word_length': 2.39034716342083, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '55781', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1602, 'n_words': 320}