summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-04-07 09:49:19 (UTC)
committer mickeyl <mickeyl>2004-04-07 09:49:19 (UTC)
commitab892edccddb983b844065e2a13b15ecaecefbbd (patch) (side-by-side diff)
tree1fea3f8f6aee0246295d226168c49ec3193e6622
parent837069ed5f048c99774c88f2ad05a057a0b76ce8 (diff)
downloadopie-ab892edccddb983b844065e2a13b15ecaecefbbd.zip
opie-ab892edccddb983b844065e2a13b15ecaecefbbd.tar.gz
opie-ab892edccddb983b844065e2a13b15ecaecefbbd.tar.bz2
copy data handed over by libpcap because libpcap reuses the data area
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp39
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,5 +1,5 @@
/*
                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.
@@ -29,7 +29,10 @@
*/
+#include "udp_ports.h"
+#include "opcap.h"
+
/* OPIE */
-#include <opie2/opcap.h>
#include <opie2/odebug.h>
+using namespace Opie::Core;
/* QT */
@@ -38,13 +41,10 @@
#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 {
@@ -56,12 +56,14 @@ namespace Net {
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 )
@@ -69,15 +71,15 @@ OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char*
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;
@@ -90,5 +92,6 @@ OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char*
OPacket::~OPacket()
{
- qDebug( "OPacket::~OPacket( %s )", name() );
+ odebug << "~OPacket( " << name() << " )" << oendl;
+ delete _data;
}