author | mickeyl <mickeyl> | 2003-10-05 13:12:45 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-05 13:12:45 (UTC) |
commit | 634a68b636a0fa24232029b79ffa915a5621b2be (patch) (unidiff) | |
tree | 3e4c58bebfd624e841c314f1db68d985d81cdc6c /libopie2/opienet | |
parent | dc9510f788212a6be063349461540e4bea690f51 (diff) | |
download | opie-634a68b636a0fa24232029b79ffa915a5621b2be.zip opie-634a68b636a0fa24232029b79ffa915a5621b2be.tar.gz opie-634a68b636a0fa24232029b79ffa915a5621b2be.tar.bz2 |
* start with preparations for scanning wired networks
* dhcp recognition now works nicely
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 7 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.h | 1 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 27 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 5 |
4 files changed, 38 insertions, 2 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index 08c40b4..ad0e89d 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp | |||
@@ -45,34 +45,39 @@ using namespace std; | |||
45 | #define IW_PRIV_TYPE_INT 0x4000 | 45 | #define IW_PRIV_TYPE_INT 0x4000 |
46 | #define IW_PRIV_TYPE_FLOAT 0x5000 | 46 | #define IW_PRIV_TYPE_FLOAT 0x5000 |
47 | #define IW_PRIV_TYPE_ADDR 0x6000 | 47 | #define IW_PRIV_TYPE_ADDR 0x6000 |
48 | #define IW_PRIV_SIZE_FIXED 0x0800 | 48 | #define IW_PRIV_SIZE_FIXED 0x0800 |
49 | #define IW_PRIV_SIZE_MASK 0x07FF | 49 | #define IW_PRIV_SIZE_MASK 0x07FF |
50 | 50 | ||
51 | /*====================================================================================== | 51 | /*====================================================================================== |
52 | * OMacAddress | 52 | * OMacAddress |
53 | *======================================================================================*/ | 53 | *======================================================================================*/ |
54 | 54 | ||
55 | // static initializer for broadcast and unknown MAC Adresses | 55 | // static initializer for broadcast and unknown MAC Adresses |
56 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 56 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
57 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); | 57 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); |
58 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; | 58 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; |
59 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); | 59 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); |
60 | 60 | ||
61 | //TODO: Incorporate Ethernet Manufacturer database here! (inline or so) | ||
62 | |||
63 | OMacAddress::OMacAddress() | ||
64 | { | ||
65 | memcpy( _bytes, __unknown, 6 ); | ||
66 | } | ||
61 | 67 | ||
62 | //TODO: Incorporate Ethernet Manufacturer database here! | ||
63 | 68 | ||
64 | OMacAddress::OMacAddress( unsigned char* p ) | 69 | OMacAddress::OMacAddress( unsigned char* p ) |
65 | { | 70 | { |
66 | memcpy( _bytes, p, 6 ); | 71 | memcpy( _bytes, p, 6 ); |
67 | } | 72 | } |
68 | 73 | ||
69 | 74 | ||
70 | OMacAddress::OMacAddress( const unsigned char* p ) | 75 | OMacAddress::OMacAddress( const unsigned char* p ) |
71 | { | 76 | { |
72 | memcpy( _bytes, p, 6 ); | 77 | memcpy( _bytes, p, 6 ); |
73 | } | 78 | } |
74 | 79 | ||
75 | 80 | ||
76 | OMacAddress::OMacAddress( struct ifreq& ifr ) | 81 | OMacAddress::OMacAddress( struct ifreq& ifr ) |
77 | { | 82 | { |
78 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); | 83 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); |
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h index 9611518..18731ba 100644 --- a/libopie2/opienet/onetutils.h +++ b/libopie2/opienet/onetutils.h | |||
@@ -38,32 +38,33 @@ | |||
38 | #include <qhostaddress.h> | 38 | #include <qhostaddress.h> |
39 | #include <qobject.h> | 39 | #include <qobject.h> |
40 | 40 | ||
41 | #include <sys/types.h> | 41 | #include <sys/types.h> |
42 | 42 | ||
43 | struct ifreq; | 43 | struct ifreq; |
44 | class OWirelessNetworkInterface; | 44 | class OWirelessNetworkInterface; |
45 | 45 | ||
46 | /*====================================================================================== | 46 | /*====================================================================================== |
47 | * OMacAddress | 47 | * OMacAddress |
48 | *======================================================================================*/ | 48 | *======================================================================================*/ |
49 | 49 | ||
50 | class OMacAddress | 50 | class OMacAddress |
51 | { | 51 | { |
52 | public: | 52 | public: |
53 | // QString c'tor? -zecke | 53 | // QString c'tor? -zecke |
54 | OMacAddress(); | ||
54 | OMacAddress( unsigned char* ); | 55 | OMacAddress( unsigned char* ); |
55 | OMacAddress( const unsigned char* ); | 56 | OMacAddress( const unsigned char* ); |
56 | OMacAddress( struct ifreq& ); | 57 | OMacAddress( struct ifreq& ); |
57 | ~OMacAddress(); | 58 | ~OMacAddress(); |
58 | 59 | ||
59 | QString manufacturer() const; | 60 | QString manufacturer() const; |
60 | QString toString( bool substitute = false ) const; | 61 | QString toString( bool substitute = false ) const; |
61 | const unsigned char* native() const; | 62 | const unsigned char* native() const; |
62 | 63 | ||
63 | // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem? | 64 | // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem? |
64 | static OMacAddress fromString( const QString& ); | 65 | static OMacAddress fromString( const QString& ); |
65 | 66 | ||
66 | public: | 67 | public: |
67 | static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff | 68 | static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff |
68 | static const OMacAddress& unknown; // 44:44:44:44:44:44 | 69 | static const OMacAddress& unknown; // 44:44:44:44:44:44 |
69 | 70 | ||
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 7a6f61b..313f5bb 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -95,32 +95,55 @@ int OPacket::caplen() const | |||
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 98 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
99 | { | 99 | { |
100 | if (!l) return; | 100 | if (!l) return; |
101 | QObject* o = l->first(); | 101 | QObject* o = l->first(); |
102 | while ( o ) | 102 | while ( o ) |
103 | { | 103 | { |
104 | stats[o->name()]++; | 104 | stats[o->name()]++; |
105 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 105 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
106 | o = l->next(); | 106 | o = l->next(); |
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | void OPacket::dumpStructure( QObjectList* l ) | ||
112 | { | ||
113 | QString packetString( "[ |" + _dumpStructure( l ) + " ]" ); | ||
114 | qDebug( "OPacket::dumpStructure: %s", (const char*) packetString ); | ||
115 | } | ||
116 | |||
117 | |||
118 | QString OPacket::_dumpStructure( QObjectList* l ) | ||
119 | { | ||
120 | if (!l) return QString::null; | ||
121 | QObject* o = l->first(); | ||
122 | QString str(" "); | ||
123 | |||
124 | while ( o ) | ||
125 | { | ||
126 | str.append( o->name() ); | ||
127 | str.append( " |" ); | ||
128 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); | ||
129 | o = l->next(); | ||
130 | } | ||
131 | return str; | ||
132 | } | ||
133 | |||
111 | QString OPacket::dump( int bpl ) const | 134 | QString OPacket::dump( int bpl ) const |
112 | { | 135 | { |
113 | static int index = 0; | 136 | static int index = 0; |
114 | index++; | 137 | index++; |
115 | int len = _hdr.caplen; | 138 | int len = _hdr.caplen; |
116 | QString str; | 139 | QString str; |
117 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); | 140 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); |
118 | str.append( "0000: " ); | 141 | str.append( "0000: " ); |
119 | QString tmp; | 142 | QString tmp; |
120 | QString bytes; | 143 | QString bytes; |
121 | QString chars; | 144 | QString chars; |
122 | 145 | ||
123 | for ( int i = 0; i < len; ++i ) | 146 | for ( int i = 0; i < len; ++i ) |
124 | { | 147 | { |
125 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 148 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
126 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 149 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
@@ -1103,33 +1126,35 @@ int OPacketCapturer::fileno() const | |||
1103 | OPacket* OPacketCapturer::next() | 1126 | OPacket* OPacketCapturer::next() |
1104 | { | 1127 | { |
1105 | packetheaderstruct header; | 1128 | packetheaderstruct header; |
1106 | qDebug( "==> OPacketCapturer::next()" ); | 1129 | qDebug( "==> OPacketCapturer::next()" ); |
1107 | const unsigned char* pdata = pcap_next( _pch, &header ); | 1130 | const unsigned char* pdata = pcap_next( _pch, &header ); |
1108 | qDebug( "<== OPacketCapturer::next()" ); | 1131 | qDebug( "<== OPacketCapturer::next()" ); |
1109 | 1132 | ||
1110 | if ( pdata && header.len ) | 1133 | if ( pdata && header.len ) |
1111 | { | 1134 | { |
1112 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); | 1135 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); |
1113 | // packets shouldn't be inserted in the QObject child-parent hierarchy, | 1136 | // packets shouldn't be inserted in the QObject child-parent hierarchy, |
1114 | // because due to memory constraints they will be deleted as soon | 1137 | // because due to memory constraints they will be deleted as soon |
1115 | // as possible - that is right after they have been processed | 1138 | // as possible - that is right after they have been processed |
1116 | // by emit() [ see below ] | 1139 | // by emit() [ see below ] |
1117 | //TODO: make gathering statistics optional, because it takes time | 1140 | //TODO: make gathering statistics optional, because it takes time |
1118 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); | 1141 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); |
1119 | 1142 | #ifndef NODEBUG | |
1143 | p->dumpStructure( const_cast<QObjectList*>( p->children() ) ); | ||
1144 | #endif | ||
1120 | return p; | 1145 | return p; |
1121 | } | 1146 | } |
1122 | else | 1147 | else |
1123 | { | 1148 | { |
1124 | qWarning( "OPacketCapturer::next() - no packet received!" ); | 1149 | qWarning( "OPacketCapturer::next() - no packet received!" ); |
1125 | return 0; | 1150 | return 0; |
1126 | } | 1151 | } |
1127 | } | 1152 | } |
1128 | 1153 | ||
1129 | 1154 | ||
1130 | bool OPacketCapturer::open( const QString& name ) | 1155 | bool OPacketCapturer::open( const QString& name ) |
1131 | { | 1156 | { |
1132 | if ( _open ) | 1157 | if ( _open ) |
1133 | { | 1158 | { |
1134 | if ( name == _name ) // ignore opening an already openend device | 1159 | if ( name == _name ) // ignore opening an already openend device |
1135 | { | 1160 | { |
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index a031dd1..f0d1d81 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -120,32 +120,37 @@ class OPacket : public QObject | |||
120 | 120 | ||
121 | friend class OPacketCapturer; | 121 | friend class OPacketCapturer; |
122 | 122 | ||
123 | public: | 123 | public: |
124 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); | 124 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); |
125 | virtual ~OPacket(); | 125 | virtual ~OPacket(); |
126 | 126 | ||
127 | timevalstruct timeval() const; | 127 | timevalstruct timeval() const; |
128 | 128 | ||
129 | int caplen() const; | 129 | int caplen() const; |
130 | int len() const; | 130 | int len() const; |
131 | QString dump( int = 32 ) const; | 131 | QString dump( int = 32 ) const; |
132 | 132 | ||
133 | void updateStats( QMap<QString,int>&, QObjectList* ); | 133 | void updateStats( QMap<QString,int>&, QObjectList* ); |
134 | 134 | ||
135 | private: | 135 | private: |
136 | |||
137 | void dumpStructure( QObjectList* ); | ||
138 | QString _dumpStructure( QObjectList* ); | ||
139 | |||
140 | private: | ||
136 | const packetheaderstruct _hdr; // pcap packet header | 141 | const packetheaderstruct _hdr; // pcap packet header |
137 | const unsigned char* _data; // pcap packet data | 142 | const unsigned char* _data; // pcap packet data |
138 | const unsigned char* _end; // end of pcap packet data | 143 | const unsigned char* _end; // end of pcap packet data |
139 | }; | 144 | }; |
140 | 145 | ||
141 | /*====================================================================================== | 146 | /*====================================================================================== |
142 | * OEthernetPacket - DLT_EN10MB frame | 147 | * OEthernetPacket - DLT_EN10MB frame |
143 | *======================================================================================*/ | 148 | *======================================================================================*/ |
144 | 149 | ||
145 | class OEthernetPacket : public QObject | 150 | class OEthernetPacket : public QObject |
146 | { | 151 | { |
147 | Q_OBJECT | 152 | Q_OBJECT |
148 | 153 | ||
149 | public: | 154 | public: |
150 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); | 155 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
151 | virtual ~OEthernetPacket(); | 156 | virtual ~OEthernetPacket(); |