Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed reading of big-endian pcap files (including gzipped pcap) #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added pcap/sample-bigendian.pcap.gz
Binary file not shown.
1 change: 1 addition & 0 deletions src/pcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bool Pcap_file::get_header()
if (res!=0xa1b2c3d4)
{
m_reverse_order = true;
rewind();
res = get_int32();
if (res!=0xa1b2c3d4)
{
Expand Down
5 changes: 5 additions & 0 deletions src/pcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ class Pcap_file
m_zip.inflate(m_filebuffer,m_zipbuffer);
}
}
void rewind()
{
m_filebuffer.m_buffer_pos = 0;
m_zipbuffer.m_buffer_pos = 0;
}
void set_gzipped()
{
m_gzipped=true;
Expand Down
14 changes: 7 additions & 7 deletions src/sql.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Column *Table::add_column(const char *name, const char *type, int id, bool hidde
return add_column(name,Coltype::_text, id, hidden);
else if (strcmp(type,"bool") == 0)
return add_column(name,Coltype::_bool, id, hidden);
else if (strcmp(type,"int") == 0)
else if (strcmp(type,"int64") == 0)
return add_column(name,Coltype::_int, id, hidden);
else if (strcmp(type,"float") == 0)
return add_column(name,Coltype::_float, id, hidden);
Expand Down Expand Up @@ -684,7 +684,7 @@ void Table::xml()
t="float";
break;
case(Coltype::_int):
t="int";
t="int64";
break;
case(Coltype::_text):
t="text";
Expand Down Expand Up @@ -725,7 +725,7 @@ void Table::xml()
g_output.add_string(r->access_column<bool_column>(offset) ? "1" : "0");
break;
case Coltype::_int:
snprintf(buf, bufsize, "%i", r->access_column<int_column>(offset));
snprintf(buf, bufsize, "%lu", r->access_column<int_column>(offset));
g_output.add_string(buf);
break;
case Coltype::_float:
Expand Down Expand Up @@ -792,7 +792,7 @@ void Table::json(bool trailing_comma)
t="float";
break;
case(Coltype::_int):
t="int";
t="int64";
break;
case(Coltype::_text):
t="text";
Expand Down Expand Up @@ -840,7 +840,7 @@ void Table::json(bool trailing_comma)
g_output.add_string(r->access_column<bool_column>(offset) ? "1" : "0");
break;
case Coltype::_int:
snprintf(buf, bufsize, "%i", r->access_column<int_column>(offset));
snprintf(buf, bufsize, "%lu", r->access_column<int_column>(offset));
g_output.add_string(buf);
break;
case Coltype::_float:
Expand Down Expand Up @@ -915,7 +915,7 @@ void Table::csv(bool format)
len = 1;
break;
case Coltype::_int:
snprintf(buf, bufsize, "%i", r->access_column<int_column>(offset));
snprintf(buf, bufsize, "%lu", r->access_column<int_column>(offset));
len = strlen(buf);
break;
case Coltype::_float:
Expand Down Expand Up @@ -988,7 +988,7 @@ void Table::csv(bool format)
out = r->access_column<bool_column>(offset) ? "1" : "0";
break;
case Coltype::_int:
snprintf(buf, bufsize, "%i", r->access_column<int_column>(offset));
snprintf(buf, bufsize, "%lu", r->access_column<int_column>(offset));
out = buf;
break;
case Coltype::_float:
Expand Down
6 changes: 3 additions & 3 deletions src/sql.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -753,13 +753,13 @@ class Static_int : public OP
public:
Static_int(const OP &op): OP(op)
{
m_val = atoi(get_token());
m_val = atol(get_token());
}
void evaluate(Row **rows, Variant &v)
{
v = m_val;
}
int m_val;
uint64_t m_val;
};

class Static_float : public OP
Expand Down Expand Up @@ -936,7 +936,7 @@ class Len_func : public OP
Variant str;
m_param[0]->evaluate(rows, str);
RefCountStringHandle t(str.get_text());
v = int(strlen((*t)->data));
v = uint64_t(strlen((*t)->data));
}
};

Expand Down
9 changes: 5 additions & 4 deletions src/variant.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef VARIANT_H
#define VARIANT_H

#include <inttypes.h>
#include <cstdlib>

#include "refcountstring.h"
Expand Down Expand Up @@ -32,7 +33,7 @@ namespace se
static const int bool_size = sizeof(bool_column);
static const int bool_align = sizeof(bool_column);

typedef int int_column;
typedef uint64_t int_column;
static const int int_size = sizeof(int_column);
static const int int_align = sizeof(int_column);

Expand All @@ -52,7 +53,7 @@ namespace se
return std::atoi(v->data);
}

inline int_column convert_column_to_int(float_column v) { return int(v); }
inline int_column convert_column_to_int(float_column v) { return uint64_t(v); }
inline int_column convert_column_to_int(int_column v) { return v; }
inline int_column convert_column_to_int(bool_column v) { return v; }
inline int_column convert_column_to_int(text_column v)
Expand All @@ -79,7 +80,7 @@ namespace se
{
const int bufsize = (sizeof(int_column) * 8 + 1) / 3 + 1;
RefCountString *str = RefCountString::allocate(bufsize);
snprintf(str->data, bufsize, "%d", v);
snprintf(str->data, bufsize, "%lu", v);
return str;
}
inline text_column convert_column_to_text(bool_column v)
Expand Down Expand Up @@ -268,7 +269,7 @@ namespace se
switch(m_type)
{
case(Coltype::_bool): return std::hash<bool>()(m_val.m_bool);
case(Coltype::_int): return std::hash<int>()(m_val.m_int);
case(Coltype::_int): return std::hash<uint64_t>()(m_val.m_int);
case(Coltype::_float): return std::hash<float>()(m_val.m_float);
case(Coltype::_text): return hash_bytes(m_val.m_text->data, strlen(m_val.m_text->data));
}
Expand Down