/* * FlowNode.cpp * Copyright (c) 2004-2006 Vlad GALU * Andrei GAVRILOAIE * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ #include CFlowNode::CFlowNode( in_addr& saddr, in_addr& daddr, u_short& sport, u_short& dport, u_char& tcp_flags, u_char& proto, u_char& tos, u_int& bytes, time_t& now) { m_flow.records.saddr = saddr; m_flow.records.daddr = daddr; m_flow.records.packets = 1; m_flow.records.bytes = bytes; m_flow.records.first = now; m_flow.records.last = now; m_flow.records.sport = sport; m_flow.records.dport = dport; m_flow.records.tcp_flags = tcp_flags; m_flow.records.proto = proto; m_flow.records.tos = tos; m_flow.stats.lastcheck = now; HASH((char*)&m_flow, 12, (u_char*)&key); m_pLeft = NULL; m_pRight = NULL; m_pParent = NULL; }; CFlowNode::~CFlowNode() { if (m_pLeft != NULL) { delete m_pLeft; m_pLeft = NULL; } if (m_pRight != NULL) { delete m_pRight; m_pRight = NULL; } }; bool CFlowNode::operator<(CFlowNode& node) { if (*this == node) return false; if (key[0] < node.key[0]) return true; if (key[0] > node.key[0]) return false; else { if (key[1] < node.key[1]) return true; if (key[1] > node.key[1]) return false; else { if (key[2] < node.key[2]) return true; if (key[2] > node.key[2]) return false; else { if (key[3] < node.key[3]) return true; else return false; } } } }; bool CFlowNode::operator > (CFlowNode& node) { if ((*this == node) || (*this < node)) return false; return true; }; bool CFlowNode::operator == (CFlowNode& node) { bool result = true; result = result && (key[0] == node.key[0]); result = result && (key[1] == node.key[1]); result = result && (key[2] == node.key[2]); result = result && (key[3] == node.key[3]); return result; }; bool CFlowNode::operator <= (CFlowNode& node) { if ((*this == node) || (*this < node)) return true; return false; }; bool CFlowNode::operator >= (CFlowNode& node) { if ((*this == node) || (*this > node)) return true; return false; }; #ifdef _DEBUG void CFlowNode::show(int& nrNodes) { if (m_pLeft!=NULL) m_pLeft->show(nrNodes); dprintf("\n"); u_char *tmp=(u_char*)&m_flow; for (int i=0;i<12;i++) dprintf("%02x",tmp[i]); dprintf(" %08x%08x%08x%08x\n", key[0],key[2],key[3],key[4]); nrNodes++; if (m_pRight!=NULL) m_pRight->show(nrNodes); }; #endif //_DEBUG // vi:ts=4