Skip to content

Commit

Permalink
Merge pull request #55 from jelu/ip_version
Browse files Browse the repository at this point in the history
Ip version
  • Loading branch information
jelu authored Jun 8, 2017
2 parents da2cf9c + 3943dda commit 7d09dd9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 30 deletions.
1 change: 1 addition & 0 deletions FIELDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ the dns table, presented as JSON identifiers.
{ "name": "dst_addr","type": "text" },
{ "name": "protocol","type": "int" },
{ "name": "ip_ttl","type": "int" },
{ "name": "ip_version","type": "int" },
{ "name": "fragments","type": "int" },
{ "name": "qname","type": "text" },
{ "name": "aname","type": "text" },
Expand Down
9 changes: 8 additions & 1 deletion src/packet_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ void IP_header::reset()
dst_port = 0;
proto = 0;
ip_ttl = 0;
ip_version = 0;
id = 0;
length = 0;
}
Expand All @@ -204,7 +205,7 @@ int IP_header::decode(unsigned char* data, int itype, int i_id)
// ether frame done (ignored mac's)
// ip

int ip_version = data[0] >> 4;
ip_version = data[0] >> 4;
proto = 0;
if (ip_version == 4) {
if (ethertype == 0)
Expand Down Expand Up @@ -429,6 +430,7 @@ void IP_header_to_table::add_packet_columns(Packet_handler& packet_handler)
packet_handler.add_packet_column("dst_addr", "", Coltype::_text, COLUMN_DST_ADDR);
packet_handler.add_packet_column("protocol", "", Coltype::_int, COLUMN_PROTOCOL);
packet_handler.add_packet_column("ip_ttl", "", Coltype::_int, COLUMN_IP_TTL);
packet_handler.add_packet_column("ip_version", "", Coltype::_int, COLUMN_IP_VERSION);
packet_handler.add_packet_column("fragments", "", Coltype::_int, COLUMN_FRAGMENTS);
}

