-rw-r--r-- | libopie2/opienet/opcap.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 93176c0..067d6b7 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp @@ -1,116 +1,119 @@ /* � � � � � � � � This file is part of the Opie Project -� � � � � � � Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> +� � � � � � � Copyright (C) 2003-2004 by Michael 'Mickey' Lauer <mickey@Vanille.de> =. .=l. � � � � � �.>+-= �_;:, � � .> � �:=|. This program is free software; you can .> <`_, � > �. � <= redistribute it and/or modify it under :`=1 )Y*s>-.-- � : the terms of the GNU Library General Public .="- .-=="i, � � .._ License as published by the Free Software �- . � .-<_> � � .<> Foundation; either version 2 of the License, � � �._= =} � � � : or (at your option) any later version. � � .%`+i> � � � _;_. � � .i_,=:_. � � �-<s. 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 ..}^=.= � � � = � � � ; Library General Public License for more ++= � -. � � .` � � .: details. �: � � = �...= . :.=- �-. � .:....=;==+<; You should have received a copy of the GNU � -_. . . � )=. �= Library General Public License along with � � -- � � � �:-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "udp_ports.h" +#include "opcap.h" + /* OPIE */ -#include <opie2/opcap.h> #include <opie2/odebug.h> +using namespace Opie::Core; /* QT */ #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) #include <qsocketnotifier.h> #include <qobjectlist.h> -/* SYSTEM */ +/* STD */ #include <sys/time.h> #include <sys/types.h> +#include <assert.h> #include <unistd.h> - -/* LOCAL */ -#include "udp_ports.h" - -using namespace Opie::Core; +#include <string.h> namespace Opie { namespace Net { /*====================================================================================== * OPacket *======================================================================================*/ OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) - :QObject( parent, "Generic" ), _hdr( header ), _data( data ) + :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) { - //FIXME: Copy the data structure here, because it isn't persistent. Check that. - - qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); - _end = (unsigned char*) data + header.len; - //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); + _data = new unsigned char[sizeof data]; + assert( _data ); + memcpy( const_cast<unsigned char*>(_data), data, sizeof data ); + // We have to copy the data structure here, because the 'data' pointer handed by libpcap + // points to an internal region which is reused by lipcap. + odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; + _end = (unsigned char*) _data + header.len; switch ( datalink ) { case DLT_EN10MB: odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; - new OEthernetPacket( _end, (const struct ether_header*) data, this ); + new OEthernetPacket( _end, (const struct ether_header*) _data, this ); break; case DLT_IEEE802_11: odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; - new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); + new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); break; case DLT_PRISM_HEADER: odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; - new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); + new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); break; default: owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; } } OPacket::~OPacket() { - qDebug( "OPacket::~OPacket( %s )", name() ); + odebug << "~OPacket( " << name() << " )" << oendl; + delete _data; } timevalstruct OPacket::timeval() const { return _hdr.ts; } int OPacket::caplen() const { return _hdr.caplen; } void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) { if (!l) return; QObject* o = l->first(); while ( o ) { stats[o->name()]++; updateStats( stats, const_cast<QObjectList*>( o->children() ) ); o = l->next(); |