////////////////////////////////////////////////////////////////////// // IP traffic analyzer - data objects // Written by Jonathan A. Foster // Started April 23rd, 2021 // Copyright JF Possibilities, Inc. All rights reserved. ////////////////////////////////////////////////////////////////////// #include #include #include #include "data.h" ////////////////////////////////////////////////////////////////////// // Conn ////////////////////////////////////////////////////////////////////// void Conn::clear() { us = them = name = protocol = ""; in=false; us_port = them_port = 0; } void Conn::swap() { std::string s; int x; s = us; us = them; them =s; x = us_port; us_port = them_port; them_port = x; in=!in; } Conn &Conn::operator=(const Splits &sp) { int x; clear(); for(x=0; xgtr.us) return 1; } // TODO: auto-wildcard port based on in? if(us_port && gtr.us_port) { // 0 = no comparison wildcard if(us_portgtr.us_port) return 1; } if(them!="*" && gtr.them!="*") { if(themgtr.them) return 1; } if(them_port && gtr.them_port) { // 0 = no comparison wildcard if(them_portgtr.them_port) return 1; } // TODO: do we want to consider the name? if(name!="*" && gtr.name!="*") { if(namegtr.name) return 1; } if(protocolgtr.protocol) return 1; if(ingtr.in) return 1; return 0; } std::ostream &operator<<(std::ostream &out, const Conn &c) { out << c.us << ( c.in ? " <- " : " -> " ) << c.them << " " << c.protocol << "[" << ( c.in ? c.us_port : c.them_port ) << "] " << c.name; return out; } const Splits &operator>>(const Splits &tsv, Conn &conn) { if(tsv.count<7) throw std::runtime_error("Conn=TSV: too few columns"); conn.clear(); conn.us = tsv[0]; conn.us_port = atoi(tsv.fields[1]); conn.them = tsv[2]; conn.them_port = atoi(tsv.fields[3]); conn.name = tsv[4]; conn.protocol = tsv[5]; conn.in = tsv[6]=="1"; return tsv; } ////////////////////////////////////////////////////////////////////// // ConnList ////////////////////////////////////////////////////////////////////// int ConnList::find(Conn &needle) { int r; for(r=0; r