Expand All @@ -439,6 +441,7 @@ void IP_header_to_table::on_table_created(Table* table, const std::vector<int>&
acc_ether_type = table->get_accessor<int_column>("ether_type");
acc_protocol = table->get_accessor<int_column>("protocol");
acc_ip_ttl = table->get_accessor<int_column>("ip_ttl");
acc_ip_version = table->get_accessor<int_column>("ip_version");
acc_src_port = table->get_accessor<int_column>("src_port");
acc_dst_port = table->get_accessor<int_column>("dst_port");
acc_s = table->get_accessor<int_column>("s");
Expand Down Expand Up @@ -478,6 +481,10 @@ void IP_header_to_table::assign(Row* row, IP_header* head, const std::vector<int
acc_ip_ttl.value(row) = head->ip_ttl;
break;

case COLUMN_IP_VERSION:
acc_ip_version.value(row) = head->ip_version;
break;

case COLUMN_SRC_PORT:
acc_src_port.value(row) = head->src_port;
break;
Expand Down
4 changes: 4 additions & 0 deletions src/packet_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class IP_header {
, dst_port(0)
, proto(0)
, ip_ttl(0)
, ip_version(0)
, id(0)
, length(0)
, fragments(0)
Expand All @@ -110,6 +111,7 @@ class IP_header {
unsigned short dst_port;
unsigned short proto;
unsigned short ip_ttl;
unsigned short ip_version;
unsigned int id;
unsigned int length;
unsigned int fragments;
Expand All @@ -128,6 +130,7 @@ class IP_header_to_table {
COLUMN_ETHER_TYPE,
COLUMN_PROTOCOL,
COLUMN_IP_TTL,
COLUMN_IP_VERSION,
COLUMN_SRC_PORT,
COLUMN_DST_PORT,
COLUMN_SRC_ADDR,
Expand All @@ -146,6 +149,7 @@ class IP_header_to_table {
Int_accessor acc_ether_type;
Int_accessor acc_protocol;
Int_accessor acc_ip_ttl;
Int_accessor acc_ip_version;
Int_accessor acc_src_port;
Int_accessor acc_dst_port;
Int_accessor acc_fragments;
Expand Down
1 change: 1 addition & 0 deletions src/test/test5.gold
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@
{ "name": "dst_addr","type": "text" },
{ "name": "protocol","type": "int" },
{ "name": "ip_ttl","type": "int" },
{ "name": "ip_version","type": "int" },
{ "name": "fragments","type": "int" },
{ "name": "type","type": "int" },
{ "name": "code","type": "int" },
Expand Down
59 changes: 30 additions & 29 deletions src/test/test7.gold
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{ "name": "dst_addr","type": "text" },
{ "name": "protocol","type": "int" },
{ "name": "ip_ttl","type": "int" },
{ "name": "ip_version","type": "int" },
{ "name": "fragments","type": "int" },
{ "name": "type","type": "int" },
{ "name": "code","type": "int" },
Expand All @@ -24,35 +25,35 @@
{ "name": "desc","type": "text" }
],
"data": [
[1,1297781718,401023,2048,0,0,"172.18.24.52","172.18.201.234",1,64,0,8,0,17563,0,0,"","","Echo Request"],
[2,1297781719,401120,2048,0,0,"172.18.24.52","172.18.201.234",1,64,0,8,0,17563,1,0,"","","Echo Request"],
[3,1297781720,401368,2048,0,0,"172.18.24.52","172.18.201.234",1,64,0,8,0,17563,2,0,"","","Echo Request"],
[4,1297781729,36800,2048,0,0,"172.18.24.52","172.18.24.1",1,64,0,8,0,17819,0,0,"","","Echo Request"],
[5,1297781729,37210,2048,0,0,"172.18.24.1","172.18.24.52",1,64,0,0,0,17819,0,0,"","","Echo Reply"],
[6,1297781730,37013,2048,0,0,"172.18.24.52","172.18.24.1",1,64,0,8,0,17819,1,0,"","","Echo Request"],
[7,1297781730,37634,2048,0,0,"172.18.24.1","172.18.24.52",1,64,0,0,0,17819,1,0,"","","Echo Reply"],
[8,1297781731,37342,2048,0,0,"172.18.24.52","172.18.24.1",1,64,0,8,0,17819,2,0,"","","Echo Request"],
[9,1297781731,37864,2048,0,0,"172.18.24.1","172.18.24.52",1,64,0,0,0,17819,2,0,"","","Echo Reply"],
[10,1297781733,388527,2048,0,0,"172.18.24.52","172.18.24.12",1,64,0,8,0,18075,0,0,"","","Echo Request"],
[11,1297781733,389073,2048,0,0,"172.18.24.12","172.18.24.52",1,128,0,0,0,18075,0,0,"","","Echo Reply"],
[12,1297781734,388627,2048,0,0,"172.18.24.52","172.18.24.12",1,64,0,8,0,18075,1,0,"","","Echo Request"],
[13,1297781734,388912,2048,0,0,"172.18.24.12","172.18.24.52",1,128,0,0,0,18075,1,0,"","","Echo Reply"],
[14,1297781735,388779,2048,0,0,"172.18.24.52","172.18.24.12",1,64,0,8,0,18075,2,0,"","","Echo Request"],
[15,1297781735,389060,2048,0,0,"172.18.24.12","172.18.24.52",1,128,0,0,0,18075,2,0,"","","Echo Reply"],
[16,1297781739,517764,2048,0,0,"172.18.24.52","172.18.23.12",1,64,0,8,0,18331,0,0,"","","Echo Request"],
[17,1297781740,518089,2048,0,0,"172.18.24.52","172.18.23.12",1,64,0,8,0,18331,1,0,"","","Echo Request"],
[18,1297781741,518404,2048,0,0,"172.18.24.52","172.18.23.12",1,64,0,8,0,18331,2,0,"","","Echo Request"],
[19,1297781745,4951,2048,0,0,"172.18.24.52","173.18.23.12",1,64,0,8,0,19355,0,0,"","","Echo Request"],
[20,1297781746,5090,2048,0,0,"172.18.24.52","173.18.23.12",1,64,0,8,0,19355,1,0,"","","Echo Request"],
[21,1297781747,5403,2048,0,0,"172.18.24.52","173.18.23.12",1,64,0,8,0,19355,2,0,"","","Echo Request"],
[22,1297781749,725341,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,0,0,"","","Echo Request"],
[23,1297781750,725507,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,1,0,"","","Echo Request"],
[24,1297781750,900759,2048,0,0,"75.160.241.10","172.18.24.52",1,234,0,3,1,0,0,1,"172.18.24.52","174.18.23.12","Destination host unreachable"],
[25,1297781751,725837,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,2,0,"","","Echo Request"],
[26,1297781752,726162,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,3,0,"","","Echo Request"],
[27,1297781753,726487,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,4,0,"","","Echo Request"],
[28,1297781754,726804,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,5,0,"","","Echo Request"],
[29,1297781754,903407,2048,0,0,"75.160.241.10","172.18.24.52",1,234,0,3,1,0,0,1,"172.18.24.52","174.18.23.12","Destination host unreachable"]
[1,1297781718,401023,2048,0,0,"172.18.24.52","172.18.201.234",1,64,4,0,8,0,17563,0,0,"","","Echo Request"],
[2,1297781719,401120,2048,0,0,"172.18.24.52","172.18.201.234",1,64,4,0,8,0,17563,1,0,"","","Echo Request"],
[3,1297781720,401368,2048,0,0,"172.18.24.52","172.18.201.234",1,64,4,0,8,0,17563,2,0,"","","Echo Request"],
[4,1297781729,36800,2048,0,0,"172.18.24.52","172.18.24.1",1,64,4,0,8,0,17819,0,0,"","","Echo Request"],
[5,1297781729,37210,2048,0,0,"172.18.24.1","172.18.24.52",1,64,4,0,0,0,17819,0,0,"","","Echo Reply"],
[6,1297781730,37013,2048,0,0,"172.18.24.52","172.18.24.1",1,64,4,0,8,0,17819,1,0,"","","Echo Request"],
[7,1297781730,37634,2048,0,0,"172.18.24.1","172.18.24.52",1,64,4,0,0,0,17819,1,0,"","","Echo Reply"],
[8,1297781731,37342,2048,0,0,"172.18.24.52","172.18.24.1",1,64,4,0,8,0,17819,2,0,"","","Echo Request"],
[9,1297781731,37864,2048,0,0,"172.18.24.1","172.18.24.52",1,64,4,0,0,0,17819,2,0,"","","Echo Reply"],
[10,1297781733,388527,2048,0,0,"172.18.24.52","172.18.24.12",1,64,4,0,8,0,18075,0,0,"","","Echo Request"],
[11,1297781733,389073,2048,0,0,"172.18.24.12","172.18.24.52",1,128,4,0,0,0,18075,0,0,"","","Echo Reply"],
[12,1297781734,388627,2048,0,0,"172.18.24.52","172.18.24.12",1,64,4,0,8,0,18075,1,0,"","","Echo Request"],
[13,1297781734,388912,2048,0,0,"172.18.24.12","172.18.24.52",1,128,4,0,0,0,18075,1,0,"","","Echo Reply"],
[14,1297781735,388779,2048,0,0,"172.18.24.52","172.18.24.12",1,64,4,0,8,0,18075,2,0,"","","Echo Request"],
[15,1297781735,389060,2048,0,0,"172.18.24.12","172.18.24.52",1,128,4,0,0,0,18075,2,0,"","","Echo Reply"],
[16,1297781739,517764,2048,0,0,"172.18.24.52","172.18.23.12",1,64,4,0,8,0,18331,0,0,"","","Echo Request"],
[17,1297781740,518089,2048,0,0,"172.18.24.52","172.18.23.12",1,64,4,0,8,0,18331,1,0,"","","Echo Request"],
[18,1297781741,518404,2048,0,0,"172.18.24.52","172.18.23.12",1,64,4,0,8,0,18331,2,0,"","","Echo Request"],
[19,1297781745,4951,2048,0,0,"172.18.24.52","173.18.23.12",1,64,4,0,8,0,19355,0,0,"","","Echo Request"],
[20,1297781746,5090,2048,0,0,"172.18.24.52","173.18.23.12",1,64,4,0,8,0,19355,1,0,"","","Echo Request"],
[21,1297781747,5403,2048,0,0,"172.18.24.52","173.18.23.12",1,64,4,0,8,0,19355,2,0,"","","Echo Request"],
[22,1297781749,725341,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,0,0,"","","Echo Request"],
[23,1297781750,725507,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,1,0,"","","Echo Request"],
[24,1297781750,900759,2048,0,0,"75.160.241.10","172.18.24.52",1,234,4,0,3,1,0,0,1,"172.18.24.52","174.18.23.12","Destination host unreachable"],
[25,1297781751,725837,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,2,0,"","","Echo Request"],
[26,1297781752,726162,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,3,0,"","","Echo Request"],
[27,1297781753,726487,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,4,0,"","","Echo Request"],
[28,1297781754,726804,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,5,0,"","","Echo Request"],
[29,1297781754,903407,2048,0,0,"75.160.241.10","172.18.24.52",1,234,4,0,3,1,0,0,1,"172.18.24.52","174.18.23.12","Destination host unreachable"]
]
}
]
Expand Down

0 comments on commit 7d09dd9

Please sign in to comment.