<commit_before>
#include "bro-config.h"

#include "Napatech.h"
#include <nt.h>

using namespace iosource::pktsrc;

NapatechSource::~NapatechSource()
{
	Close();
}

NapatechSource::NapatechSource(const std::string& path, bool is_live, const std::string& arg_kind)
{
	if ( ! is_live )
		Error("napatech source does not support offline input");

	kind = arg_kind;
	current_filter = -1;

	stream_id = atoi(path.c_str());

	props.path = path;
	props.is_live = is_live;

        status = NT_Init(NTAPI_VERSION);
        if ( status != NT_SUCCESS ) {
                NT_ExplainError(status, errorBuffer, sizeof(errorBuffer));
                Error(errorBuffer);
                return;
        }
}

static inline struct timeval nt_timestamp_to_timeval(const int64_t ts_nanosec)
{
    struct timeval tv;
    long tv_nsec;

    if (ts_nanosec == 0) {
        return (struct timeval) { 0, 0 };
    } else {
        tv.tv_sec = ts_nanosec / _NSEC_PER_SEC;
        tv_nsec = (ts_nanosec % _NSEC_PER_SEC);
        tv.tv_usec = tv_nsec / 1000;
    }

    return tv;
}

void NapatechSource::Open()
{
	// Last argument is the HBA - Host Buffer Allowance, or the amount of the Host Buffer that
	// can be held back. Need to createa  BIF to configure this.
	status = NT_NetRxOpen(&rx_stream, "BroStream", NT_NET_INTERFACE_PACKET, stream_id, 50);
	if ( status != NT_SUCCESS) {
		Info("Failed to open stream");
		NT_ExplainError(status, errorBuffer, sizeof(errorBuffer));
		Error(errorBuffer);
		return;
	}

	props.netmask = NETMASK_UNKNOWN;
	props.is_live = true;
	props.link_type = DLT_EN10MB;

	// Open a statistics stream
	// Napatech NICs track what gets collected from a stream and what does not.
	// Because of this, we can move lots of the stats tracking out of the plugin.
	status = NT_StatOpen(&stat_stream, "BroStats");<commit_msg>Modified HBA to be 100. Seeing really weird reporting when HBA is set <100.<commit_after>
#include "bro-config.h"

#include "Napatech.h"
#include <nt.h>

using namespace iosource::pktsrc;

NapatechSource::~NapatechSource()
{
	Close();
}

NapatechSource::NapatechSource(const std::string& path, bool is_live, const std::string& arg_kind)
{
	if ( ! is_live )
		Error("napatech source does not support offline input");

	kind = arg_kind;
	current_filter = -1;

	stream_id = atoi(path.c_str());

	props.path = path;
	props.is_live = is_live;

        status = NT_Init(NTAPI_VERSION);
        if ( status != NT_SUCCESS ) {
                NT_ExplainError(status, errorBuffer, sizeof(errorBuffer));
                Error(errorBuffer);
                return;
        }
}

static inline struct timeval nt_timestamp_to_timeval(const int64_t ts_nanosec)
{
    struct timeval tv;
    long tv_nsec;

    if (ts_nanosec == 0) {
        return (struct timeval) { 0, 0 };
    } else {
        tv.tv_sec = ts_nanosec / _NSEC_PER_SEC;
        tv_nsec = (ts_nanosec % _NSEC_PER_SEC);
        tv.tv_usec = tv_nsec / 1000;
    }

    return tv;
}

void NapatechSource::Open()
{
	// Last argument is the HBA - Host Buffer Allowance, or the amount of the Host Buffer that
	// can be held back. Need to createa  BIF to configure this.
	status = NT_NetRxOpen(&rx_stream, "BroStream", NT_NET_INTERFACE_PACKET, stream_id, 100);
	if ( status != NT_SUCCESS) {
		Info("Failed to open stream");
		NT_ExplainError(status, errorBuffer, sizeof(errorBuffer));
		Error(errorBuffer);
		return;
	}

	props.netmask = NETMASK_UNKNOWN;
	props.is_live = true;
	props.link_type = DLT_EN10MB;

	// Open a statistics stream
	// Napatech NICs track what gets collected from a stream and what does not.
	// Because of this, we can move lots of the stats tracking out of the plugin.
	status = NT_StatOpen(&stat_stream, "BroStats");
{'fraction_non_alphanumeric': 0.10655516590234691, 'fraction_numerical': 0.009441596978688967, 'mean_word_length': 3.34192037470726, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '4069543', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1277, 'n_words': 350}