summaryrefslogtreecommitdiff
Unidiff
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,6 +1,6 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> 3              Copyright (C) 2003-2004 by Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
@@ -28,24 +28,24 @@
28 28
29*/ 29*/
30 30
31#include "udp_ports.h"
32#include "opcap.h"
33
31/* OPIE */ 34/* OPIE */
32#include <opie2/opcap.h>
33#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36using namespace Opie::Core;
34 37
35/* QT */ 38/* QT */
36#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) 39#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects)
37#include <qsocketnotifier.h> 40#include <qsocketnotifier.h>
38#include <qobjectlist.h> 41#include <qobjectlist.h>
39 42
40/* SYSTEM */ 43/* STD */
41#include <sys/time.h> 44#include <sys/time.h>
42#include <sys/types.h> 45#include <sys/types.h>
46#include <assert.h>
43#include <unistd.h> 47#include <unistd.h>
44 48#include <string.h>
45/* LOCAL */
46#include "udp_ports.h"
47
48using namespace Opie::Core;
49 49
50namespace Opie { 50namespace Opie {
51namespace Net { 51namespace Net {
@@ -55,30 +55,32 @@ namespace Net {
55 *======================================================================================*/ 55 *======================================================================================*/
56 56
57OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 57OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
58 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 58 :QObject( parent, "Generic" ), _hdr( header ), _data( 0 )
59{ 59{
60 //FIXME: Copy the data structure here, because it isn't persistent. Check that.
61
62 qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
63 60
64 _end = (unsigned char*) data + header.len; 61 _data = new unsigned char[sizeof data];
65 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 62 assert( _data );
63 memcpy( const_cast<unsigned char*>(_data), data, sizeof data );
64 // We have to copy the data structure here, because the 'data' pointer handed by libpcap
65 // points to an internal region which is reused by lipcap.
66 odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl;
67 _end = (unsigned char*) _data + header.len;
66 68
67 switch ( datalink ) 69 switch ( datalink )
68 { 70 {
69 case DLT_EN10MB: 71 case DLT_EN10MB:
70 odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; 72 odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl;
71 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 73 new OEthernetPacket( _end, (const struct ether_header*) _data, this );
72 break; 74 break;
73 75
74 case DLT_IEEE802_11: 76 case DLT_IEEE802_11:
75 odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; 77 odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl;
76 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 78 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this );
77 break; 79 break;
78 80
79 case DLT_PRISM_HEADER: 81 case DLT_PRISM_HEADER:
80 odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; 82 odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl;
81 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); 83 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this );
82 break; 84 break;
83 85
84 default: 86 default:
@@ -89,7 +91,8 @@ OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char*
89 91
90OPacket::~OPacket() 92OPacket::~OPacket()
91{ 93{
92 qDebug( "OPacket::~OPacket( %s )", name() ); 94 odebug << "~OPacket( " << name() << " )" << oendl;
95 delete _data;
93} 96}
94 97
95 98