author | mickeyl <mickeyl> | 2005-02-07 11:36:05 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-02-07 11:36:05 (UTC) |
commit | 896d2e77ebafd09ee58d6148e31365f47a3668b4 (patch) (unidiff) | |
tree | bffff919cd5cc864465c773db52ce8d8f48fe2c8 | |
parent | 5652634e4ff03370564925ce0856b260c001dc0f (diff) | |
download | opie-896d2e77ebafd09ee58d6148e31365f47a3668b4.zip opie-896d2e77ebafd09ee58d6148e31365f47a3668b4.tar.gz opie-896d2e77ebafd09ee58d6148e31365f47a3668b4.tar.bz2 |
change license.
-rw-r--r-- | libopie2/opienet/omanufacturerdb.cpp | 4 | ||||
-rw-r--r-- | libopie2/opienet/omanufacturerdb.h | 4 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 4 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.h | 4 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 4 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 4 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 4 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 4 | ||||
-rw-r--r-- | libopie2/opienet/ostation.cpp | 4 | ||||
-rw-r--r-- | libopie2/opienet/ostation.h | 4 |
10 files changed, 20 insertions, 20 deletions
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp index 7e185a2..123aee8 100644 --- a/libopie2/opienet/omanufacturerdb.cpp +++ b/libopie2/opienet/omanufacturerdb.cpp | |||
@@ -1,143 +1,143 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "omanufacturerdb.h" | 29 | #include "omanufacturerdb.h" |
30 | 30 | ||
31 | #define OPIE_IMPROVE_GUI_LATENCY 1 | 31 | #define OPIE_IMPROVE_GUI_LATENCY 1 |
32 | 32 | ||
33 | /* OPIE */ | 33 | /* OPIE */ |
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
36 | #ifdef OPIE_IMPROVE_GUI_LATENCY | 36 | #ifdef OPIE_IMPROVE_GUI_LATENCY |
37 | #include <qpe/global.h> | 37 | #include <qpe/global.h> |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | 40 | ||
41 | 41 | ||
42 | /* QT */ | 42 | /* QT */ |
43 | #include <qapplication.h> | 43 | #include <qapplication.h> |
44 | #include <qfile.h> | 44 | #include <qfile.h> |
45 | #include <qtextstream.h> | 45 | #include <qtextstream.h> |
46 | 46 | ||
47 | using namespace Opie::Core; | 47 | using namespace Opie::Core; |
48 | namespace Opie { | 48 | namespace Opie { |
49 | namespace Net { | 49 | namespace Net { |
50 | 50 | ||
51 | OManufacturerDB* OManufacturerDB::_instance = 0; | 51 | OManufacturerDB* OManufacturerDB::_instance = 0; |
52 | 52 | ||
53 | OManufacturerDB* OManufacturerDB::instance() | 53 | OManufacturerDB* OManufacturerDB::instance() |
54 | { | 54 | { |
55 | if ( !OManufacturerDB::_instance ) | 55 | if ( !OManufacturerDB::_instance ) |
56 | { | 56 | { |
57 | odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; | 57 | odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; |
58 | _instance = new OManufacturerDB(); | 58 | _instance = new OManufacturerDB(); |
59 | } | 59 | } |
60 | return _instance; | 60 | return _instance; |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | OManufacturerDB::OManufacturerDB() | 64 | OManufacturerDB::OManufacturerDB() |
65 | { | 65 | { |
66 | #ifdef OPIE_IMPROVE_GUI_LATENCY | 66 | #ifdef OPIE_IMPROVE_GUI_LATENCY |
67 | Global::statusMessage( "Reading Manufacturers..." ); | 67 | Global::statusMessage( "Reading Manufacturers..." ); |
68 | #endif | 68 | #endif |
69 | QString filename( "/etc/manufacturers" ); | 69 | QString filename( "/etc/manufacturers" ); |
70 | odebug << "OManufacturerDB: trying to read " << filename << oendl; | 70 | odebug << "OManufacturerDB: trying to read " << filename << oendl; |
71 | if ( !QFile::exists( filename ) ) | 71 | if ( !QFile::exists( filename ) ) |
72 | { | 72 | { |
73 | filename = QPEApplication::qpeDir()+"etc/manufacturers"; | 73 | filename = QPEApplication::qpeDir()+"etc/manufacturers"; |
74 | odebug << "OManufacturerDB: trying to read " << filename << oendl; | 74 | odebug << "OManufacturerDB: trying to read " << filename << oendl; |
75 | if ( !QFile::exists( filename ) ) | 75 | if ( !QFile::exists( filename ) ) |
76 | { | 76 | { |
77 | filename = "/usr/share/wellenreiter/manufacturers"; | 77 | filename = "/usr/share/wellenreiter/manufacturers"; |
78 | odebug << "OManufacturerDB: trying to read " << filename << oendl; | 78 | odebug << "OManufacturerDB: trying to read " << filename << oendl; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | QFile file( filename ); | 82 | QFile file( filename ); |
83 | bool hasFile = file.open( IO_ReadOnly ); | 83 | bool hasFile = file.open( IO_ReadOnly ); |
84 | if (!hasFile) | 84 | if (!hasFile) |
85 | { | 85 | { |
86 | owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; | 86 | owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; |
87 | } | 87 | } |
88 | else | 88 | else |
89 | { | 89 | { |
90 | odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; | 90 | odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; |
91 | QTextStream s( &file ); | 91 | QTextStream s( &file ); |
92 | QString addr; | 92 | QString addr; |
93 | QString manu; | 93 | QString manu; |
94 | QString extManu; | 94 | QString extManu; |
95 | #ifdef OPIE_IMPROVE_GUI_LATENCY | 95 | #ifdef OPIE_IMPROVE_GUI_LATENCY |
96 | int counter = 0; | 96 | int counter = 0; |
97 | #endif | 97 | #endif |
98 | while (!s.atEnd()) | 98 | while (!s.atEnd()) |
99 | { | 99 | { |
100 | s >> addr; | 100 | s >> addr; |
101 | s >> manu; | 101 | s >> manu; |
102 | s >> extManu; | 102 | s >> extManu; |
103 | 103 | ||
104 | manufacturers.insert( addr, manu ); | 104 | manufacturers.insert( addr, manu ); |
105 | manufacturersExt.insert( addr, extManu ); | 105 | manufacturersExt.insert( addr, extManu ); |
106 | // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; | 106 | // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; |
107 | #ifdef OPIE_IMPROVE_GUI_LATENCY | 107 | #ifdef OPIE_IMPROVE_GUI_LATENCY |
108 | counter++; | 108 | counter++; |
109 | if ( counter == 50 ) | 109 | if ( counter == 50 ) |
110 | { | 110 | { |
111 | qApp->processEvents(); | 111 | qApp->processEvents(); |
112 | counter = 0; | 112 | counter = 0; |
113 | } | 113 | } |
114 | #endif | 114 | #endif |
115 | } | 115 | } |
116 | odebug << "OManufacturerDB: manufacturer list completed." << oendl; | 116 | odebug << "OManufacturerDB: manufacturer list completed." << oendl; |
117 | #ifdef OPIE_IMPROVE_GUI_LATENCY | 117 | #ifdef OPIE_IMPROVE_GUI_LATENCY |
118 | Global::statusMessage( "Manufacturers Complete..." ); | 118 | Global::statusMessage( "Manufacturers Complete..." ); |
119 | #endif | 119 | #endif |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | OManufacturerDB::~OManufacturerDB() | 124 | OManufacturerDB::~OManufacturerDB() |
125 | { | 125 | { |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
129 | const QString& OManufacturerDB::lookup( const QString& macaddr ) const | 129 | const QString& OManufacturerDB::lookup( const QString& macaddr ) const |
130 | { | 130 | { |
131 | return manufacturers[macaddr.upper().left(8)]; | 131 | return manufacturers[macaddr.upper().left(8)]; |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
135 | const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const | 135 | const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const |
136 | { | 136 | { |
137 | QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); | 137 | QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); |
138 | return it == manufacturersExt.end() ? lookup( macaddr ) : *it; | 138 | return it == manufacturersExt.end() ? lookup( macaddr ) : *it; |
139 | } | 139 | } |
140 | 140 | ||
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
diff --git a/libopie2/opienet/omanufacturerdb.h b/libopie2/opienet/omanufacturerdb.h index c667e20..2b3b7ed 100644 --- a/libopie2/opienet/omanufacturerdb.h +++ b/libopie2/opienet/omanufacturerdb.h | |||
@@ -1,75 +1,75 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef OMANUFACTURERDB_H | 29 | #ifndef OMANUFACTURERDB_H |
30 | #define OMANUFACTURERDB_H | 30 | #define OMANUFACTURERDB_H |
31 | 31 | ||
32 | #include <qmap.h> | 32 | #include <qmap.h> |
33 | 33 | ||
34 | namespace Opie { | 34 | namespace Opie { |
35 | namespace Net { | 35 | namespace Net { |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * @brief A Ethernet card vendor database. | 38 | * @brief A Ethernet card vendor database. |
39 | * | 39 | * |
40 | * This class encapsulates the lookup of Ethernet vendor given a | 40 | * This class encapsulates the lookup of Ethernet vendor given a |
41 | * certain Mac Address. Only the first three bytes define the vendor. | 41 | * certain Mac Address. Only the first three bytes define the vendor. |
42 | */ | 42 | */ |
43 | class OManufacturerDB | 43 | class OManufacturerDB |
44 | { | 44 | { |
45 | public: | 45 | public: |
46 | /** | 46 | /** |
47 | * @returns the one-and-only @ref OManufacturerDB instance. | 47 | * @returns the one-and-only @ref OManufacturerDB instance. |
48 | */ | 48 | */ |
49 | static OManufacturerDB* instance(); | 49 | static OManufacturerDB* instance(); |
50 | /** | 50 | /** |
51 | * @returns the short manufacturer string given a @a macaddr. | 51 | * @returns the short manufacturer string given a @a macaddr. |
52 | */ | 52 | */ |
53 | const QString& lookup( const QString& macaddr ) const; | 53 | const QString& lookup( const QString& macaddr ) const; |
54 | /** | 54 | /** |
55 | * @returns the enhanced manufacturer string given a @a macaddr. | 55 | * @returns the enhanced manufacturer string given a @a macaddr. |
56 | */ | 56 | */ |
57 | const QString& lookupExt( const QString& macaddr ) const; | 57 | const QString& lookupExt( const QString& macaddr ) const; |
58 | 58 | ||
59 | protected: | 59 | protected: |
60 | OManufacturerDB(); | 60 | OManufacturerDB(); |
61 | virtual ~OManufacturerDB(); | 61 | virtual ~OManufacturerDB(); |
62 | 62 | ||
63 | private: | 63 | private: |
64 | QMap<QString, QString> manufacturers; | 64 | QMap<QString, QString> manufacturers; |
65 | QMap<QString, QString> manufacturersExt; | 65 | QMap<QString, QString> manufacturersExt; |
66 | static OManufacturerDB* _instance; | 66 | static OManufacturerDB* _instance; |
67 | class Private; | 67 | class Private; |
68 | Private *d; | 68 | Private *d; |
69 | }; | 69 | }; |
70 | 70 | ||
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | #endif | 74 | #endif |
75 | 75 | ||
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index 047a704..c8c494a 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp | |||
@@ -1,241 +1,241 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 4 | (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; version 2 of the License. |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <opie2/onetutils.h> | 32 | #include <opie2/onetutils.h> |
33 | #include <opie2/onetwork.h> | 33 | #include <opie2/onetwork.h> |
34 | #include <opie2/omanufacturerdb.h> | 34 | #include <opie2/omanufacturerdb.h> |
35 | 35 | ||
36 | #include <net/if.h> | 36 | #include <net/if.h> |
37 | #include <assert.h> | 37 | #include <assert.h> |
38 | #include <stdio.h> | 38 | #include <stdio.h> |
39 | 39 | ||
40 | namespace Opie { | 40 | namespace Opie { |
41 | namespace Net { | 41 | namespace Net { |
42 | 42 | ||
43 | /*====================================================================================== | 43 | /*====================================================================================== |
44 | * OMacAddress | 44 | * OMacAddress |
45 | *======================================================================================*/ | 45 | *======================================================================================*/ |
46 | 46 | ||
47 | // static initializer for broadcast and unknown MAC Adresses | 47 | // static initializer for broadcast and unknown MAC Adresses |
48 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 48 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
49 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); | 49 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); |
50 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; | 50 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; |
51 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); | 51 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); |
52 | 52 | ||
53 | //TODO: Incorporate Ethernet Manufacturer database here! (inline or so) | 53 | //TODO: Incorporate Ethernet Manufacturer database here! (inline or so) |
54 | 54 | ||
55 | OMacAddress::OMacAddress() | 55 | OMacAddress::OMacAddress() |
56 | { | 56 | { |
57 | memcpy( _bytes, __unknown, 6 ); | 57 | memcpy( _bytes, __unknown, 6 ); |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | OMacAddress::OMacAddress( unsigned char* p ) | 61 | OMacAddress::OMacAddress( unsigned char* p ) |
62 | { | 62 | { |
63 | memcpy( _bytes, p, 6 ); | 63 | memcpy( _bytes, p, 6 ); |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
67 | OMacAddress::OMacAddress( const unsigned char* p ) | 67 | OMacAddress::OMacAddress( const unsigned char* p ) |
68 | { | 68 | { |
69 | memcpy( _bytes, p, 6 ); | 69 | memcpy( _bytes, p, 6 ); |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | OMacAddress::OMacAddress( struct ifreq& ifr ) | 73 | OMacAddress::OMacAddress( struct ifreq& ifr ) |
74 | { | 74 | { |
75 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); | 75 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | OMacAddress::~OMacAddress() | 79 | OMacAddress::~OMacAddress() |
80 | { | 80 | { |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | //#ifdef QT_NO_DEBUG | 84 | //#ifdef QT_NO_DEBUG |
85 | //inline | 85 | //inline |
86 | //#endif | 86 | //#endif |
87 | const unsigned char* OMacAddress::native() const | 87 | const unsigned char* OMacAddress::native() const |
88 | { | 88 | { |
89 | return (const unsigned char*) &_bytes; | 89 | return (const unsigned char*) &_bytes; |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | OMacAddress OMacAddress::fromString( const QString& str ) | 93 | OMacAddress OMacAddress::fromString( const QString& str ) |
94 | { | 94 | { |
95 | QString addr( str ); | 95 | QString addr( str ); |
96 | unsigned char buf[6]; | 96 | unsigned char buf[6]; |
97 | bool ok = true; | 97 | bool ok = true; |
98 | int index = 14; | 98 | int index = 14; |
99 | for ( int i = 5; i >= 0; --i ) | 99 | for ( int i = 5; i >= 0; --i ) |
100 | { | 100 | { |
101 | buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); | 101 | buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); |
102 | if ( !ok ) return OMacAddress::unknown; | 102 | if ( !ok ) return OMacAddress::unknown; |
103 | addr.truncate( index ); | 103 | addr.truncate( index ); |
104 | index -= 3; | 104 | index -= 3; |
105 | } | 105 | } |
106 | return (const unsigned char*) &buf; | 106 | return (const unsigned char*) &buf; |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | QString OMacAddress::toString( bool substitute ) const | 110 | QString OMacAddress::toString( bool substitute ) const |
111 | { | 111 | { |
112 | QString manu; | 112 | QString manu; |
113 | manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff ); | 113 | manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff ); |
114 | QString serial; | 114 | QString serial; |
115 | serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); | 115 | serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); |
116 | if ( !substitute ) return manu+serial; | 116 | if ( !substitute ) return manu+serial; |
117 | // fallback - if no vendor is found, just use the number | 117 | // fallback - if no vendor is found, just use the number |
118 | QString textmanu = OManufacturerDB::instance()->lookup( manu ); | 118 | QString textmanu = OManufacturerDB::instance()->lookup( manu ); |
119 | return textmanu.isNull() ? manu+serial : textmanu+serial; | 119 | return textmanu.isNull() ? manu+serial : textmanu+serial; |
120 | } | 120 | } |
121 | 121 | ||
122 | 122 | ||
123 | QString OMacAddress::manufacturer() const | 123 | QString OMacAddress::manufacturer() const |
124 | { | 124 | { |
125 | return OManufacturerDB::instance()->lookupExt( toString() ); | 125 | return OManufacturerDB::instance()->lookupExt( toString() ); |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
129 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) | 129 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) |
130 | { | 130 | { |
131 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; | 131 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
135 | /*====================================================================================== | 135 | /*====================================================================================== |
136 | * OHostAddress | 136 | * OHostAddress |
137 | *======================================================================================*/ | 137 | *======================================================================================*/ |
138 | 138 | ||
139 | 139 | ||
140 | /*====================================================================================== | 140 | /*====================================================================================== |
141 | * OPrivateIOCTL | 141 | * OPrivateIOCTL |
142 | *======================================================================================*/ | 142 | *======================================================================================*/ |
143 | 143 | ||
144 | OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) | 144 | OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) |
145 | :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) | 145 | :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) |
146 | { | 146 | { |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | OPrivateIOCTL::~OPrivateIOCTL() | 150 | OPrivateIOCTL::~OPrivateIOCTL() |
151 | { | 151 | { |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | int OPrivateIOCTL::numberGetArgs() const | 155 | int OPrivateIOCTL::numberGetArgs() const |
156 | { | 156 | { |
157 | return _getargs & IW_PRIV_SIZE_MASK; | 157 | return _getargs & IW_PRIV_SIZE_MASK; |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | int OPrivateIOCTL::typeGetArgs() const | 161 | int OPrivateIOCTL::typeGetArgs() const |
162 | { | 162 | { |
163 | return _getargs & IW_PRIV_TYPE_MASK >> 12; | 163 | return _getargs & IW_PRIV_TYPE_MASK >> 12; |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | int OPrivateIOCTL::numberSetArgs() const | 167 | int OPrivateIOCTL::numberSetArgs() const |
168 | { | 168 | { |
169 | return _setargs & IW_PRIV_SIZE_MASK; | 169 | return _setargs & IW_PRIV_SIZE_MASK; |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
173 | int OPrivateIOCTL::typeSetArgs() const | 173 | int OPrivateIOCTL::typeSetArgs() const |
174 | { | 174 | { |
175 | return _setargs & IW_PRIV_TYPE_MASK >> 12; | 175 | return _setargs & IW_PRIV_TYPE_MASK >> 12; |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
179 | void OPrivateIOCTL::invoke() const | 179 | void OPrivateIOCTL::invoke() const |
180 | { | 180 | { |
181 | ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); | 181 | ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); |
182 | } | 182 | } |
183 | 183 | ||
184 | 184 | ||
185 | void OPrivateIOCTL::setParameter( int num, u_int32_t value ) | 185 | void OPrivateIOCTL::setParameter( int num, u_int32_t value ) |
186 | { | 186 | { |
187 | u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; | 187 | u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; |
188 | arglist[num] = value; | 188 | arglist[num] = value; |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | 192 | ||
193 | namespace Internal { | 193 | namespace Internal { |
194 | /*====================================================================================== | 194 | /*====================================================================================== |
195 | * assorted functions | 195 | * assorted functions |
196 | *======================================================================================*/ | 196 | *======================================================================================*/ |
197 | 197 | ||
198 | void dumpBytes( const unsigned char* data, int num ) | 198 | void dumpBytes( const unsigned char* data, int num ) |
199 | { | 199 | { |
200 | printf( "Dumping %d bytes @ 0x%p", num, data ); | 200 | printf( "Dumping %d bytes @ 0x%p", num, data ); |
201 | printf( "-------------------------------------------\n" ); | 201 | printf( "-------------------------------------------\n" ); |
202 | 202 | ||
203 | for ( int i = 0; i < num; ++i ) | 203 | for ( int i = 0; i < num; ++i ) |
204 | { | 204 | { |
205 | printf( "%02x ", data[i] ); | 205 | printf( "%02x ", data[i] ); |
206 | if ( !((i+1) % 32) ) printf( "\n" ); | 206 | if ( !((i+1) % 32) ) printf( "\n" ); |
207 | } | 207 | } |
208 | printf( "\n\n" ); | 208 | printf( "\n\n" ); |
209 | } | 209 | } |
210 | 210 | ||
211 | 211 | ||
212 | int stringToMode( const QString& mode ) | 212 | int stringToMode( const QString& mode ) |
213 | { | 213 | { |
214 | if ( mode == "auto" ) return IW_MODE_AUTO; | 214 | if ( mode == "auto" ) return IW_MODE_AUTO; |
215 | else if ( mode == "adhoc" ) return IW_MODE_ADHOC; | 215 | else if ( mode == "adhoc" ) return IW_MODE_ADHOC; |
216 | else if ( mode == "managed" ) return IW_MODE_INFRA; | 216 | else if ( mode == "managed" ) return IW_MODE_INFRA; |
217 | else if ( mode == "master" ) return IW_MODE_MASTER; | 217 | else if ( mode == "master" ) return IW_MODE_MASTER; |
218 | else if ( mode == "repeater" ) return IW_MODE_REPEAT; | 218 | else if ( mode == "repeater" ) return IW_MODE_REPEAT; |
219 | else if ( mode == "secondary" ) return IW_MODE_SECOND; | 219 | else if ( mode == "secondary" ) return IW_MODE_SECOND; |
220 | else if ( mode == "monitor" ) return IW_MODE_MONITOR; | 220 | else if ( mode == "monitor" ) return IW_MODE_MONITOR; |
221 | else assert( 0 ); | 221 | else assert( 0 ); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | QString modeToString( int mode ) | 225 | QString modeToString( int mode ) |
226 | { | 226 | { |
227 | switch ( mode ) | 227 | switch ( mode ) |
228 | { | 228 | { |
229 | case IW_MODE_AUTO: return "auto"; | 229 | case IW_MODE_AUTO: return "auto"; |
230 | case IW_MODE_ADHOC: return "adhoc"; | 230 | case IW_MODE_ADHOC: return "adhoc"; |
231 | case IW_MODE_INFRA: return "managed"; | 231 | case IW_MODE_INFRA: return "managed"; |
232 | case IW_MODE_MASTER: return "master"; | 232 | case IW_MODE_MASTER: return "master"; |
233 | case IW_MODE_REPEAT: return "repeater"; | 233 | case IW_MODE_REPEAT: return "repeater"; |
234 | case IW_MODE_SECOND: return "second"; | 234 | case IW_MODE_SECOND: return "second"; |
235 | case IW_MODE_MONITOR: return "monitor"; | 235 | case IW_MODE_MONITOR: return "monitor"; |
236 | default: assert( 0 ); | 236 | default: assert( 0 ); |
237 | } | 237 | } |
238 | } | 238 | } |
239 | } | 239 | } |
240 | } | 240 | } |
241 | } | 241 | } |
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h index 4a09426..f1d34a0 100644 --- a/libopie2/opienet/onetutils.h +++ b/libopie2/opienet/onetutils.h | |||
@@ -1,196 +1,196 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; version 2 of the License. |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #ifndef ONETUTILS_H | 32 | #ifndef ONETUTILS_H |
33 | #define ONETUTILS_H | 33 | #define ONETUTILS_H |
34 | 34 | ||
35 | #include <qdict.h> | 35 | #include <qdict.h> |
36 | #include <qmap.h> | 36 | #include <qmap.h> |
37 | #include <qstring.h> | 37 | #include <qstring.h> |
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 | 44 | ||
45 | namespace Opie { | 45 | namespace Opie { |
46 | namespace Net { | 46 | namespace Net { |
47 | 47 | ||
48 | class OWirelessNetworkInterface; | 48 | class OWirelessNetworkInterface; |
49 | 49 | ||
50 | /*====================================================================================== | 50 | /*====================================================================================== |
51 | * OMacAddress | 51 | * OMacAddress |
52 | *======================================================================================*/ | 52 | *======================================================================================*/ |
53 | 53 | ||
54 | class OMacAddress | 54 | class OMacAddress |
55 | { | 55 | { |
56 | public: | 56 | public: |
57 | // QString c'tor? -zecke | 57 | // QString c'tor? -zecke |
58 | OMacAddress(); | 58 | OMacAddress(); |
59 | OMacAddress( unsigned char* ); | 59 | OMacAddress( unsigned char* ); |
60 | OMacAddress( const unsigned char* ); | 60 | OMacAddress( const unsigned char* ); |
61 | OMacAddress( struct ifreq& ); | 61 | OMacAddress( struct ifreq& ); |
62 | ~OMacAddress(); | 62 | ~OMacAddress(); |
63 | 63 | ||
64 | QString manufacturer() const; | 64 | QString manufacturer() const; |
65 | QString toString( bool substitute = false ) const; | 65 | QString toString( bool substitute = false ) const; |
66 | const unsigned char* native() const; | 66 | const unsigned char* native() const; |
67 | 67 | ||
68 | // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem? | 68 | // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem? |
69 | static OMacAddress fromString( const QString& ); | 69 | static OMacAddress fromString( const QString& ); |
70 | 70 | ||
71 | public: | 71 | public: |
72 | static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff | 72 | static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff |
73 | static const OMacAddress& unknown; // 44:44:44:44:44:44 | 73 | static const OMacAddress& unknown; // 44:44:44:44:44:44 |
74 | 74 | ||
75 | private: | 75 | private: |
76 | unsigned char _bytes[6]; | 76 | unsigned char _bytes[6]; |
77 | 77 | ||
78 | friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); | 78 | friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); |
79 | class Private; | 79 | class Private; |
80 | Private *d; | 80 | Private *d; |
81 | 81 | ||
82 | }; | 82 | }; |
83 | 83 | ||
84 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); | 84 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); |
85 | 85 | ||
86 | 86 | ||
87 | /*====================================================================================== | 87 | /*====================================================================================== |
88 | * OHostAddress | 88 | * OHostAddress |
89 | *======================================================================================*/ | 89 | *======================================================================================*/ |
90 | 90 | ||
91 | class OHostAddress : public QHostAddress | 91 | class OHostAddress : public QHostAddress |
92 | { | 92 | { |
93 | /*public: | 93 | /*public: |
94 | OHostAddress(); | 94 | OHostAddress(); |
95 | ~OHostAddress(); | 95 | ~OHostAddress(); |
96 | */ | 96 | */ |
97 | private: | 97 | private: |
98 | class Private; | 98 | class Private; |
99 | Private *d; | 99 | Private *d; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | 102 | ||
103 | /*====================================================================================== | 103 | /*====================================================================================== |
104 | * OPrivateIOCTL | 104 | * OPrivateIOCTL |
105 | *======================================================================================*/ | 105 | *======================================================================================*/ |
106 | 106 | ||
107 | class OPrivateIOCTL : public QObject | 107 | class OPrivateIOCTL : public QObject |
108 | { | 108 | { |
109 | public: | 109 | public: |
110 | OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); | 110 | OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); |
111 | ~OPrivateIOCTL(); | 111 | ~OPrivateIOCTL(); |
112 | 112 | ||
113 | int numberGetArgs() const; | 113 | int numberGetArgs() const; |
114 | int typeGetArgs() const; | 114 | int typeGetArgs() const; |
115 | int numberSetArgs() const; | 115 | int numberSetArgs() const; |
116 | int typeSetArgs() const; | 116 | int typeSetArgs() const; |
117 | 117 | ||
118 | // FIXME return int? as ::ioctl does? -zecke | 118 | // FIXME return int? as ::ioctl does? -zecke |
119 | void invoke() const; | 119 | void invoke() const; |
120 | void setParameter( int, u_int32_t ); | 120 | void setParameter( int, u_int32_t ); |
121 | 121 | ||
122 | private: | 122 | private: |
123 | u_int32_t _ioctl; | 123 | u_int32_t _ioctl; |
124 | u_int16_t _getargs; | 124 | u_int16_t _getargs; |
125 | u_int16_t _setargs; | 125 | u_int16_t _setargs; |
126 | 126 | ||
127 | class Private; | 127 | class Private; |
128 | Private *d; | 128 | Private *d; |
129 | }; | 129 | }; |
130 | 130 | ||
131 | /*====================================================================================== | 131 | /*====================================================================================== |
132 | * Miscellaneous | 132 | * Miscellaneous |
133 | *======================================================================================*/ | 133 | *======================================================================================*/ |
134 | 134 | ||
135 | namespace Internal { | 135 | namespace Internal { |
136 | void dumpBytes( const unsigned char* data, int num ); | 136 | void dumpBytes( const unsigned char* data, int num ); |
137 | QString modeToString( int ); | 137 | QString modeToString( int ); |
138 | int stringToMode( const QString& ); | 138 | int stringToMode( const QString& ); |
139 | } | 139 | } |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | #define IW_PRIV_TYPE_MASK 0x7000 | 143 | #define IW_PRIV_TYPE_MASK 0x7000 |
144 | #define IW_PRIV_TYPE_NONE 0x0000 | 144 | #define IW_PRIV_TYPE_NONE 0x0000 |
145 | #define IW_PRIV_TYPE_BYTE 0x1000 | 145 | #define IW_PRIV_TYPE_BYTE 0x1000 |
146 | #define IW_PRIV_TYPE_CHAR 0x2000 | 146 | #define IW_PRIV_TYPE_CHAR 0x2000 |
147 | #define IW_PRIV_TYPE_INT 0x4000 | 147 | #define IW_PRIV_TYPE_INT 0x4000 |
148 | #define IW_PRIV_TYPE_FLOAT 0x5000 | 148 | #define IW_PRIV_TYPE_FLOAT 0x5000 |
149 | #define IW_PRIV_TYPE_ADDR 0x6000 | 149 | #define IW_PRIV_TYPE_ADDR 0x6000 |
150 | #define IW_PRIV_SIZE_FIXED 0x0800 | 150 | #define IW_PRIV_SIZE_FIXED 0x0800 |
151 | #define IW_PRIV_SIZE_MASK 0x07FF | 151 | #define IW_PRIV_SIZE_MASK 0x07FF |
152 | 152 | ||
153 | #ifndef ARPHRD_IEEE80211 | 153 | #ifndef ARPHRD_IEEE80211 |
154 | #define ARPHRD_IEEE80211 801 | 154 | #define ARPHRD_IEEE80211 801 |
155 | #endif | 155 | #endif |
156 | #ifndef ARPHRD_IEEE80211_PRISM | 156 | #ifndef ARPHRD_IEEE80211_PRISM |
157 | #define ARPHRD_IEEE80211_PRISM 802 | 157 | #define ARPHRD_IEEE80211_PRISM 802 |
158 | #endif | 158 | #endif |
159 | 159 | ||
160 | 160 | ||
161 | /* Network to host order macros */ | 161 | /* Network to host order macros */ |
162 | 162 | ||
163 | #ifdef LBL_ALIGN | 163 | #ifdef LBL_ALIGN |
164 | #define EXTRACT_16BITS(p) \ | 164 | #define EXTRACT_16BITS(p) \ |
165 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ | 165 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ |
166 | (u_int16_t)*((const u_int8_t *)(p) + 1))) | 166 | (u_int16_t)*((const u_int8_t *)(p) + 1))) |
167 | #define EXTRACT_32BITS(p) \ | 167 | #define EXTRACT_32BITS(p) \ |
168 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ | 168 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ |
169 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ | 169 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ |
170 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ | 170 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ |
171 | (u_int32_t)*((const u_int8_t *)(p) + 3))) | 171 | (u_int32_t)*((const u_int8_t *)(p) + 3))) |
172 | #else | 172 | #else |
173 | #define EXTRACT_16BITS(p) \ | 173 | #define EXTRACT_16BITS(p) \ |
174 | ((u_int16_t)ntohs(*(const u_int16_t *)(p))) | 174 | ((u_int16_t)ntohs(*(const u_int16_t *)(p))) |
175 | #define EXTRACT_32BITS(p) \ | 175 | #define EXTRACT_32BITS(p) \ |
176 | ((u_int32_t)ntohl(*(const u_int32_t *)(p))) | 176 | ((u_int32_t)ntohl(*(const u_int32_t *)(p))) |
177 | #endif | 177 | #endif |
178 | 178 | ||
179 | #define EXTRACT_24BITS(p) \ | 179 | #define EXTRACT_24BITS(p) \ |
180 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ | 180 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ |
181 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 181 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
182 | (u_int32_t)*((const u_int8_t *)(p) + 2))) | 182 | (u_int32_t)*((const u_int8_t *)(p) + 2))) |
183 | 183 | ||
184 | /* Little endian protocol host order macros */ | 184 | /* Little endian protocol host order macros */ |
185 | #define EXTRACT_LE_8BITS(p) (*(p)) | 185 | #define EXTRACT_LE_8BITS(p) (*(p)) |
186 | #define EXTRACT_LE_16BITS(p) \ | 186 | #define EXTRACT_LE_16BITS(p) \ |
187 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 187 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
188 | (u_int16_t)*((const u_int8_t *)(p) + 0))) | 188 | (u_int16_t)*((const u_int8_t *)(p) + 0))) |
189 | #define EXTRACT_LE_32BITS(p) \ | 189 | #define EXTRACT_LE_32BITS(p) \ |
190 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ | 190 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ |
191 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ | 191 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ |
192 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 192 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
193 | (u_int32_t)*((const u_int8_t *)(p) + 0))) | 193 | (u_int32_t)*((const u_int8_t *)(p) + 0))) |
194 | 194 | ||
195 | #endif // ONETUTILS_H | 195 | #endif // ONETUTILS_H |
196 | 196 | ||
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 591681c..ae1865d 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,780 +1,780 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer | 3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer |
4 | =. <mickey@Vanille.de> | 4 | =. <mickey@Vanille.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | 32 | ||
33 | #include <opie2/onetwork.h> | 33 | #include <opie2/onetwork.h> |
34 | #include <opie2/ostation.h> | 34 | #include <opie2/ostation.h> |
35 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | 38 | ||
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include <qtextstream.h> | 40 | #include <qtextstream.h> |
41 | 41 | ||
42 | /* UNIX */ | 42 | /* UNIX */ |
43 | 43 | ||
44 | #include <assert.h> | 44 | #include <assert.h> |
45 | #include <arpa/inet.h> | 45 | #include <arpa/inet.h> |
46 | #include <errno.h> | 46 | #include <errno.h> |
47 | #include <string.h> | 47 | #include <string.h> |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | #include <math.h> | 49 | #include <math.h> |
50 | #include <sys/ioctl.h> | 50 | #include <sys/ioctl.h> |
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #include <sys/types.h> | 52 | #include <sys/types.h> |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #include <linux/sockios.h> | 54 | #include <linux/sockios.h> |
55 | #include <net/if_arp.h> | 55 | #include <net/if_arp.h> |
56 | #include <stdarg.h> | 56 | #include <stdarg.h> |
57 | 57 | ||
58 | #ifndef NODEBUG | 58 | #ifndef NODEBUG |
59 | #include <opie2/odebugmapper.h> | 59 | #include <opie2/odebugmapper.h> |
60 | 60 | ||
61 | 61 | ||
62 | using namespace Opie::Core; | 62 | using namespace Opie::Core; |
63 | using namespace Opie::Net::Internal; | 63 | using namespace Opie::Net::Internal; |
64 | DebugMapper* debugmapper = new DebugMapper(); | 64 | DebugMapper* debugmapper = new DebugMapper(); |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | /*====================================================================================== | 67 | /*====================================================================================== |
68 | * ONetwork | 68 | * ONetwork |
69 | *======================================================================================*/ | 69 | *======================================================================================*/ |
70 | 70 | ||
71 | namespace Opie { | 71 | namespace Opie { |
72 | namespace Net { | 72 | namespace Net { |
73 | ONetwork* ONetwork::_instance = 0; | 73 | ONetwork* ONetwork::_instance = 0; |
74 | 74 | ||
75 | ONetwork::ONetwork() | 75 | ONetwork::ONetwork() |
76 | { | 76 | { |
77 | odebug << "ONetwork::ONetwork()" << oendl; | 77 | odebug << "ONetwork::ONetwork()" << oendl; |
78 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; | 78 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; |
79 | synchronize(); | 79 | synchronize(); |
80 | } | 80 | } |
81 | 81 | ||
82 | void ONetwork::synchronize() | 82 | void ONetwork::synchronize() |
83 | { | 83 | { |
84 | // gather available interfaces by inspecting /proc/net/dev | 84 | // gather available interfaces by inspecting /proc/net/dev |
85 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 85 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
86 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 86 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
87 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev | 87 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev |
88 | 88 | ||
89 | _interfaces.clear(); | 89 | _interfaces.clear(); |
90 | QString str; | 90 | QString str; |
91 | QFile f( "/proc/net/dev" ); | 91 | QFile f( "/proc/net/dev" ); |
92 | bool hasFile = f.open( IO_ReadOnly ); | 92 | bool hasFile = f.open( IO_ReadOnly ); |
93 | if ( !hasFile ) | 93 | if ( !hasFile ) |
94 | { | 94 | { |
95 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; | 95 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; |
96 | return; | 96 | return; |
97 | } | 97 | } |
98 | QTextStream s( &f ); | 98 | QTextStream s( &f ); |
99 | s.readLine(); | 99 | s.readLine(); |
100 | s.readLine(); | 100 | s.readLine(); |
101 | while ( !s.atEnd() ) | 101 | while ( !s.atEnd() ) |
102 | { | 102 | { |
103 | s >> str; | 103 | s >> str; |
104 | str.truncate( str.find( ':' ) ); | 104 | str.truncate( str.find( ':' ) ); |
105 | odebug << "ONetwork: found interface '" << str << "'" << oendl; | 105 | odebug << "ONetwork: found interface '" << str << "'" << oendl; |
106 | ONetworkInterface* iface = 0; | 106 | ONetworkInterface* iface = 0; |
107 | if ( isWirelessInterface( str ) ) | 107 | if ( isWirelessInterface( str ) ) |
108 | { | 108 | { |
109 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 109 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
110 | odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; | 110 | odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; |
111 | } | 111 | } |
112 | else | 112 | else |
113 | { | 113 | { |
114 | iface = new ONetworkInterface( this, (const char*) str ); | 114 | iface = new ONetworkInterface( this, (const char*) str ); |
115 | } | 115 | } |
116 | _interfaces.insert( str, iface ); | 116 | _interfaces.insert( str, iface ); |
117 | s.readLine(); | 117 | s.readLine(); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | short ONetwork::wirelessExtensionCompileVersion() | 122 | short ONetwork::wirelessExtensionCompileVersion() |
123 | { | 123 | { |
124 | return WIRELESS_EXT; | 124 | return WIRELESS_EXT; |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | int ONetwork::count() const | 128 | int ONetwork::count() const |
129 | { | 129 | { |
130 | return _interfaces.count(); | 130 | return _interfaces.count(); |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 134 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
135 | { | 135 | { |
136 | return _interfaces[iface]; | 136 | return _interfaces[iface]; |
137 | } | 137 | } |
138 | 138 | ||
139 | 139 | ||
140 | ONetwork* ONetwork::instance() | 140 | ONetwork* ONetwork::instance() |
141 | { | 141 | { |
142 | if ( !_instance ) _instance = new ONetwork(); | 142 | if ( !_instance ) _instance = new ONetwork(); |
143 | return _instance; | 143 | return _instance; |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | ONetwork::InterfaceIterator ONetwork::iterator() const | 147 | ONetwork::InterfaceIterator ONetwork::iterator() const |
148 | { | 148 | { |
149 | return ONetwork::InterfaceIterator( _interfaces ); | 149 | return ONetwork::InterfaceIterator( _interfaces ); |
150 | } | 150 | } |
151 | 151 | ||
152 | 152 | ||
153 | bool ONetwork::isPresent( const char* name ) const | 153 | bool ONetwork::isPresent( const char* name ) const |
154 | { | 154 | { |
155 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 155 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
156 | struct ifreq ifr; | 156 | struct ifreq ifr; |
157 | memset( &ifr, 0, sizeof( struct ifreq ) ); | 157 | memset( &ifr, 0, sizeof( struct ifreq ) ); |
158 | strcpy( (char*) &ifr.ifr_name, name ); | 158 | strcpy( (char*) &ifr.ifr_name, name ); |
159 | int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr ); | 159 | int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr ); |
160 | return result != -1; | 160 | return result != -1; |
161 | } | 161 | } |
162 | 162 | ||
163 | 163 | ||
164 | bool ONetwork::isWirelessInterface( const char* name ) const | 164 | bool ONetwork::isWirelessInterface( const char* name ) const |
165 | { | 165 | { |
166 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 166 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
167 | struct iwreq iwr; | 167 | struct iwreq iwr; |
168 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 168 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
169 | strcpy( (char*) &iwr.ifr_name, name ); | 169 | strcpy( (char*) &iwr.ifr_name, name ); |
170 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 170 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
171 | return result != -1; | 171 | return result != -1; |
172 | } | 172 | } |
173 | 173 | ||
174 | /*====================================================================================== | 174 | /*====================================================================================== |
175 | * ONetworkInterface | 175 | * ONetworkInterface |
176 | *======================================================================================*/ | 176 | *======================================================================================*/ |
177 | 177 | ||
178 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 178 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
179 | :QObject( parent, name ), | 179 | :QObject( parent, name ), |
180 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 180 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
181 | { | 181 | { |
182 | odebug << "ONetworkInterface::ONetworkInterface()" << oendl; | 182 | odebug << "ONetworkInterface::ONetworkInterface()" << oendl; |
183 | init(); | 183 | init(); |
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | struct ifreq& ONetworkInterface::ifr() const | 187 | struct ifreq& ONetworkInterface::ifr() const |
188 | { | 188 | { |
189 | return _ifr; | 189 | return _ifr; |
190 | } | 190 | } |
191 | 191 | ||
192 | 192 | ||
193 | void ONetworkInterface::init() | 193 | void ONetworkInterface::init() |
194 | { | 194 | { |
195 | odebug << "ONetworkInterface::init()" << oendl; | 195 | odebug << "ONetworkInterface::init()" << oendl; |
196 | 196 | ||
197 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 197 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
198 | 198 | ||
199 | if ( _sfd == -1 ) | 199 | if ( _sfd == -1 ) |
200 | { | 200 | { |
201 | odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; | 201 | odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; |
202 | return; | 202 | return; |
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
207 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 207 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
208 | { | 208 | { |
209 | #ifndef NODEBUG | 209 | #ifndef NODEBUG |
210 | int result = ::ioctl( _sfd, call, &ifreq ); | 210 | int result = ::ioctl( _sfd, call, &ifreq ); |
211 | if ( result == -1 ) | 211 | if ( result == -1 ) |
212 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) | 212 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) |
213 | << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | 213 | << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
214 | else | 214 | else |
215 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) | 215 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) |
216 | << "' - Status: Ok." << oendl; | 216 | << "' - Status: Ok." << oendl; |
217 | return ( result != -1 ); | 217 | return ( result != -1 ); |
218 | #else | 218 | #else |
219 | return ::ioctl( _sfd, call, &ifreq ) != -1; | 219 | return ::ioctl( _sfd, call, &ifreq ) != -1; |
220 | #endif | 220 | #endif |
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | bool ONetworkInterface::ioctl( int call ) const | 224 | bool ONetworkInterface::ioctl( int call ) const |
225 | { | 225 | { |
226 | strcpy( _ifr.ifr_name, name() ); | 226 | strcpy( _ifr.ifr_name, name() ); |
227 | return ioctl( call, _ifr ); | 227 | return ioctl( call, _ifr ); |
228 | } | 228 | } |
229 | 229 | ||
230 | 230 | ||
231 | bool ONetworkInterface::isLoopback() const | 231 | bool ONetworkInterface::isLoopback() const |
232 | { | 232 | { |
233 | ioctl( SIOCGIFFLAGS ); | 233 | ioctl( SIOCGIFFLAGS ); |
234 | return _ifr.ifr_flags & IFF_LOOPBACK; | 234 | return _ifr.ifr_flags & IFF_LOOPBACK; |
235 | } | 235 | } |
236 | 236 | ||
237 | 237 | ||
238 | bool ONetworkInterface::setUp( bool b ) | 238 | bool ONetworkInterface::setUp( bool b ) |
239 | { | 239 | { |
240 | ioctl( SIOCGIFFLAGS ); | 240 | ioctl( SIOCGIFFLAGS ); |
241 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 241 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
242 | else _ifr.ifr_flags &= (~IFF_UP); | 242 | else _ifr.ifr_flags &= (~IFF_UP); |
243 | return ioctl( SIOCSIFFLAGS ); | 243 | return ioctl( SIOCSIFFLAGS ); |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | bool ONetworkInterface::isUp() const | 247 | bool ONetworkInterface::isUp() const |
248 | { | 248 | { |
249 | ioctl( SIOCGIFFLAGS ); | 249 | ioctl( SIOCGIFFLAGS ); |
250 | return _ifr.ifr_flags & IFF_UP; | 250 | return _ifr.ifr_flags & IFF_UP; |
251 | } | 251 | } |
252 | 252 | ||
253 | 253 | ||
254 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | 254 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) |
255 | { | 255 | { |
256 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 256 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
257 | sa->sin_family = AF_INET; | 257 | sa->sin_family = AF_INET; |
258 | sa->sin_port = 0; | 258 | sa->sin_port = 0; |
259 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 259 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
260 | ioctl( SIOCSIFADDR ); | 260 | ioctl( SIOCSIFADDR ); |
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | QString ONetworkInterface::ipV4Address() const | 264 | QString ONetworkInterface::ipV4Address() const |
265 | { | 265 | { |
266 | if ( ioctl( SIOCGIFADDR ) ) | 266 | if ( ioctl( SIOCGIFADDR ) ) |
267 | { | 267 | { |
268 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 268 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
269 | //FIXME: Use QHostAddress here | 269 | //FIXME: Use QHostAddress here |
270 | return QString( inet_ntoa( sa->sin_addr ) ); | 270 | return QString( inet_ntoa( sa->sin_addr ) ); |
271 | } | 271 | } |
272 | else | 272 | else |
273 | return "<unknown>"; | 273 | return "<unknown>"; |
274 | 274 | ||
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 278 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
279 | { | 279 | { |
280 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 280 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
281 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | 281 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); |
282 | ioctl( SIOCSIFHWADDR ); | 282 | ioctl( SIOCSIFHWADDR ); |
283 | } | 283 | } |
284 | 284 | ||
285 | 285 | ||
286 | OMacAddress ONetworkInterface::macAddress() const | 286 | OMacAddress ONetworkInterface::macAddress() const |
287 | { | 287 | { |
288 | if ( ioctl( SIOCGIFHWADDR ) ) | 288 | if ( ioctl( SIOCGIFHWADDR ) ) |
289 | { | 289 | { |
290 | return OMacAddress( _ifr ); | 290 | return OMacAddress( _ifr ); |
291 | } | 291 | } |
292 | else | 292 | else |
293 | { | 293 | { |
294 | return OMacAddress::unknown; | 294 | return OMacAddress::unknown; |
295 | } | 295 | } |
296 | } | 296 | } |
297 | 297 | ||
298 | 298 | ||
299 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | 299 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) |
300 | { | 300 | { |
301 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 301 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
302 | sa->sin_family = AF_INET; | 302 | sa->sin_family = AF_INET; |
303 | sa->sin_port = 0; | 303 | sa->sin_port = 0; |
304 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 304 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
305 | ioctl( SIOCSIFNETMASK ); | 305 | ioctl( SIOCSIFNETMASK ); |
306 | } | 306 | } |
307 | 307 | ||
308 | 308 | ||
309 | QString ONetworkInterface::ipV4Netmask() const | 309 | QString ONetworkInterface::ipV4Netmask() const |
310 | { | 310 | { |
311 | if ( ioctl( SIOCGIFNETMASK ) ) | 311 | if ( ioctl( SIOCGIFNETMASK ) ) |
312 | { | 312 | { |
313 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 313 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
314 | //FIXME: Use QHostAddress here | 314 | //FIXME: Use QHostAddress here |
315 | return QString( inet_ntoa( sa->sin_addr ) ); | 315 | return QString( inet_ntoa( sa->sin_addr ) ); |
316 | } | 316 | } |
317 | else | 317 | else |
318 | return "<unknown>"; | 318 | return "<unknown>"; |
319 | } | 319 | } |
320 | 320 | ||
321 | 321 | ||
322 | int ONetworkInterface::dataLinkType() const | 322 | int ONetworkInterface::dataLinkType() const |
323 | { | 323 | { |
324 | if ( ioctl( SIOCGIFHWADDR ) ) | 324 | if ( ioctl( SIOCGIFHWADDR ) ) |
325 | { | 325 | { |
326 | return _ifr.ifr_hwaddr.sa_family; | 326 | return _ifr.ifr_hwaddr.sa_family; |
327 | } | 327 | } |
328 | else | 328 | else |
329 | { | 329 | { |
330 | return -1; | 330 | return -1; |
331 | } | 331 | } |
332 | } | 332 | } |
333 | 333 | ||
334 | 334 | ||
335 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 335 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
336 | { | 336 | { |
337 | _mon = m; | 337 | _mon = m; |
338 | odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl; | 338 | odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl; |
339 | } | 339 | } |
340 | 340 | ||
341 | 341 | ||
342 | OMonitoringInterface* ONetworkInterface::monitoring() const | 342 | OMonitoringInterface* ONetworkInterface::monitoring() const |
343 | { | 343 | { |
344 | return _mon; | 344 | return _mon; |
345 | } | 345 | } |
346 | 346 | ||
347 | 347 | ||
348 | ONetworkInterface::~ONetworkInterface() | 348 | ONetworkInterface::~ONetworkInterface() |
349 | { | 349 | { |
350 | odebug << "ONetworkInterface::~ONetworkInterface()" << oendl; | 350 | odebug << "ONetworkInterface::~ONetworkInterface()" << oendl; |
351 | if ( _sfd != -1 ) ::close( _sfd ); | 351 | if ( _sfd != -1 ) ::close( _sfd ); |
352 | } | 352 | } |
353 | 353 | ||
354 | 354 | ||
355 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 355 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
356 | { | 356 | { |
357 | ioctl( SIOCGIFFLAGS ); | 357 | ioctl( SIOCGIFFLAGS ); |
358 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 358 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
359 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 359 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
360 | return ioctl( SIOCSIFFLAGS ); | 360 | return ioctl( SIOCSIFFLAGS ); |
361 | } | 361 | } |
362 | 362 | ||
363 | 363 | ||
364 | bool ONetworkInterface::promiscuousMode() const | 364 | bool ONetworkInterface::promiscuousMode() const |
365 | { | 365 | { |
366 | ioctl( SIOCGIFFLAGS ); | 366 | ioctl( SIOCGIFFLAGS ); |
367 | return _ifr.ifr_flags & IFF_PROMISC; | 367 | return _ifr.ifr_flags & IFF_PROMISC; |
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
371 | bool ONetworkInterface::isWireless() const | 371 | bool ONetworkInterface::isWireless() const |
372 | { | 372 | { |
373 | return ioctl( SIOCGIWNAME ); | 373 | return ioctl( SIOCGIWNAME ); |
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
377 | /*====================================================================================== | 377 | /*====================================================================================== |
378 | * OChannelHopper | 378 | * OChannelHopper |
379 | *======================================================================================*/ | 379 | *======================================================================================*/ |
380 | 380 | ||
381 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 381 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
382 | :QObject( 0, "Mickey's funky hopper" ), | 382 | :QObject( 0, "Mickey's funky hopper" ), |
383 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 383 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
384 | { | 384 | { |
385 | int _maxChannel = iface->channels(); | 385 | int _maxChannel = iface->channels(); |
386 | // generate fancy hopping sequence honoring the device capabilities | 386 | // generate fancy hopping sequence honoring the device capabilities |
387 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 387 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
388 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 388 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
389 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 389 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
390 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 390 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
391 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 391 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
392 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 392 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
393 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 393 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
394 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 394 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
395 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 395 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
396 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 396 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
397 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 397 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
398 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 398 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
399 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 399 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
400 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 400 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
401 | _channel = _channels.begin(); | 401 | _channel = _channels.begin(); |
402 | } | 402 | } |
403 | 403 | ||
404 | 404 | ||
405 | OChannelHopper::~OChannelHopper() | 405 | OChannelHopper::~OChannelHopper() |
406 | { | 406 | { |
407 | } | 407 | } |
408 | 408 | ||
409 | 409 | ||
410 | bool OChannelHopper::isActive() const | 410 | bool OChannelHopper::isActive() const |
411 | { | 411 | { |
412 | return _tid; | 412 | return _tid; |
413 | } | 413 | } |
414 | 414 | ||
415 | 415 | ||
416 | int OChannelHopper::channel() const | 416 | int OChannelHopper::channel() const |
417 | { | 417 | { |
418 | return *_channel; | 418 | return *_channel; |
419 | } | 419 | } |
420 | 420 | ||
421 | 421 | ||
422 | void OChannelHopper::timerEvent( QTimerEvent* ) | 422 | void OChannelHopper::timerEvent( QTimerEvent* ) |
423 | { | 423 | { |
424 | _iface->setChannel( *_channel ); | 424 | _iface->setChannel( *_channel ); |
425 | emit( hopped( *_channel ) ); | 425 | emit( hopped( *_channel ) ); |
426 | odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; | 426 | odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; |
427 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 427 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
428 | } | 428 | } |
429 | 429 | ||
430 | 430 | ||
431 | void OChannelHopper::setInterval( int interval ) | 431 | void OChannelHopper::setInterval( int interval ) |
432 | { | 432 | { |
433 | if ( interval == _interval ) | 433 | if ( interval == _interval ) |
434 | return; | 434 | return; |
435 | 435 | ||
436 | if ( _interval ) | 436 | if ( _interval ) |
437 | killTimer( _tid ); | 437 | killTimer( _tid ); |
438 | 438 | ||
439 | _tid = 0; | 439 | _tid = 0; |
440 | _interval = interval; | 440 | _interval = interval; |
441 | 441 | ||
442 | if ( _interval ) | 442 | if ( _interval ) |
443 | { | 443 | { |
444 | _tid = startTimer( interval ); | 444 | _tid = startTimer( interval ); |
445 | } | 445 | } |
446 | } | 446 | } |
447 | 447 | ||
448 | 448 | ||
449 | int OChannelHopper::interval() const | 449 | int OChannelHopper::interval() const |
450 | { | 450 | { |
451 | return _interval; | 451 | return _interval; |
452 | } | 452 | } |
453 | 453 | ||
454 | 454 | ||
455 | /*====================================================================================== | 455 | /*====================================================================================== |
456 | * OWirelessNetworkInterface | 456 | * OWirelessNetworkInterface |
457 | *======================================================================================*/ | 457 | *======================================================================================*/ |
458 | 458 | ||
459 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 459 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
460 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 460 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
461 | { | 461 | { |
462 | odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; | 462 | odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; |
463 | init(); | 463 | init(); |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 467 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
468 | { | 468 | { |
469 | } | 469 | } |
470 | 470 | ||
471 | 471 | ||
472 | struct iwreq& OWirelessNetworkInterface::iwr() const | 472 | struct iwreq& OWirelessNetworkInterface::iwr() const |
473 | { | 473 | { |
474 | return _iwr; | 474 | return _iwr; |
475 | } | 475 | } |
476 | 476 | ||
477 | 477 | ||
478 | void OWirelessNetworkInterface::init() | 478 | void OWirelessNetworkInterface::init() |
479 | { | 479 | { |
480 | odebug << "OWirelessNetworkInterface::init()" << oendl; | 480 | odebug << "OWirelessNetworkInterface::init()" << oendl; |
481 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 481 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
482 | buildInformation(); | 482 | buildInformation(); |
483 | buildPrivateList(); | 483 | buildPrivateList(); |
484 | dumpInformation(); | 484 | dumpInformation(); |
485 | } | 485 | } |
486 | 486 | ||
487 | 487 | ||
488 | bool OWirelessNetworkInterface::isAssociated() const | 488 | bool OWirelessNetworkInterface::isAssociated() const |
489 | { | 489 | { |
490 | //FIXME: handle different modes | 490 | //FIXME: handle different modes |
491 | return !(associatedAP() == OMacAddress::unknown); | 491 | return !(associatedAP() == OMacAddress::unknown); |
492 | } | 492 | } |
493 | 493 | ||
494 | 494 | ||
495 | OMacAddress OWirelessNetworkInterface::associatedAP() const | 495 | OMacAddress OWirelessNetworkInterface::associatedAP() const |
496 | { | 496 | { |
497 | if ( ioctl( SIOCGIWAP ) ) | 497 | if ( ioctl( SIOCGIWAP ) ) |
498 | return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; | 498 | return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; |
499 | else | 499 | else |
500 | return OMacAddress::unknown; | 500 | return OMacAddress::unknown; |
501 | } | 501 | } |
502 | 502 | ||
503 | 503 | ||
504 | void OWirelessNetworkInterface::buildInformation() | 504 | void OWirelessNetworkInterface::buildInformation() |
505 | { | 505 | { |
506 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 506 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
507 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 507 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
508 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 508 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
509 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 509 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
510 | //ML: _too much_ space. This is damn shitty crap *sigh* | 510 | //ML: _too much_ space. This is damn shitty crap *sigh* |
511 | //ML: We allocate a large memory region in RAM and check whether the | 511 | //ML: We allocate a large memory region in RAM and check whether the |
512 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | 512 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
513 | //ML: so please forward this... | 513 | //ML: so please forward this... |
514 | 514 | ||
515 | struct iwreq wrq; | 515 | struct iwreq wrq; |
516 | int len = sizeof( struct iw_range )*2; | 516 | int len = sizeof( struct iw_range )*2; |
517 | char *buffer = (char*) malloc( len ); | 517 | char *buffer = (char*) malloc( len ); |
518 | //FIXME: Validate if we actually got the memory block | 518 | //FIXME: Validate if we actually got the memory block |
519 | memset( buffer, 0, len ); | 519 | memset( buffer, 0, len ); |
520 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 520 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
521 | wrq.u.data.pointer = (caddr_t) buffer; | 521 | wrq.u.data.pointer = (caddr_t) buffer; |
522 | wrq.u.data.length = sizeof( struct iw_range ); | 522 | wrq.u.data.length = sizeof( struct iw_range ); |
523 | wrq.u.data.flags = 0; | 523 | wrq.u.data.flags = 0; |
524 | 524 | ||
525 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 525 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
526 | { | 526 | { |
527 | owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; | 527 | owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; |
528 | _channels.insert( 2412, 1 ); // 2.412 GHz | 528 | _channels.insert( 2412, 1 ); // 2.412 GHz |
529 | _channels.insert( 2417, 2 ); // 2.417 GHz | 529 | _channels.insert( 2417, 2 ); // 2.417 GHz |
530 | _channels.insert( 2422, 3 ); // 2.422 GHz | 530 | _channels.insert( 2422, 3 ); // 2.422 GHz |
531 | _channels.insert( 2427, 4 ); // 2.427 GHz | 531 | _channels.insert( 2427, 4 ); // 2.427 GHz |
532 | _channels.insert( 2432, 5 ); // 2.432 GHz | 532 | _channels.insert( 2432, 5 ); // 2.432 GHz |
533 | _channels.insert( 2437, 6 ); // 2.437 GHz | 533 | _channels.insert( 2437, 6 ); // 2.437 GHz |
534 | _channels.insert( 2442, 7 ); // 2.442 GHz | 534 | _channels.insert( 2442, 7 ); // 2.442 GHz |
535 | _channels.insert( 2447, 8 ); // 2.447 GHz | 535 | _channels.insert( 2447, 8 ); // 2.447 GHz |
536 | _channels.insert( 2452, 9 ); // 2.452 GHz | 536 | _channels.insert( 2452, 9 ); // 2.452 GHz |
537 | _channels.insert( 2457, 10 ); // 2.457 GHz | 537 | _channels.insert( 2457, 10 ); // 2.457 GHz |
538 | _channels.insert( 2462, 11 ); // 2.462 GHz | 538 | _channels.insert( 2462, 11 ); // 2.462 GHz |
539 | 539 | ||
540 | memset( &_range, 0, sizeof( struct iw_range ) ); | 540 | memset( &_range, 0, sizeof( struct iw_range ) ); |
541 | } | 541 | } |
542 | else | 542 | else |
543 | { | 543 | { |
544 | // <check if the driver overwrites stuff> | 544 | // <check if the driver overwrites stuff> |
545 | int max = 0; | 545 | int max = 0; |
546 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 546 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
547 | if (buffer[r] != 0) | 547 | if (buffer[r] != 0) |
548 | max = r; | 548 | max = r; |
549 | if (max > 0) | 549 | if (max > 0) |
550 | { | 550 | { |
551 | owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() | 551 | owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() |
552 | << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; | 552 | << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; |
553 | } | 553 | } |
554 | // </check if the driver overwrites stuff> | 554 | // </check if the driver overwrites stuff> |
555 | 555 | ||
556 | struct iw_range range; | 556 | struct iw_range range; |
557 | memcpy( &range, buffer, sizeof range ); | 557 | memcpy( &range, buffer, sizeof range ); |
558 | 558 | ||
559 | odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; | 559 | odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; |
560 | for ( int i = 0; i < range.num_frequency; ++i ) | 560 | for ( int i = 0; i < range.num_frequency; ++i ) |
561 | { | 561 | { |
562 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 562 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
563 | odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl; | 563 | odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl; |
564 | _channels.insert( freq, i+1 ); | 564 | _channels.insert( freq, i+1 ); |
565 | } | 565 | } |
566 | } | 566 | } |
567 | 567 | ||
568 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); | 568 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); |
569 | odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; | 569 | odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; |
570 | free(buffer); | 570 | free(buffer); |
571 | } | 571 | } |
572 | 572 | ||
573 | 573 | ||
574 | short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const | 574 | short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const |
575 | { | 575 | { |
576 | return _range.we_version_compiled; | 576 | return _range.we_version_compiled; |
577 | } | 577 | } |
578 | 578 | ||
579 | 579 | ||
580 | void OWirelessNetworkInterface::buildPrivateList() | 580 | void OWirelessNetworkInterface::buildPrivateList() |
581 | { | 581 | { |
582 | odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; | 582 | odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; |
583 | 583 | ||
584 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 584 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
585 | 585 | ||
586 | _iwr.u.data.pointer = (char*) &priv; | 586 | _iwr.u.data.pointer = (char*) &priv; |
587 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 587 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself |
588 | _iwr.u.data.flags = 0; | 588 | _iwr.u.data.flags = 0; |
589 | 589 | ||
590 | if ( !wioctl( SIOCGIWPRIV ) ) | 590 | if ( !wioctl( SIOCGIWPRIV ) ) |
591 | { | 591 | { |
592 | owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; | 592 | owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; |
593 | return; | 593 | return; |
594 | } | 594 | } |
595 | 595 | ||
596 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 596 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
597 | { | 597 | { |
598 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 598 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
599 | } | 599 | } |
600 | odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; | 600 | odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; |
601 | } | 601 | } |
602 | 602 | ||
603 | 603 | ||
604 | void OWirelessNetworkInterface::dumpInformation() const | 604 | void OWirelessNetworkInterface::dumpInformation() const |
605 | { | 605 | { |
606 | odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; | 606 | odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; |
607 | 607 | ||
608 | odebug << " - driver's idea of maximum throughput is " << _range.throughput | 608 | odebug << " - driver's idea of maximum throughput is " << _range.throughput |
609 | << " bps = " << ( _range.throughput / 8 ) << " byte/s = " << ( _range.throughput / 8 / 1024 ) | 609 | << " bps = " << ( _range.throughput / 8 ) << " byte/s = " << ( _range.throughput / 8 / 1024 ) |
610 | << " Kb/s = " << QString().sprintf("%f.2", float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ) | 610 | << " Kb/s = " << QString().sprintf("%f.2", float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ) |
611 | << " Mb/s" << oendl; | 611 | << " Mb/s" << oendl; |
612 | 612 | ||
613 | odebug << " - driver for '" << name() << "' (V" << _range.we_version_source | 613 | odebug << " - driver for '" << name() << "' (V" << _range.we_version_source |
614 | << ") has been compiled against WE V" << _range.we_version_compiled << oendl; | 614 | << ") has been compiled against WE V" << _range.we_version_compiled << oendl; |
615 | 615 | ||
616 | if ( _range.we_version_compiled != WIRELESS_EXT ) | 616 | if ( _range.we_version_compiled != WIRELESS_EXT ) |
617 | { | 617 | { |
618 | owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; | 618 | owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; |
619 | } | 619 | } |
620 | 620 | ||
621 | odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; | 621 | odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; |
622 | } | 622 | } |
623 | 623 | ||
624 | 624 | ||
625 | int OWirelessNetworkInterface::channel() const | 625 | int OWirelessNetworkInterface::channel() const |
626 | { | 626 | { |
627 | //FIXME: When monitoring enabled, then use it | 627 | //FIXME: When monitoring enabled, then use it |
628 | //FIXME: to gather the current RF channel | 628 | //FIXME: to gather the current RF channel |
629 | //FIXME: Until then, get active channel from hopper. | 629 | //FIXME: Until then, get active channel from hopper. |
630 | if ( _hopper && _hopper->isActive() ) | 630 | if ( _hopper && _hopper->isActive() ) |
631 | return _hopper->channel(); | 631 | return _hopper->channel(); |
632 | 632 | ||
633 | if ( !wioctl( SIOCGIWFREQ ) ) | 633 | if ( !wioctl( SIOCGIWFREQ ) ) |
634 | { | 634 | { |
635 | return -1; | 635 | return -1; |
636 | } | 636 | } |
637 | else | 637 | else |
638 | { | 638 | { |
639 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 639 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
640 | } | 640 | } |
641 | } | 641 | } |
642 | 642 | ||
643 | 643 | ||
644 | void OWirelessNetworkInterface::setChannel( int c ) const | 644 | void OWirelessNetworkInterface::setChannel( int c ) const |
645 | { | 645 | { |
646 | if ( !c ) | 646 | if ( !c ) |
647 | { | 647 | { |
648 | oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; | 648 | oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; |
649 | return; | 649 | return; |
650 | } | 650 | } |
651 | 651 | ||
652 | if ( !_mon ) | 652 | if ( !_mon ) |
653 | { | 653 | { |
654 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 654 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
655 | _iwr.u.freq.m = c; | 655 | _iwr.u.freq.m = c; |
656 | _iwr.u.freq.e = 0; | 656 | _iwr.u.freq.e = 0; |
657 | wioctl( SIOCSIWFREQ ); | 657 | wioctl( SIOCSIWFREQ ); |
658 | } | 658 | } |
659 | else | 659 | else |
660 | { | 660 | { |
661 | _mon->setChannel( c ); | 661 | _mon->setChannel( c ); |
662 | } | 662 | } |
663 | } | 663 | } |
664 | 664 | ||
665 | 665 | ||
666 | double OWirelessNetworkInterface::frequency() const | 666 | double OWirelessNetworkInterface::frequency() const |
667 | { | 667 | { |
668 | if ( !wioctl( SIOCGIWFREQ ) ) | 668 | if ( !wioctl( SIOCGIWFREQ ) ) |
669 | { | 669 | { |
670 | return -1.0; | 670 | return -1.0; |
671 | } | 671 | } |
672 | else | 672 | else |
673 | { | 673 | { |
674 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 674 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
675 | } | 675 | } |
676 | } | 676 | } |
677 | 677 | ||
678 | 678 | ||
679 | int OWirelessNetworkInterface::channels() const | 679 | int OWirelessNetworkInterface::channels() const |
680 | { | 680 | { |
681 | return _channels.count(); | 681 | return _channels.count(); |
682 | } | 682 | } |
683 | 683 | ||
684 | 684 | ||
685 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 685 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
686 | { | 686 | { |
687 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 687 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
688 | _hopper->setInterval( interval ); | 688 | _hopper->setInterval( interval ); |
689 | //FIXME: When and by whom will the channel hopper be deleted? | 689 | //FIXME: When and by whom will the channel hopper be deleted? |
690 | //TODO: rely on QObject hierarchy | 690 | //TODO: rely on QObject hierarchy |
691 | } | 691 | } |
692 | 692 | ||
693 | 693 | ||
694 | int OWirelessNetworkInterface::channelHopping() const | 694 | int OWirelessNetworkInterface::channelHopping() const |
695 | { | 695 | { |
696 | return _hopper->interval(); | 696 | return _hopper->interval(); |
697 | } | 697 | } |
698 | 698 | ||
699 | 699 | ||
700 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 700 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
701 | { | 701 | { |
702 | return _hopper; | 702 | return _hopper; |
703 | } | 703 | } |
704 | 704 | ||
705 | 705 | ||
706 | void OWirelessNetworkInterface::commit() const | 706 | void OWirelessNetworkInterface::commit() const |
707 | { | 707 | { |
708 | wioctl( SIOCSIWCOMMIT ); | 708 | wioctl( SIOCSIWCOMMIT ); |
709 | } | 709 | } |
710 | 710 | ||
711 | 711 | ||
712 | void OWirelessNetworkInterface::setMode( const QString& newMode ) | 712 | void OWirelessNetworkInterface::setMode( const QString& newMode ) |
713 | { | 713 | { |
714 | #ifdef FINALIZE | 714 | #ifdef FINALIZE |
715 | QString currentMode = mode(); | 715 | QString currentMode = mode(); |
716 | if ( currentMode == newMode ) return; | 716 | if ( currentMode == newMode ) return; |
717 | #endif | 717 | #endif |
718 | 718 | ||
719 | odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; | 719 | odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; |
720 | 720 | ||
721 | _iwr.u.mode = stringToMode( newMode ); | 721 | _iwr.u.mode = stringToMode( newMode ); |
722 | 722 | ||
723 | if ( _iwr.u.mode != IW_MODE_MONITOR ) | 723 | if ( _iwr.u.mode != IW_MODE_MONITOR ) |
724 | { | 724 | { |
725 | // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! | 725 | // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! |
726 | _iwr.u.mode = stringToMode( newMode ); | 726 | _iwr.u.mode = stringToMode( newMode ); |
727 | wioctl( SIOCSIWMODE ); | 727 | wioctl( SIOCSIWMODE ); |
728 | 728 | ||
729 | // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) | 729 | // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) |
730 | 730 | ||
731 | if ( mode() == "monitor" ) | 731 | if ( mode() == "monitor" ) |
732 | { | 732 | { |
733 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; | 733 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; |
734 | if ( _mon ) | 734 | if ( _mon ) |
735 | _mon->setEnabled( false ); | 735 | _mon->setEnabled( false ); |
736 | else | 736 | else |
737 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; | 737 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; |
738 | } | 738 | } |
739 | 739 | ||
740 | } | 740 | } |
741 | else // special iwpriv fallback for monitor mode | 741 | else // special iwpriv fallback for monitor mode |
742 | { | 742 | { |
743 | if ( wioctl( SIOCSIWMODE ) ) | 743 | if ( wioctl( SIOCSIWMODE ) ) |
744 | { | 744 | { |
745 | odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; | 745 | odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; |
746 | } | 746 | } |
747 | else | 747 | else |
748 | { | 748 | { |
749 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; | 749 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; |
750 | 750 | ||
751 | if ( _mon ) | 751 | if ( _mon ) |
752 | _mon->setEnabled( true ); | 752 | _mon->setEnabled( true ); |
753 | else | 753 | else |
754 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; | 754 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; |
755 | } | 755 | } |
756 | } | 756 | } |
757 | } | 757 | } |
758 | 758 | ||
759 | 759 | ||
760 | QString OWirelessNetworkInterface::mode() const | 760 | QString OWirelessNetworkInterface::mode() const |
761 | { | 761 | { |
762 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 762 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
763 | 763 | ||
764 | if ( !wioctl( SIOCGIWMODE ) ) | 764 | if ( !wioctl( SIOCGIWMODE ) ) |
765 | { | 765 | { |
766 | return "<unknown>"; | 766 | return "<unknown>"; |
767 | } | 767 | } |
768 | 768 | ||
769 | odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; | 769 | odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; |
770 | 770 | ||
771 | // legacy compatible monitor mode check | 771 | // legacy compatible monitor mode check |
772 | 772 | ||
773 | if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) | 773 | if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) |
774 | { | 774 | { |
775 | return "monitor"; | 775 | return "monitor"; |
776 | } | 776 | } |
777 | else | 777 | else |
778 | { | 778 | { |
779 | return modeToString( _iwr.u.mode ); | 779 | return modeToString( _iwr.u.mode ); |
780 | } | 780 | } |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 057b1a0..be4bb46 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -1,588 +1,588 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer | 3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer |
4 | =. <mickey@Vanille.de> | 4 | =. <mickey@Vanille.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef ONETWORK_H | 31 | #ifndef ONETWORK_H |
32 | #define ONETWORK_H | 32 | #define ONETWORK_H |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/onetutils.h> | 35 | #include <opie2/onetutils.h> |
36 | #include <opie2/ostation.h> | 36 | #include <opie2/ostation.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | #include <qvaluelist.h> | 39 | #include <qvaluelist.h> |
40 | #include <qdict.h> | 40 | #include <qdict.h> |
41 | #include <qmap.h> | 41 | #include <qmap.h> |
42 | #include <qobject.h> | 42 | #include <qobject.h> |
43 | #include <qhostaddress.h> | 43 | #include <qhostaddress.h> |
44 | 44 | ||
45 | /* STD */ | 45 | /* STD */ |
46 | // hacky workaround until we have a user space wireless.h | 46 | // hacky workaround until we have a user space wireless.h |
47 | #include <net/if.h> | 47 | #include <net/if.h> |
48 | #define _LINUX_IF_H | 48 | #define _LINUX_IF_H |
49 | #include <linux/wireless.h> | 49 | #include <linux/wireless.h> |
50 | #ifndef IW_MAX_PRIV_DEF | 50 | #ifndef IW_MAX_PRIV_DEF |
51 | #define IW_MAX_PRIV_DEF 128 | 51 | #define IW_MAX_PRIV_DEF 128 |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | namespace Opie { | 54 | namespace Opie { |
55 | namespace Net { | 55 | namespace Net { |
56 | class ONetworkInterface; | 56 | class ONetworkInterface; |
57 | class OWirelessNetworkInterface; | 57 | class OWirelessNetworkInterface; |
58 | class OChannelHopper; | 58 | class OChannelHopper; |
59 | class OMonitoringInterface; | 59 | class OMonitoringInterface; |
60 | 60 | ||
61 | /*====================================================================================== | 61 | /*====================================================================================== |
62 | * ONetwork | 62 | * ONetwork |
63 | *======================================================================================*/ | 63 | *======================================================================================*/ |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * @brief A container class for all network interfaces | 66 | * @brief A container class for all network interfaces |
67 | * | 67 | * |
68 | * This class provides access to all available network interfaces of your computer. | 68 | * This class provides access to all available network interfaces of your computer. |
69 | * | 69 | * |
70 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 70 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
71 | */ | 71 | */ |
72 | class ONetwork : public QObject | 72 | class ONetwork : public QObject |
73 | { | 73 | { |
74 | Q_OBJECT | 74 | Q_OBJECT |
75 | 75 | ||
76 | public: | 76 | public: |
77 | typedef QDict<ONetworkInterface> InterfaceMap; | 77 | typedef QDict<ONetworkInterface> InterfaceMap; |
78 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 78 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
79 | 79 | ||
80 | public: | 80 | public: |
81 | /** | 81 | /** |
82 | * @returns the number of available interfaces | 82 | * @returns the number of available interfaces |
83 | */ | 83 | */ |
84 | int count() const; | 84 | int count() const; |
85 | /** | 85 | /** |
86 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 86 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
87 | */ | 87 | */ |
88 | static ONetwork* instance(); | 88 | static ONetwork* instance(); |
89 | /** | 89 | /** |
90 | * @returns an iterator usable for iterating through all network interfaces. | 90 | * @returns an iterator usable for iterating through all network interfaces. |
91 | */ | 91 | */ |
92 | InterfaceIterator iterator() const; | 92 | InterfaceIterator iterator() const; |
93 | /** | 93 | /** |
94 | * @returns true, if the @a interface is present. | 94 | * @returns true, if the @a interface is present. |
95 | */ | 95 | */ |
96 | bool isPresent( const char* interface ) const; | 96 | bool isPresent( const char* interface ) const; |
97 | /** | 97 | /** |
98 | * @returns true, if the @a interface supports the wireless extension protocol. | 98 | * @returns true, if the @a interface supports the wireless extension protocol. |
99 | */ | 99 | */ |
100 | bool isWirelessInterface( const char* interface ) const; | 100 | bool isWirelessInterface( const char* interface ) const; |
101 | /** | 101 | /** |
102 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. | 102 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. |
103 | * @see ONetworkInterface | 103 | * @see ONetworkInterface |
104 | */ | 104 | */ |
105 | ONetworkInterface* interface( const QString& interface ) const; | 105 | ONetworkInterface* interface( const QString& interface ) const; |
106 | /** | 106 | /** |
107 | * @internal Rebuild the internal interface database | 107 | * @internal Rebuild the internal interface database |
108 | * @note Sometimes it might be useful to call this from client code, | 108 | * @note Sometimes it might be useful to call this from client code, |
109 | * e.g. after issuing a cardctl insert | 109 | * e.g. after issuing a cardctl insert |
110 | */ | 110 | */ |
111 | void synchronize(); | 111 | void synchronize(); |
112 | /** | 112 | /** |
113 | * @returns the wireless extension version used at compile time. | 113 | * @returns the wireless extension version used at compile time. |
114 | **/ | 114 | **/ |
115 | static short wirelessExtensionCompileVersion(); | 115 | static short wirelessExtensionCompileVersion(); |
116 | 116 | ||
117 | protected: | 117 | protected: |
118 | ONetwork(); | 118 | ONetwork(); |
119 | 119 | ||
120 | private: | 120 | private: |
121 | static ONetwork* _instance; | 121 | static ONetwork* _instance; |
122 | InterfaceMap _interfaces; | 122 | InterfaceMap _interfaces; |
123 | class Private; | 123 | class Private; |
124 | Private *d; | 124 | Private *d; |
125 | }; | 125 | }; |
126 | 126 | ||
127 | 127 | ||
128 | /*====================================================================================== | 128 | /*====================================================================================== |
129 | * ONetworkInterface | 129 | * ONetworkInterface |
130 | *======================================================================================*/ | 130 | *======================================================================================*/ |
131 | 131 | ||
132 | /** | 132 | /** |
133 | * @brief A network interface wrapper. | 133 | * @brief A network interface wrapper. |
134 | * | 134 | * |
135 | * This class provides a wrapper for a network interface. All the cumbersume details of | 135 | * This class provides a wrapper for a network interface. All the cumbersume details of |
136 | * Linux ioctls are hidden under a convenient high-level interface. | 136 | * Linux ioctls are hidden under a convenient high-level interface. |
137 | * @warning Most of the setting methods contained in this class require the appropriate | 137 | * @warning Most of the setting methods contained in this class require the appropriate |
138 | * process permissions to work. | 138 | * process permissions to work. |
139 | * | 139 | * |
140 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 140 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
141 | */ | 141 | */ |
142 | class ONetworkInterface : public QObject | 142 | class ONetworkInterface : public QObject |
143 | { | 143 | { |
144 | friend class OMonitoringInterface; | 144 | friend class OMonitoringInterface; |
145 | friend class OCiscoMonitoringInterface; | 145 | friend class OCiscoMonitoringInterface; |
146 | friend class OWlanNGMonitoringInterface; | 146 | friend class OWlanNGMonitoringInterface; |
147 | friend class OHostAPMonitoringInterface; | 147 | friend class OHostAPMonitoringInterface; |
148 | friend class OOrinocoMonitoringInterface; | 148 | friend class OOrinocoMonitoringInterface; |
149 | 149 | ||
150 | public: | 150 | public: |
151 | /** | 151 | /** |
152 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, | 152 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, |
153 | * but access them via @ref ONetwork::interface(). | 153 | * but access them via @ref ONetwork::interface(). |
154 | */ | 154 | */ |
155 | ONetworkInterface( QObject* parent, const char* name ); | 155 | ONetworkInterface( QObject* parent, const char* name ); |
156 | /** | 156 | /** |
157 | * Destructor. | 157 | * Destructor. |
158 | */ | 158 | */ |
159 | virtual ~ONetworkInterface(); | 159 | virtual ~ONetworkInterface(); |
160 | /** | 160 | /** |
161 | * Associates a @a monitoring interface with this network interface. | 161 | * Associates a @a monitoring interface with this network interface. |
162 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. | 162 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. |
163 | */ | 163 | */ |
164 | void setMonitoring( OMonitoringInterface* monitoring ); | 164 | void setMonitoring( OMonitoringInterface* monitoring ); |
165 | /** | 165 | /** |
166 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. | 166 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. |
167 | */ | 167 | */ |
168 | OMonitoringInterface* monitoring() const; | 168 | OMonitoringInterface* monitoring() const; |
169 | /** | 169 | /** |
170 | * Setting an interface to promiscuous mode enables the device to receive | 170 | * Setting an interface to promiscuous mode enables the device to receive |
171 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. | 171 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. |
172 | */ | 172 | */ |
173 | bool setPromiscuousMode( bool ); | 173 | bool setPromiscuousMode( bool ); |
174 | /** | 174 | /** |
175 | * @returns true if the interface is set to promiscuous mode. | 175 | * @returns true if the interface is set to promiscuous mode. |
176 | */ | 176 | */ |
177 | bool promiscuousMode() const; | 177 | bool promiscuousMode() const; |
178 | /** | 178 | /** |
179 | * Setting an interface to up enables it to receive packets. | 179 | * Setting an interface to up enables it to receive packets. |
180 | */ | 180 | */ |
181 | bool setUp( bool ); | 181 | bool setUp( bool ); |
182 | /** | 182 | /** |
183 | * @returns true if the interface is up. | 183 | * @returns true if the interface is up. |
184 | */ | 184 | */ |
185 | bool isUp() const; | 185 | bool isUp() const; |
186 | /** | 186 | /** |
187 | * @returns true if the interface is a loopback interface. | 187 | * @returns true if the interface is a loopback interface. |
188 | */ | 188 | */ |
189 | bool isLoopback() const; | 189 | bool isLoopback() const; |
190 | /** | 190 | /** |
191 | * @returns true if the interface is featuring supports the wireless extension protocol. | 191 | * @returns true if the interface is featuring supports the wireless extension protocol. |
192 | */ | 192 | */ |
193 | bool isWireless() const; | 193 | bool isWireless() const; |
194 | /** | 194 | /** |
195 | * Associate the IP address @ addr with the interface. | 195 | * Associate the IP address @ addr with the interface. |
196 | */ | 196 | */ |
197 | void setIPV4Address( const QHostAddress& addr ); | 197 | void setIPV4Address( const QHostAddress& addr ); |
198 | /** | 198 | /** |
199 | * @returns the IPv4 address associated with the interface. | 199 | * @returns the IPv4 address associated with the interface. |
200 | */ | 200 | */ |
201 | QString ipV4Address() const; //TODO: make this return an OHostAddress | 201 | QString ipV4Address() const; //TODO: make this return an OHostAddress |
202 | /** | 202 | /** |
203 | * Associate the MAC address @a addr with the interface. | 203 | * Associate the MAC address @a addr with the interface. |
204 | * @note It can be necessary to shut down the interface prior to calling this method. | 204 | * @note It can be necessary to shut down the interface prior to calling this method. |
205 | * @warning This is not supported by all drivers. | 205 | * @warning This is not supported by all drivers. |
206 | */ | 206 | */ |
207 | void setMacAddress( const OMacAddress& addr ); | 207 | void setMacAddress( const OMacAddress& addr ); |
208 | /** | 208 | /** |
209 | * @returns the MAC address associated with the interface. | 209 | * @returns the MAC address associated with the interface. |
210 | */ | 210 | */ |
211 | OMacAddress macAddress() const; | 211 | OMacAddress macAddress() const; |
212 | /** | 212 | /** |
213 | * Associate the IPv4 @a netmask with the interface. | 213 | * Associate the IPv4 @a netmask with the interface. |
214 | */ | 214 | */ |
215 | void setIPV4Netmask( const QHostAddress& netmask ); | 215 | void setIPV4Netmask( const QHostAddress& netmask ); |
216 | /** | 216 | /** |
217 | * @returns the IPv4 netmask associated with the interface. | 217 | * @returns the IPv4 netmask associated with the interface. |
218 | */ | 218 | */ |
219 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress | 219 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress |
220 | /** | 220 | /** |
221 | * @returns the data link type currently associated with the interface. | 221 | * @returns the data link type currently associated with the interface. |
222 | * @see #include <net/if_arp.h> for possible values. | 222 | * @see #include <net/if_arp.h> for possible values. |
223 | */ | 223 | */ |
224 | int dataLinkType() const; | 224 | int dataLinkType() const; |
225 | 225 | ||
226 | protected: | 226 | protected: |
227 | const int _sfd; | 227 | const int _sfd; |
228 | mutable ifreq _ifr; | 228 | mutable ifreq _ifr; |
229 | OMonitoringInterface* _mon; | 229 | OMonitoringInterface* _mon; |
230 | 230 | ||
231 | protected: | 231 | protected: |
232 | struct ifreq& ifr() const; | 232 | struct ifreq& ifr() const; |
233 | virtual void init(); | 233 | virtual void init(); |
234 | bool ioctl( int call ) const; | 234 | bool ioctl( int call ) const; |
235 | bool ioctl( int call, struct ifreq& ) const; | 235 | bool ioctl( int call, struct ifreq& ) const; |
236 | private: | 236 | private: |
237 | class Private; | 237 | class Private; |
238 | Private *d; | 238 | Private *d; |
239 | }; | 239 | }; |
240 | 240 | ||
241 | /*====================================================================================== | 241 | /*====================================================================================== |
242 | * OChannelHopper | 242 | * OChannelHopper |
243 | *======================================================================================*/ | 243 | *======================================================================================*/ |
244 | 244 | ||
245 | /** | 245 | /** |
246 | * @brief A radio frequency channel hopper. | 246 | * @brief A radio frequency channel hopper. |
247 | * | 247 | * |
248 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently | 248 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently |
249 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. | 249 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. |
250 | * This is necessary when in monitoring mode and scanning for other devices, because | 250 | * This is necessary when in monitoring mode and scanning for other devices, because |
251 | * the radio frequency hardware can only detect packets sent on the same frequency. | 251 | * the radio frequency hardware can only detect packets sent on the same frequency. |
252 | * | 252 | * |
253 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 253 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
254 | */ | 254 | */ |
255 | class OChannelHopper : public QObject | 255 | class OChannelHopper : public QObject |
256 | { | 256 | { |
257 | Q_OBJECT | 257 | Q_OBJECT |
258 | 258 | ||
259 | public: | 259 | public: |
260 | /** | 260 | /** |
261 | * Constructor. | 261 | * Constructor. |
262 | */ | 262 | */ |
263 | OChannelHopper( OWirelessNetworkInterface* ); | 263 | OChannelHopper( OWirelessNetworkInterface* ); |
264 | /** | 264 | /** |
265 | * Destructor. | 265 | * Destructor. |
266 | */ | 266 | */ |
267 | virtual ~OChannelHopper(); | 267 | virtual ~OChannelHopper(); |
268 | /** | 268 | /** |
269 | * @returns true, if the channel hopper is hopping channels | 269 | * @returns true, if the channel hopper is hopping channels |
270 | */ | 270 | */ |
271 | bool isActive() const; | 271 | bool isActive() const; |
272 | /** | 272 | /** |
273 | * @returns the last hopped channel | 273 | * @returns the last hopped channel |
274 | */ | 274 | */ |
275 | int channel() const; | 275 | int channel() const; |
276 | /** | 276 | /** |
277 | * Set the channel hopping @a interval. | 277 | * Set the channel hopping @a interval. |
278 | * An interval of 0 deactivates the channel hopper. | 278 | * An interval of 0 deactivates the channel hopper. |
279 | */ | 279 | */ |
280 | void setInterval( int interval ); | 280 | void setInterval( int interval ); |
281 | /** | 281 | /** |
282 | * @returns the channel hopping interval | 282 | * @returns the channel hopping interval |
283 | */ | 283 | */ |
284 | int interval() const; | 284 | int interval() const; |
285 | 285 | ||
286 | signals: | 286 | signals: |
287 | /** | 287 | /** |
288 | * This signal is emitted right after the channel hopper performed a hop | 288 | * This signal is emitted right after the channel hopper performed a hop |
289 | */ | 289 | */ |
290 | void hopped( int ); | 290 | void hopped( int ); |
291 | 291 | ||
292 | protected: | 292 | protected: |
293 | virtual void timerEvent( QTimerEvent* ); | 293 | virtual void timerEvent( QTimerEvent* ); |
294 | 294 | ||
295 | private: | 295 | private: |
296 | OWirelessNetworkInterface* _iface; | 296 | OWirelessNetworkInterface* _iface; |
297 | int _interval; | 297 | int _interval; |
298 | int _tid; | 298 | int _tid; |
299 | QValueList<int> _channels; | 299 | QValueList<int> _channels; |
300 | QValueList<int>::Iterator _channel; | 300 | QValueList<int>::Iterator _channel; |
301 | class Private; | 301 | class Private; |
302 | Private *d; | 302 | Private *d; |
303 | }; | 303 | }; |
304 | 304 | ||
305 | 305 | ||
306 | /*====================================================================================== | 306 | /*====================================================================================== |
307 | * OWirelessNetworkInterface | 307 | * OWirelessNetworkInterface |
308 | *======================================================================================*/ | 308 | *======================================================================================*/ |
309 | 309 | ||
310 | /** | 310 | /** |
311 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. | 311 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. |
312 | * | 312 | * |
313 | * This class provides a high-level encapsulation of the Linux wireless extension API. | 313 | * This class provides a high-level encapsulation of the Linux wireless extension API. |
314 | * | 314 | * |
315 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 315 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
316 | */ | 316 | */ |
317 | class OWirelessNetworkInterface : public ONetworkInterface | 317 | class OWirelessNetworkInterface : public ONetworkInterface |
318 | { | 318 | { |
319 | friend class OMonitoringInterface; | 319 | friend class OMonitoringInterface; |
320 | friend class OCiscoMonitoringInterface; | 320 | friend class OCiscoMonitoringInterface; |
321 | friend class OWlanNGMonitoringInterface; | 321 | friend class OWlanNGMonitoringInterface; |
322 | friend class OHostAPMonitoringInterface; | 322 | friend class OHostAPMonitoringInterface; |
323 | friend class OOrinocoMonitoringInterface; | 323 | friend class OOrinocoMonitoringInterface; |
324 | 324 | ||
325 | friend class OPrivateIOCTL; | 325 | friend class OPrivateIOCTL; |
326 | 326 | ||
327 | public: | 327 | public: |
328 | /** | 328 | /** |
329 | * Constructor. | 329 | * Constructor. |
330 | */ | 330 | */ |
331 | OWirelessNetworkInterface( QObject* parent, const char* name ); | 331 | OWirelessNetworkInterface( QObject* parent, const char* name ); |
332 | /** | 332 | /** |
333 | * Destructor. | 333 | * Destructor. |
334 | */ | 334 | */ |
335 | virtual ~OWirelessNetworkInterface(); | 335 | virtual ~OWirelessNetworkInterface(); |
336 | /** | 336 | /** |
337 | * Setting the @a channel of the interface changes the radio frequency (RF) | 337 | * Setting the @a channel of the interface changes the radio frequency (RF) |
338 | * of the corresponding wireless network device. | 338 | * of the corresponding wireless network device. |
339 | * @note Common channel range is within [1-14]. A value of 0 is not allowed. | 339 | * @note Common channel range is within [1-14]. A value of 0 is not allowed. |
340 | * @see channels() | 340 | * @see channels() |
341 | */ | 341 | */ |
342 | virtual void setChannel( int channel ) const; | 342 | virtual void setChannel( int channel ) const; |
343 | /** | 343 | /** |
344 | * @returns the channel index of the current radio frequency. | 344 | * @returns the channel index of the current radio frequency. |
345 | */ | 345 | */ |
346 | virtual int channel() const; | 346 | virtual int channel() const; |
347 | /** | 347 | /** |
348 | * @returns the current radio frequency (in MHz). | 348 | * @returns the current radio frequency (in MHz). |
349 | */ | 349 | */ |
350 | virtual double frequency() const; | 350 | virtual double frequency() const; |
351 | /** | 351 | /** |
352 | * @returns the number of radio frequency channels for the | 352 | * @returns the number of radio frequency channels for the |
353 | * corresponding wireless network device. | 353 | * corresponding wireless network device. |
354 | * @note European devices usually have 14 channels, while American typically feature 11 channels. | 354 | * @note European devices usually have 14 channels, while American typically feature 11 channels. |
355 | */ | 355 | */ |
356 | virtual int channels() const; | 356 | virtual int channels() const; |
357 | /** | 357 | /** |
358 | * Set the IEEE 802.11 operation @a mode. | 358 | * Set the IEEE 802.11 operation @a mode. |
359 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master | 359 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master |
360 | * @warning Not all drivers support the all modes. | 360 | * @warning Not all drivers support the all modes. |
361 | * @note You might have to change the SSID to get the operation mode change into effect. | 361 | * @note You might have to change the SSID to get the operation mode change into effect. |
362 | */ | 362 | */ |
363 | virtual void setMode( const QString& mode ); | 363 | virtual void setMode( const QString& mode ); |
364 | /** | 364 | /** |
365 | * @returns the current IEEE 802.11 operation mode. | 365 | * @returns the current IEEE 802.11 operation mode. |
366 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown | 366 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown |
367 | * | 367 | * |
368 | * @note: Important note concerning the 'monitor' mode: | 368 | * @note: Important note concerning the 'monitor' mode: |
369 | * Setting the monitor mode on a wireless network interface enables | 369 | * Setting the monitor mode on a wireless network interface enables |
370 | * listening to IEEE 802.11 data and management frames which normally | 370 | * listening to IEEE 802.11 data and management frames which normally |
371 | * are handled by the device firmware. This can be used to detect | 371 | * are handled by the device firmware. This can be used to detect |
372 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. | 372 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. |
373 | * @warning Standard wireless network drives don't support the monitor mode. | 373 | * @warning Standard wireless network drives don't support the monitor mode. |
374 | * @warning You need a patched driver for this to work. | 374 | * @warning You need a patched driver for this to work. |
375 | * @note Enabling the monitor mode is highly driver dependent and requires | 375 | * @note Enabling the monitor mode is highly driver dependent and requires |
376 | * the proper @ref OMonitoringInterface to be associated with the interface. | 376 | * the proper @ref OMonitoringInterface to be associated with the interface. |
377 | * @see OMonitoringInterface | 377 | * @see OMonitoringInterface |
378 | */ | 378 | */ |
379 | virtual QString mode() const; | 379 | virtual QString mode() const; |
380 | /** | 380 | /** |
381 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. | 381 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. |
382 | * @see OChannelHopper | 382 | * @see OChannelHopper |
383 | */ | 383 | */ |
384 | virtual void setChannelHopping( int interval = 0 ); | 384 | virtual void setChannelHopping( int interval = 0 ); |
385 | /** | 385 | /** |
386 | * @returns the channel hopping interval or 0, if channel hopping is disabled. | 386 | * @returns the channel hopping interval or 0, if channel hopping is disabled. |
387 | */ | 387 | */ |
388 | virtual int channelHopping() const; | 388 | virtual int channelHopping() const; |
389 | /** | 389 | /** |
390 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before | 390 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before |
391 | */ | 391 | */ |
392 | virtual OChannelHopper* channelHopper() const; | 392 | virtual OChannelHopper* channelHopper() const; |
393 | /** | 393 | /** |
394 | * Set the station @a nickname. | 394 | * Set the station @a nickname. |
395 | */ | 395 | */ |
396 | virtual void setNickName( const QString& nickname ); | 396 | virtual void setNickName( const QString& nickname ); |
397 | /** | 397 | /** |
398 | * @returns the current station nickname. | 398 | * @returns the current station nickname. |
399 | */ | 399 | */ |
400 | virtual QString nickName() const; | 400 | virtual QString nickName() const; |
401 | /** | 401 | /** |
402 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. | 402 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. |
403 | * @see OPrivateIOCTL | 403 | * @see OPrivateIOCTL |
404 | */ | 404 | */ |
405 | virtual void setPrivate( const QString& command, int number, ... ); | 405 | virtual void setPrivate( const QString& command, int number, ... ); |
406 | /** | 406 | /** |
407 | * @returns true if the interface is featuring the private IOCTL @command. | 407 | * @returns true if the interface is featuring the private IOCTL @command. |
408 | */ | 408 | */ |
409 | virtual bool hasPrivate( const QString& command ); | 409 | virtual bool hasPrivate( const QString& command ); |
410 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this | 410 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this |
411 | /** | 411 | /** |
412 | * @returns true if the interface is associated to an access point | 412 | * @returns true if the interface is associated to an access point |
413 | * @note: This information is only valid if the interface is in managed mode. | 413 | * @note: This information is only valid if the interface is in managed mode. |
414 | */ | 414 | */ |
415 | virtual bool isAssociated() const; | 415 | virtual bool isAssociated() const; |
416 | /** | 416 | /** |
417 | * @returns the MAC address of the Access Point if the device is in infrastructure mode. | 417 | * @returns the MAC address of the Access Point if the device is in infrastructure mode. |
418 | * @returns a (more or less random) cell ID address if the device is in adhoc mode. | 418 | * @returns a (more or less random) cell ID address if the device is in adhoc mode. |
419 | */ | 419 | */ |
420 | virtual OMacAddress associatedAP() const; | 420 | virtual OMacAddress associatedAP() const; |
421 | /** | 421 | /** |
422 | * Set the @a ssid (Service Set ID) string. This is used to decide | 422 | * Set the @a ssid (Service Set ID) string. This is used to decide |
423 | * which network to associate with (use "any" to let the driver decide). | 423 | * which network to associate with (use "any" to let the driver decide). |
424 | */ | 424 | */ |
425 | virtual void setSSID( const QString& ssid ); | 425 | virtual void setSSID( const QString& ssid ); |
426 | /** | 426 | /** |
427 | * @returns the current SSID (Service Set ID). | 427 | * @returns the current SSID (Service Set ID). |
428 | */ | 428 | */ |
429 | virtual QString SSID() const; | 429 | virtual QString SSID() const; |
430 | /** | 430 | /** |
431 | * Perform scanning the wireless network neighbourhood. | 431 | * Perform scanning the wireless network neighbourhood. |
432 | * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! | 432 | * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! |
433 | */ | 433 | */ |
434 | virtual OStationList* scanNetwork(); | 434 | virtual OStationList* scanNetwork(); |
435 | /** | 435 | /** |
436 | * @return signal strength to associated neighbour (in percent). | 436 | * @return signal strength to associated neighbour (in percent). |
437 | * In infrastructure mode, this is the signal strength of the Access Point. | 437 | * In infrastructure mode, this is the signal strength of the Access Point. |
438 | * In other modes the result is driver dependent. | 438 | * In other modes the result is driver dependent. |
439 | */ | 439 | */ |
440 | virtual int signalStrength() const; | 440 | virtual int signalStrength() const; |
441 | /** | 441 | /** |
442 | * @returns the wireless extension version used by the interface driver. | 442 | * @returns the wireless extension version used by the interface driver. |
443 | **/ | 443 | **/ |
444 | short wirelessExtensionDriverVersion() const; | 444 | short wirelessExtensionDriverVersion() const; |
445 | /** | 445 | /** |
446 | * @internal commit pending changes to the driver | 446 | * @internal commit pending changes to the driver |
447 | */ | 447 | */ |
448 | void commit() const; | 448 | void commit() const; |
449 | 449 | ||
450 | protected: | 450 | protected: |
451 | void buildInformation(); | 451 | void buildInformation(); |
452 | void buildPrivateList(); | 452 | void buildPrivateList(); |
453 | void dumpInformation() const; | 453 | void dumpInformation() const; |
454 | virtual void init(); | 454 | virtual void init(); |
455 | struct iwreq& iwr() const; | 455 | struct iwreq& iwr() const; |
456 | bool wioctl( int call ) const; | 456 | bool wioctl( int call ) const; |
457 | bool wioctl( int call, struct iwreq& ) const; | 457 | bool wioctl( int call, struct iwreq& ) const; |
458 | 458 | ||
459 | protected: | 459 | protected: |
460 | mutable struct iwreq _iwr; | 460 | mutable struct iwreq _iwr; |
461 | QMap<int,int> _channels; | 461 | QMap<int,int> _channels; |
462 | struct iw_range _range; | 462 | struct iw_range _range; |
463 | 463 | ||
464 | private: | 464 | private: |
465 | OChannelHopper* _hopper; | 465 | OChannelHopper* _hopper; |
466 | class Private; | 466 | class Private; |
467 | Private *d; | 467 | Private *d; |
468 | }; | 468 | }; |
469 | 469 | ||
470 | 470 | ||
471 | /*====================================================================================== | 471 | /*====================================================================================== |
472 | * OMonitoringInterface | 472 | * OMonitoringInterface |
473 | *======================================================================================*/ | 473 | *======================================================================================*/ |
474 | 474 | ||
475 | 475 | ||
476 | class OMonitoringInterface | 476 | class OMonitoringInterface |
477 | { | 477 | { |
478 | public: | 478 | public: |
479 | OMonitoringInterface(); | 479 | OMonitoringInterface(); |
480 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 480 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
481 | virtual ~OMonitoringInterface(); | 481 | virtual ~OMonitoringInterface(); |
482 | 482 | ||
483 | public: | 483 | public: |
484 | virtual void setEnabled( bool ); | 484 | virtual void setEnabled( bool ); |
485 | virtual void setChannel( int ); | 485 | virtual void setChannel( int ); |
486 | 486 | ||
487 | virtual QString name() const = 0; | 487 | virtual QString name() const = 0; |
488 | 488 | ||
489 | protected: | 489 | protected: |
490 | OWirelessNetworkInterface* _if; | 490 | OWirelessNetworkInterface* _if; |
491 | bool _prismHeader; | 491 | bool _prismHeader; |
492 | private: | 492 | private: |
493 | class Private; | 493 | class Private; |
494 | Private *d; | 494 | Private *d; |
495 | 495 | ||
496 | }; | 496 | }; |
497 | 497 | ||
498 | 498 | ||
499 | /*====================================================================================== | 499 | /*====================================================================================== |
500 | * OCiscoMonitoring | 500 | * OCiscoMonitoring |
501 | *======================================================================================*/ | 501 | *======================================================================================*/ |
502 | 502 | ||
503 | 503 | ||
504 | class OCiscoMonitoringInterface : public OMonitoringInterface | 504 | class OCiscoMonitoringInterface : public OMonitoringInterface |
505 | { | 505 | { |
506 | public: | 506 | public: |
507 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 507 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
508 | virtual ~OCiscoMonitoringInterface(); | 508 | virtual ~OCiscoMonitoringInterface(); |
509 | 509 | ||
510 | virtual void setEnabled( bool ); | 510 | virtual void setEnabled( bool ); |
511 | virtual QString name() const; | 511 | virtual QString name() const; |
512 | virtual void setChannel( int ); | 512 | virtual void setChannel( int ); |
513 | private: | 513 | private: |
514 | class Private; | 514 | class Private; |
515 | Private *d; | 515 | Private *d; |
516 | 516 | ||
517 | }; | 517 | }; |
518 | 518 | ||
519 | 519 | ||
520 | /*====================================================================================== | 520 | /*====================================================================================== |
521 | * OWlanNGMonitoringInterface | 521 | * OWlanNGMonitoringInterface |
522 | *======================================================================================*/ | 522 | *======================================================================================*/ |
523 | 523 | ||
524 | 524 | ||
525 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 525 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
526 | { | 526 | { |
527 | public: | 527 | public: |
528 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 528 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
529 | virtual ~OWlanNGMonitoringInterface(); | 529 | virtual ~OWlanNGMonitoringInterface(); |
530 | 530 | ||
531 | public: | 531 | public: |
532 | virtual void setEnabled( bool ); | 532 | virtual void setEnabled( bool ); |
533 | virtual QString name() const; | 533 | virtual QString name() const; |
534 | virtual void setChannel( int ); | 534 | virtual void setChannel( int ); |
535 | private: | 535 | private: |
536 | class Private; | 536 | class Private; |
537 | Private *d; | 537 | Private *d; |
538 | 538 | ||
539 | }; | 539 | }; |
540 | 540 | ||
541 | 541 | ||
542 | /*====================================================================================== | 542 | /*====================================================================================== |
543 | * OHostAPMonitoringInterface | 543 | * OHostAPMonitoringInterface |
544 | *======================================================================================*/ | 544 | *======================================================================================*/ |
545 | 545 | ||
546 | 546 | ||
547 | class OHostAPMonitoringInterface : public OMonitoringInterface | 547 | class OHostAPMonitoringInterface : public OMonitoringInterface |
548 | { | 548 | { |
549 | public: | 549 | public: |
550 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 550 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
551 | virtual ~OHostAPMonitoringInterface(); | 551 | virtual ~OHostAPMonitoringInterface(); |
552 | 552 | ||
553 | public: | 553 | public: |
554 | virtual void setEnabled( bool ); | 554 | virtual void setEnabled( bool ); |
555 | virtual QString name() const; | 555 | virtual QString name() const; |
556 | 556 | ||
557 | private: | 557 | private: |
558 | class Private; | 558 | class Private; |
559 | Private *d; | 559 | Private *d; |
560 | }; | 560 | }; |
561 | 561 | ||
562 | 562 | ||
563 | /*====================================================================================== | 563 | /*====================================================================================== |
564 | * OOrinocoMonitoringInterface | 564 | * OOrinocoMonitoringInterface |
565 | *======================================================================================*/ | 565 | *======================================================================================*/ |
566 | 566 | ||
567 | 567 | ||
568 | class OOrinocoMonitoringInterface : public OMonitoringInterface | 568 | class OOrinocoMonitoringInterface : public OMonitoringInterface |
569 | { | 569 | { |
570 | public: | 570 | public: |
571 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 571 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
572 | virtual ~OOrinocoMonitoringInterface(); | 572 | virtual ~OOrinocoMonitoringInterface(); |
573 | 573 | ||
574 | public: | 574 | public: |
575 | virtual void setChannel( int ); | 575 | virtual void setChannel( int ); |
576 | virtual void setEnabled( bool ); | 576 | virtual void setEnabled( bool ); |
577 | virtual QString name() const; | 577 | virtual QString name() const; |
578 | 578 | ||
579 | private: | 579 | private: |
580 | class Private; | 580 | class Private; |
581 | Private *d; | 581 | Private *d; |
582 | }; | 582 | }; |
583 | 583 | ||
584 | } | 584 | } |
585 | } | 585 | } |
586 | 586 | ||
587 | #endif // ONETWORK_H | 587 | #endif // ONETWORK_H |
588 | 588 | ||
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 25ac09b..eafbeea 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,780 +1,780 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 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 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "udp_ports.h" | 31 | #include "udp_ports.h" |
32 | #include "opcap.h" | 32 | #include "opcap.h" |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | using namespace Opie::Core; | 36 | using namespace Opie::Core; |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | #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) |
40 | #include <qsocketnotifier.h> | 40 | #include <qsocketnotifier.h> |
41 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
42 | 42 | ||
43 | /* STD */ | 43 | /* STD */ |
44 | #include <sys/time.h> | 44 | #include <sys/time.h> |
45 | #include <sys/types.h> | 45 | #include <sys/types.h> |
46 | #include <assert.h> | 46 | #include <assert.h> |
47 | #include <unistd.h> | 47 | #include <unistd.h> |
48 | #include <string.h> | 48 | #include <string.h> |
49 | 49 | ||
50 | namespace Opie { | 50 | namespace Opie { |
51 | namespace Net { | 51 | namespace Net { |
52 | 52 | ||
53 | /*====================================================================================== | 53 | /*====================================================================================== |
54 | * OPacket | 54 | * OPacket |
55 | *======================================================================================*/ | 55 | *======================================================================================*/ |
56 | 56 | ||
57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) | 57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) |
58 | :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) | 58 | :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) |
59 | { | 59 | { |
60 | 60 | ||
61 | _data = new unsigned char[ header.len ]; | 61 | _data = new unsigned char[ header.len ]; |
62 | assert( _data ); | 62 | assert( _data ); |
63 | memcpy( const_cast<unsigned char*>(_data), data, header.len ); | 63 | memcpy( const_cast<unsigned char*>(_data), data, header.len ); |
64 | // We have to copy the data structure here, because the 'data' pointer handed by libpcap | 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. | 65 | // points to an internal region which is reused by lipcap. |
66 | odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; | 66 | odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; |
67 | _end = (unsigned char*) _data + header.len; | 67 | _end = (unsigned char*) _data + header.len; |
68 | 68 | ||
69 | switch ( datalink ) | 69 | switch ( datalink ) |
70 | { | 70 | { |
71 | case DLT_EN10MB: | 71 | case DLT_EN10MB: |
72 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; | 72 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; |
73 | new OEthernetPacket( _end, (const struct ether_header*) _data, this ); | 73 | new OEthernetPacket( _end, (const struct ether_header*) _data, this ); |
74 | break; | 74 | break; |
75 | 75 | ||
76 | case DLT_IEEE802_11: | 76 | case DLT_IEEE802_11: |
77 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; | 77 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; |
78 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); | 78 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); |
79 | break; | 79 | break; |
80 | 80 | ||
81 | case DLT_PRISM_HEADER: | 81 | case DLT_PRISM_HEADER: |
82 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; | 82 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; |
83 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); | 83 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); |
84 | break; | 84 | break; |
85 | 85 | ||
86 | default: | 86 | default: |
87 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; | 87 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | OPacket::~OPacket() | 92 | OPacket::~OPacket() |
93 | { | 93 | { |
94 | odebug << "~OPacket( " << name() << " )" << oendl; | 94 | odebug << "~OPacket( " << name() << " )" << oendl; |
95 | delete [] _data; | 95 | delete [] _data; |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | timevalstruct OPacket::timeval() const | 99 | timevalstruct OPacket::timeval() const |
100 | { | 100 | { |
101 | return _hdr.ts; | 101 | return _hdr.ts; |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | int OPacket::caplen() const | 105 | int OPacket::caplen() const |
106 | { | 106 | { |
107 | return _hdr.caplen; | 107 | return _hdr.caplen; |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 111 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
112 | { | 112 | { |
113 | if (!l) return; | 113 | if (!l) return; |
114 | QObject* o = l->first(); | 114 | QObject* o = l->first(); |
115 | while ( o ) | 115 | while ( o ) |
116 | { | 116 | { |
117 | stats[o->name()]++; | 117 | stats[o->name()]++; |
118 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 118 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
119 | o = l->next(); | 119 | o = l->next(); |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | QString OPacket::dumpStructure() const | 124 | QString OPacket::dumpStructure() const |
125 | { | 125 | { |
126 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; | 126 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | QString OPacket::_dumpStructure( QObjectList* l ) const | 130 | QString OPacket::_dumpStructure( QObjectList* l ) const |
131 | { | 131 | { |
132 | if (!l) return QString::null; | 132 | if (!l) return QString::null; |
133 | QObject* o = l->first(); | 133 | QObject* o = l->first(); |
134 | QString str(" "); | 134 | QString str(" "); |
135 | 135 | ||
136 | while ( o ) | 136 | while ( o ) |
137 | { | 137 | { |
138 | str.append( o->name() ); | 138 | str.append( o->name() ); |
139 | str.append( " |" ); | 139 | str.append( " |" ); |
140 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); | 140 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); |
141 | o = l->next(); | 141 | o = l->next(); |
142 | } | 142 | } |
143 | return str; | 143 | return str; |
144 | } | 144 | } |
145 | 145 | ||
146 | QString OPacket::dump( int bpl ) const | 146 | QString OPacket::dump( int bpl ) const |
147 | { | 147 | { |
148 | static int index = 0; | 148 | static int index = 0; |
149 | index++; | 149 | index++; |
150 | int len = _hdr.caplen; | 150 | int len = _hdr.caplen; |
151 | QString str( "000:" ); | 151 | QString str( "000:" ); |
152 | QString tmp; | 152 | QString tmp; |
153 | QString bytes; | 153 | QString bytes; |
154 | QString chars; | 154 | QString chars; |
155 | 155 | ||
156 | for ( int i = 0; i < len; ++i ) | 156 | for ( int i = 0; i < len; ++i ) |
157 | { | 157 | { |
158 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 158 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
159 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 159 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
160 | else chars.append( '.' ); | 160 | else chars.append( '.' ); |
161 | 161 | ||
162 | if ( !((i+1) % bpl) ) | 162 | if ( !((i+1) % bpl) ) |
163 | { | 163 | { |
164 | str.append( bytes ); | 164 | str.append( bytes ); |
165 | str.append( ' ' ); | 165 | str.append( ' ' ); |
166 | str.append( chars ); | 166 | str.append( chars ); |
167 | str.append( '\n' ); | 167 | str.append( '\n' ); |
168 | tmp.sprintf( "%03X:", i+1 ); str.append( tmp ); | 168 | tmp.sprintf( "%03X:", i+1 ); str.append( tmp ); |
169 | bytes = ""; | 169 | bytes = ""; |
170 | chars = ""; | 170 | chars = ""; |
171 | } | 171 | } |
172 | 172 | ||
173 | } | 173 | } |
174 | if ( (len % bpl) ) | 174 | if ( (len % bpl) ) |
175 | { | 175 | { |
176 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 176 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
177 | str.append( chars ); | 177 | str.append( chars ); |
178 | } | 178 | } |
179 | str.append( '\n' ); | 179 | str.append( '\n' ); |
180 | return str; | 180 | return str; |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | int OPacket::len() const | 184 | int OPacket::len() const |
185 | { | 185 | { |
186 | return _hdr.len; | 186 | return _hdr.len; |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) | 190 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) |
191 | { | 191 | { |
192 | s << p.dumpStructure(); | 192 | s << p.dumpStructure(); |
193 | return s; | 193 | return s; |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | /*====================================================================================== | 197 | /*====================================================================================== |
198 | * OEthernetPacket | 198 | * OEthernetPacket |
199 | *======================================================================================*/ | 199 | *======================================================================================*/ |
200 | 200 | ||
201 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 201 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
202 | :QObject( parent, "Ethernet" ), _ether( data ) | 202 | :QObject( parent, "Ethernet" ), _ether( data ) |
203 | { | 203 | { |
204 | 204 | ||
205 | odebug << "Source = " << sourceAddress().toString() << oendl; | 205 | odebug << "Source = " << sourceAddress().toString() << oendl; |
206 | odebug << "Destination = " << destinationAddress().toString() << oendl; | 206 | odebug << "Destination = " << destinationAddress().toString() << oendl; |
207 | 207 | ||
208 | if ( sourceAddress() == OMacAddress::broadcast ) | 208 | if ( sourceAddress() == OMacAddress::broadcast ) |
209 | odebug << "Source is broadcast address" << oendl; | 209 | odebug << "Source is broadcast address" << oendl; |
210 | if ( destinationAddress() == OMacAddress::broadcast ) | 210 | if ( destinationAddress() == OMacAddress::broadcast ) |
211 | odebug << "Destination is broadcast address" << oendl; | 211 | odebug << "Destination is broadcast address" << oendl; |
212 | 212 | ||
213 | switch ( type() ) | 213 | switch ( type() ) |
214 | { | 214 | { |
215 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 215 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
216 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 216 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
217 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } | 217 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } |
218 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; | 218 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; |
219 | } | 219 | } |
220 | 220 | ||
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | OEthernetPacket::~OEthernetPacket() | 224 | OEthernetPacket::~OEthernetPacket() |
225 | { | 225 | { |
226 | } | 226 | } |
227 | 227 | ||
228 | 228 | ||
229 | OMacAddress OEthernetPacket::sourceAddress() const | 229 | OMacAddress OEthernetPacket::sourceAddress() const |
230 | { | 230 | { |
231 | return OMacAddress( _ether->ether_shost ); | 231 | return OMacAddress( _ether->ether_shost ); |
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | OMacAddress OEthernetPacket::destinationAddress() const | 235 | OMacAddress OEthernetPacket::destinationAddress() const |
236 | { | 236 | { |
237 | return OMacAddress( _ether->ether_dhost ); | 237 | return OMacAddress( _ether->ether_dhost ); |
238 | } | 238 | } |
239 | 239 | ||
240 | int OEthernetPacket::type() const | 240 | int OEthernetPacket::type() const |
241 | { | 241 | { |
242 | return ntohs( _ether->ether_type ); | 242 | return ntohs( _ether->ether_type ); |
243 | } | 243 | } |
244 | 244 | ||
245 | 245 | ||
246 | /*====================================================================================== | 246 | /*====================================================================================== |
247 | * OIPPacket | 247 | * OIPPacket |
248 | *======================================================================================*/ | 248 | *======================================================================================*/ |
249 | 249 | ||
250 | 250 | ||
251 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 251 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
252 | :QObject( parent, "IP" ), _iphdr( data ) | 252 | :QObject( parent, "IP" ), _iphdr( data ) |
253 | { | 253 | { |
254 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; | 254 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; |
255 | 255 | ||
256 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; | 256 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; |
257 | odebug << " toAddress = " << toIPAddress().toString() << oendl; | 257 | odebug << " toAddress = " << toIPAddress().toString() << oendl; |
258 | 258 | ||
259 | switch ( protocol() ) | 259 | switch ( protocol() ) |
260 | { | 260 | { |
261 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 261 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
262 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 262 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
263 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; | 263 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; |
264 | } | 264 | } |
265 | 265 | ||
266 | } | 266 | } |
267 | 267 | ||
268 | OIPPacket::~OIPPacket() | 268 | OIPPacket::~OIPPacket() |
269 | { | 269 | { |
270 | } | 270 | } |
271 | 271 | ||
272 | 272 | ||
273 | QHostAddress OIPPacket::fromIPAddress() const | 273 | QHostAddress OIPPacket::fromIPAddress() const |
274 | { | 274 | { |
275 | return EXTRACT_32BITS( &_iphdr->saddr ); | 275 | return EXTRACT_32BITS( &_iphdr->saddr ); |
276 | } | 276 | } |
277 | 277 | ||
278 | 278 | ||
279 | QHostAddress OIPPacket::toIPAddress() const | 279 | QHostAddress OIPPacket::toIPAddress() const |
280 | { | 280 | { |
281 | return EXTRACT_32BITS( &_iphdr->saddr ); | 281 | return EXTRACT_32BITS( &_iphdr->saddr ); |
282 | } | 282 | } |
283 | 283 | ||
284 | 284 | ||
285 | int OIPPacket::tos() const | 285 | int OIPPacket::tos() const |
286 | { | 286 | { |
287 | return _iphdr->tos; | 287 | return _iphdr->tos; |
288 | } | 288 | } |
289 | 289 | ||
290 | 290 | ||
291 | int OIPPacket::len() const | 291 | int OIPPacket::len() const |
292 | { | 292 | { |
293 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 293 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
294 | } | 294 | } |
295 | 295 | ||
296 | 296 | ||
297 | int OIPPacket::id() const | 297 | int OIPPacket::id() const |
298 | { | 298 | { |
299 | return EXTRACT_16BITS( &_iphdr->id ); | 299 | return EXTRACT_16BITS( &_iphdr->id ); |
300 | } | 300 | } |
301 | 301 | ||
302 | 302 | ||
303 | int OIPPacket::offset() const | 303 | int OIPPacket::offset() const |
304 | { | 304 | { |
305 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 305 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
306 | } | 306 | } |
307 | 307 | ||
308 | 308 | ||
309 | int OIPPacket::ttl() const | 309 | int OIPPacket::ttl() const |
310 | { | 310 | { |
311 | return _iphdr->ttl; | 311 | return _iphdr->ttl; |
312 | } | 312 | } |
313 | 313 | ||
314 | 314 | ||
315 | int OIPPacket::protocol() const | 315 | int OIPPacket::protocol() const |
316 | { | 316 | { |
317 | return _iphdr->protocol; | 317 | return _iphdr->protocol; |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
321 | int OIPPacket::checksum() const | 321 | int OIPPacket::checksum() const |
322 | { | 322 | { |
323 | return EXTRACT_16BITS( &_iphdr->check ); | 323 | return EXTRACT_16BITS( &_iphdr->check ); |
324 | } | 324 | } |
325 | 325 | ||
326 | /*====================================================================================== | 326 | /*====================================================================================== |
327 | * OARPPacket | 327 | * OARPPacket |
328 | *======================================================================================*/ | 328 | *======================================================================================*/ |
329 | 329 | ||
330 | 330 | ||
331 | OARPPacket::OARPPacket( const unsigned char* /*end*/, const struct myarphdr* data, QObject* parent ) | 331 | OARPPacket::OARPPacket( const unsigned char* /*end*/, const struct myarphdr* data, QObject* parent ) |
332 | :QObject( parent, "ARP" ), _arphdr( data ) | 332 | :QObject( parent, "ARP" ), _arphdr( data ) |
333 | { | 333 | { |
334 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; | 334 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; |
335 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; | 335 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; |
336 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; | 336 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; |
337 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; | 337 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; |
338 | } | 338 | } |
339 | 339 | ||
340 | 340 | ||
341 | OARPPacket::~OARPPacket() | 341 | OARPPacket::~OARPPacket() |
342 | { | 342 | { |
343 | } | 343 | } |
344 | 344 | ||
345 | 345 | ||
346 | QString OARPPacket::type() const | 346 | QString OARPPacket::type() const |
347 | { | 347 | { |
348 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) | 348 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) |
349 | { | 349 | { |
350 | case 1: return "REQUEST"; | 350 | case 1: return "REQUEST"; |
351 | case 2: return "REPLY"; | 351 | case 2: return "REPLY"; |
352 | case 3: return "RREQUEST"; | 352 | case 3: return "RREQUEST"; |
353 | case 4: return "RREPLY"; | 353 | case 4: return "RREPLY"; |
354 | case 8: return "InREQUEST"; | 354 | case 8: return "InREQUEST"; |
355 | case 9: return "InREPLY"; | 355 | case 9: return "InREPLY"; |
356 | case 10: return "NAK"; | 356 | case 10: return "NAK"; |
357 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; | 357 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; |
358 | } | 358 | } |
359 | } | 359 | } |
360 | 360 | ||
361 | 361 | ||
362 | QHostAddress OARPPacket::senderIPV4Address() const | 362 | QHostAddress OARPPacket::senderIPV4Address() const |
363 | { | 363 | { |
364 | return EXTRACT_32BITS( &_arphdr->ar_sip ); | 364 | return EXTRACT_32BITS( &_arphdr->ar_sip ); |
365 | } | 365 | } |
366 | 366 | ||
367 | 367 | ||
368 | QHostAddress OARPPacket::targetIPV4Address() const | 368 | QHostAddress OARPPacket::targetIPV4Address() const |
369 | { | 369 | { |
370 | return EXTRACT_32BITS( &_arphdr->ar_tip ); | 370 | return EXTRACT_32BITS( &_arphdr->ar_tip ); |
371 | } | 371 | } |
372 | 372 | ||
373 | 373 | ||
374 | OMacAddress OARPPacket::senderMacAddress() const | 374 | OMacAddress OARPPacket::senderMacAddress() const |
375 | { | 375 | { |
376 | return OMacAddress( _arphdr->ar_sha ); | 376 | return OMacAddress( _arphdr->ar_sha ); |
377 | } | 377 | } |
378 | 378 | ||
379 | 379 | ||
380 | OMacAddress OARPPacket::targetMacAddress() const | 380 | OMacAddress OARPPacket::targetMacAddress() const |
381 | { | 381 | { |
382 | return OMacAddress( _arphdr->ar_tha ); | 382 | return OMacAddress( _arphdr->ar_tha ); |
383 | } | 383 | } |
384 | 384 | ||
385 | 385 | ||
386 | /*====================================================================================== | 386 | /*====================================================================================== |
387 | * OUDPPacket | 387 | * OUDPPacket |
388 | *======================================================================================*/ | 388 | *======================================================================================*/ |
389 | 389 | ||
390 | 390 | ||
391 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 391 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
392 | :QObject( parent, "UDP" ), _udphdr( data ) | 392 | :QObject( parent, "UDP" ), _udphdr( data ) |
393 | 393 | ||
394 | { | 394 | { |
395 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; | 395 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; |
396 | odebug << "fromPort = " << fromPort() << oendl; | 396 | odebug << "fromPort = " << fromPort() << oendl; |
397 | odebug << " toPort = " << toPort() << oendl; | 397 | odebug << " toPort = " << toPort() << oendl; |
398 | 398 | ||
399 | // TODO: Make this a case or a hash if we know more udp protocols | 399 | // TODO: Make this a case or a hash if we know more udp protocols |
400 | 400 | ||
401 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || | 401 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || |
402 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) | 402 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) |
403 | { | 403 | { |
404 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; | 404 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; |
405 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); | 405 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); |
406 | } | 406 | } |
407 | } | 407 | } |
408 | 408 | ||
409 | 409 | ||
410 | OUDPPacket::~OUDPPacket() | 410 | OUDPPacket::~OUDPPacket() |
411 | { | 411 | { |
412 | } | 412 | } |
413 | 413 | ||
414 | 414 | ||
415 | int OUDPPacket::fromPort() const | 415 | int OUDPPacket::fromPort() const |
416 | { | 416 | { |
417 | return EXTRACT_16BITS( &_udphdr->source ); | 417 | return EXTRACT_16BITS( &_udphdr->source ); |
418 | } | 418 | } |
419 | 419 | ||
420 | 420 | ||
421 | int OUDPPacket::toPort() const | 421 | int OUDPPacket::toPort() const |
422 | { | 422 | { |
423 | return EXTRACT_16BITS( &_udphdr->dest ); | 423 | return EXTRACT_16BITS( &_udphdr->dest ); |
424 | } | 424 | } |
425 | 425 | ||
426 | 426 | ||
427 | int OUDPPacket::length() const | 427 | int OUDPPacket::length() const |
428 | { | 428 | { |
429 | return EXTRACT_16BITS( &_udphdr->len ); | 429 | return EXTRACT_16BITS( &_udphdr->len ); |
430 | } | 430 | } |
431 | 431 | ||
432 | 432 | ||
433 | int OUDPPacket::checksum() const | 433 | int OUDPPacket::checksum() const |
434 | { | 434 | { |
435 | return EXTRACT_16BITS( &_udphdr->check ); | 435 | return EXTRACT_16BITS( &_udphdr->check ); |
436 | } | 436 | } |
437 | 437 | ||
438 | 438 | ||
439 | /*====================================================================================== | 439 | /*====================================================================================== |
440 | * ODHCPPacket | 440 | * ODHCPPacket |
441 | *======================================================================================*/ | 441 | *======================================================================================*/ |
442 | 442 | ||
443 | 443 | ||
444 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) | 444 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) |
445 | :QObject( parent, "DHCP" ), _dhcphdr( data ) | 445 | :QObject( parent, "DHCP" ), _dhcphdr( data ) |
446 | 446 | ||
447 | { | 447 | { |
448 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; | 448 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; |
449 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; | 449 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; |
450 | odebug << "clientAddress = " << clientAddress().toString() << oendl; | 450 | odebug << "clientAddress = " << clientAddress().toString() << oendl; |
451 | odebug << " yourAddress = " << yourAddress().toString() << oendl; | 451 | odebug << " yourAddress = " << yourAddress().toString() << oendl; |
452 | odebug << "serverAddress = " << serverAddress().toString() << oendl; | 452 | odebug << "serverAddress = " << serverAddress().toString() << oendl; |
453 | odebug << " relayAddress = " << relayAddress().toString() << oendl; | 453 | odebug << " relayAddress = " << relayAddress().toString() << oendl; |
454 | odebug << "parsing DHCP options..." << oendl; | 454 | odebug << "parsing DHCP options..." << oendl; |
455 | 455 | ||
456 | _type = 0; | 456 | _type = 0; |
457 | 457 | ||
458 | const unsigned char* option = &_dhcphdr->options[4]; | 458 | const unsigned char* option = &_dhcphdr->options[4]; |
459 | char tag = -1; | 459 | char tag = -1; |
460 | char len = -1; | 460 | char len = -1; |
461 | 461 | ||
462 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) | 462 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) |
463 | { | 463 | { |
464 | len = *option++; | 464 | len = *option++; |
465 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; | 465 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; |
466 | 466 | ||
467 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) | 467 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) |
468 | _type = *option; | 468 | _type = *option; |
469 | 469 | ||
470 | option += len; | 470 | option += len; |
471 | if ( option >= end ) | 471 | if ( option >= end ) |
472 | { | 472 | { |
473 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; | 473 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; |
474 | break; | 474 | break; |
475 | } | 475 | } |
476 | } | 476 | } |
477 | 477 | ||
478 | odebug << "DHCP type seems to be << " << type() << oendl; | 478 | odebug << "DHCP type seems to be << " << type() << oendl; |
479 | } | 479 | } |
480 | 480 | ||
481 | 481 | ||
482 | ODHCPPacket::~ODHCPPacket() | 482 | ODHCPPacket::~ODHCPPacket() |
483 | { | 483 | { |
484 | } | 484 | } |
485 | 485 | ||
486 | 486 | ||
487 | bool ODHCPPacket::isRequest() const | 487 | bool ODHCPPacket::isRequest() const |
488 | { | 488 | { |
489 | return ( _dhcphdr->op == 01 ); | 489 | return ( _dhcphdr->op == 01 ); |
490 | } | 490 | } |
491 | 491 | ||
492 | 492 | ||
493 | bool ODHCPPacket::isReply() const | 493 | bool ODHCPPacket::isReply() const |
494 | { | 494 | { |
495 | return ( _dhcphdr->op == 02 ); | 495 | return ( _dhcphdr->op == 02 ); |
496 | } | 496 | } |
497 | 497 | ||
498 | 498 | ||
499 | QString ODHCPPacket::type() const | 499 | QString ODHCPPacket::type() const |
500 | { | 500 | { |
501 | switch ( _type ) | 501 | switch ( _type ) |
502 | { | 502 | { |
503 | case 1: return "DISCOVER"; | 503 | case 1: return "DISCOVER"; |
504 | case 2: return "OFFER"; | 504 | case 2: return "OFFER"; |
505 | case 3: return "REQUEST"; | 505 | case 3: return "REQUEST"; |
506 | case 4: return "DECLINE"; | 506 | case 4: return "DECLINE"; |
507 | case 5: return "ACK"; | 507 | case 5: return "ACK"; |
508 | case 6: return "NAK"; | 508 | case 6: return "NAK"; |
509 | case 7: return "RELEASE"; | 509 | case 7: return "RELEASE"; |
510 | case 8: return "INFORM"; | 510 | case 8: return "INFORM"; |
511 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; | 511 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; |
512 | } | 512 | } |
513 | } | 513 | } |
514 | 514 | ||
515 | 515 | ||
516 | QHostAddress ODHCPPacket::clientAddress() const | 516 | QHostAddress ODHCPPacket::clientAddress() const |
517 | { | 517 | { |
518 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); | 518 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); |
519 | } | 519 | } |
520 | 520 | ||
521 | 521 | ||
522 | QHostAddress ODHCPPacket::yourAddress() const | 522 | QHostAddress ODHCPPacket::yourAddress() const |
523 | { | 523 | { |
524 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); | 524 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); |
525 | } | 525 | } |
526 | 526 | ||
527 | 527 | ||
528 | QHostAddress ODHCPPacket::serverAddress() const | 528 | QHostAddress ODHCPPacket::serverAddress() const |
529 | { | 529 | { |
530 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); | 530 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); |
531 | } | 531 | } |
532 | 532 | ||
533 | 533 | ||
534 | QHostAddress ODHCPPacket::relayAddress() const | 534 | QHostAddress ODHCPPacket::relayAddress() const |
535 | { | 535 | { |
536 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); | 536 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); |
537 | } | 537 | } |
538 | 538 | ||
539 | 539 | ||
540 | OMacAddress ODHCPPacket::clientMacAddress() const | 540 | OMacAddress ODHCPPacket::clientMacAddress() const |
541 | { | 541 | { |
542 | return OMacAddress( _dhcphdr->chaddr ); | 542 | return OMacAddress( _dhcphdr->chaddr ); |
543 | } | 543 | } |
544 | 544 | ||
545 | 545 | ||
546 | /*====================================================================================== | 546 | /*====================================================================================== |
547 | * OTCPPacket | 547 | * OTCPPacket |
548 | *======================================================================================*/ | 548 | *======================================================================================*/ |
549 | 549 | ||
550 | 550 | ||
551 | OTCPPacket::OTCPPacket( const unsigned char* /*end*/, const struct tcphdr* data, QObject* parent ) | 551 | OTCPPacket::OTCPPacket( const unsigned char* /*end*/, const struct tcphdr* data, QObject* parent ) |
552 | :QObject( parent, "TCP" ), _tcphdr( data ) | 552 | :QObject( parent, "TCP" ), _tcphdr( data ) |
553 | 553 | ||
554 | { | 554 | { |
555 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; | 555 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; |
556 | } | 556 | } |
557 | 557 | ||
558 | 558 | ||
559 | OTCPPacket::~OTCPPacket() | 559 | OTCPPacket::~OTCPPacket() |
560 | { | 560 | { |
561 | } | 561 | } |
562 | 562 | ||
563 | 563 | ||
564 | int OTCPPacket::fromPort() const | 564 | int OTCPPacket::fromPort() const |
565 | { | 565 | { |
566 | return EXTRACT_16BITS( &_tcphdr->source ); | 566 | return EXTRACT_16BITS( &_tcphdr->source ); |
567 | } | 567 | } |
568 | 568 | ||
569 | 569 | ||
570 | int OTCPPacket::toPort() const | 570 | int OTCPPacket::toPort() const |
571 | { | 571 | { |
572 | return EXTRACT_16BITS( &_tcphdr->dest ); | 572 | return EXTRACT_16BITS( &_tcphdr->dest ); |
573 | } | 573 | } |
574 | 574 | ||
575 | 575 | ||
576 | int OTCPPacket::seq() const | 576 | int OTCPPacket::seq() const |
577 | { | 577 | { |
578 | return EXTRACT_16BITS( &_tcphdr->seq ); | 578 | return EXTRACT_16BITS( &_tcphdr->seq ); |
579 | } | 579 | } |
580 | 580 | ||
581 | 581 | ||
582 | int OTCPPacket::ack() const | 582 | int OTCPPacket::ack() const |
583 | { | 583 | { |
584 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); | 584 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); |
585 | } | 585 | } |
586 | 586 | ||
587 | 587 | ||
588 | int OTCPPacket::window() const | 588 | int OTCPPacket::window() const |
589 | { | 589 | { |
590 | return EXTRACT_16BITS( &_tcphdr->window ); | 590 | return EXTRACT_16BITS( &_tcphdr->window ); |
591 | } | 591 | } |
592 | 592 | ||
593 | 593 | ||
594 | int OTCPPacket::checksum() const | 594 | int OTCPPacket::checksum() const |
595 | { | 595 | { |
596 | return EXTRACT_16BITS( &_tcphdr->check ); | 596 | return EXTRACT_16BITS( &_tcphdr->check ); |
597 | } | 597 | } |
598 | 598 | ||
599 | /*====================================================================================== | 599 | /*====================================================================================== |
600 | * OPrismHeaderPacket | 600 | * OPrismHeaderPacket |
601 | *======================================================================================*/ | 601 | *======================================================================================*/ |
602 | 602 | ||
603 | 603 | ||
604 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | 604 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) |
605 | :QObject( parent, "Prism" ), _header( data ) | 605 | :QObject( parent, "Prism" ), _header( data ) |
606 | 606 | ||
607 | { | 607 | { |
608 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; | 608 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; |
609 | 609 | ||
610 | odebug << "Signal Strength = " << data->signal.data << oendl; | 610 | odebug << "Signal Strength = " << data->signal.data << oendl; |
611 | 611 | ||
612 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); | 612 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); |
613 | } | 613 | } |
614 | 614 | ||
615 | OPrismHeaderPacket::~OPrismHeaderPacket() | 615 | OPrismHeaderPacket::~OPrismHeaderPacket() |
616 | { | 616 | { |
617 | } | 617 | } |
618 | 618 | ||
619 | 619 | ||
620 | unsigned int OPrismHeaderPacket::signalStrength() const | 620 | unsigned int OPrismHeaderPacket::signalStrength() const |
621 | { | 621 | { |
622 | return _header->signal.data; | 622 | return _header->signal.data; |
623 | } | 623 | } |
624 | 624 | ||
625 | /*====================================================================================== | 625 | /*====================================================================================== |
626 | * OWaveLanPacket | 626 | * OWaveLanPacket |
627 | *======================================================================================*/ | 627 | *======================================================================================*/ |
628 | 628 | ||
629 | 629 | ||
630 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | 630 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
631 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 631 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
632 | 632 | ||
633 | { | 633 | { |
634 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; | 634 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; |
635 | odebug << "type = " << type() << oendl; | 635 | odebug << "type = " << type() << oendl; |
636 | odebug << "subType = " << subType() << oendl; | 636 | odebug << "subType = " << subType() << oendl; |
637 | odebug << "duration = " << duration() << oendl; | 637 | odebug << "duration = " << duration() << oendl; |
638 | odebug << "powermanagement = " << usesPowerManagement() << oendl; | 638 | odebug << "powermanagement = " << usesPowerManagement() << oendl; |
639 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; | 639 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; |
640 | odebug << "MAC1 = " << macAddress1().toString() << oendl; | 640 | odebug << "MAC1 = " << macAddress1().toString() << oendl; |
641 | odebug << "MAC2 = " << macAddress2().toString() << oendl; | 641 | odebug << "MAC2 = " << macAddress2().toString() << oendl; |
642 | odebug << "MAC3 = " << macAddress3().toString() << oendl; | 642 | odebug << "MAC3 = " << macAddress3().toString() << oendl; |
643 | odebug << "MAC4 = " << macAddress4().toString() << oendl; | 643 | odebug << "MAC4 = " << macAddress4().toString() << oendl; |
644 | 644 | ||
645 | switch ( type() ) | 645 | switch ( type() ) |
646 | { | 646 | { |
647 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 647 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
648 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 648 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
649 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 649 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
650 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; | 650 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; |
651 | } | 651 | } |
652 | } | 652 | } |
653 | 653 | ||
654 | OWaveLanPacket::~OWaveLanPacket() | 654 | OWaveLanPacket::~OWaveLanPacket() |
655 | { | 655 | { |
656 | } | 656 | } |
657 | 657 | ||
658 | 658 | ||
659 | int OWaveLanPacket::duration() const | 659 | int OWaveLanPacket::duration() const |
660 | { | 660 | { |
661 | return _wlanhdr->duration; | 661 | return _wlanhdr->duration; |
662 | } | 662 | } |
663 | 663 | ||
664 | 664 | ||
665 | OMacAddress OWaveLanPacket::macAddress1() const | 665 | OMacAddress OWaveLanPacket::macAddress1() const |
666 | { | 666 | { |
667 | return OMacAddress( _wlanhdr->mac1 ); | 667 | return OMacAddress( _wlanhdr->mac1 ); |
668 | } | 668 | } |
669 | 669 | ||
670 | 670 | ||
671 | OMacAddress OWaveLanPacket::macAddress2() const | 671 | OMacAddress OWaveLanPacket::macAddress2() const |
672 | { | 672 | { |
673 | return OMacAddress( _wlanhdr->mac2 ); | 673 | return OMacAddress( _wlanhdr->mac2 ); |
674 | } | 674 | } |
675 | 675 | ||
676 | 676 | ||
677 | OMacAddress OWaveLanPacket::macAddress3() const | 677 | OMacAddress OWaveLanPacket::macAddress3() const |
678 | { | 678 | { |
679 | return OMacAddress( _wlanhdr->mac3 ); | 679 | return OMacAddress( _wlanhdr->mac3 ); |
680 | } | 680 | } |
681 | 681 | ||
682 | 682 | ||
683 | OMacAddress OWaveLanPacket::macAddress4() const | 683 | OMacAddress OWaveLanPacket::macAddress4() const |
684 | { | 684 | { |
685 | return OMacAddress( _wlanhdr->mac4 ); | 685 | return OMacAddress( _wlanhdr->mac4 ); |
686 | } | 686 | } |
687 | 687 | ||
688 | 688 | ||
689 | int OWaveLanPacket::subType() const | 689 | int OWaveLanPacket::subType() const |
690 | { | 690 | { |
691 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 691 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
692 | } | 692 | } |
693 | 693 | ||
694 | 694 | ||
695 | int OWaveLanPacket::type() const | 695 | int OWaveLanPacket::type() const |
696 | { | 696 | { |
697 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 697 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
698 | } | 698 | } |
699 | 699 | ||
700 | 700 | ||
701 | int OWaveLanPacket::version() const | 701 | int OWaveLanPacket::version() const |
702 | { | 702 | { |
703 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 703 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
704 | } | 704 | } |
705 | 705 | ||
706 | 706 | ||
707 | bool OWaveLanPacket::fromDS() const | 707 | bool OWaveLanPacket::fromDS() const |
708 | { | 708 | { |
709 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 709 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
710 | } | 710 | } |
711 | 711 | ||
712 | 712 | ||
713 | bool OWaveLanPacket::toDS() const | 713 | bool OWaveLanPacket::toDS() const |
714 | { | 714 | { |
715 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 715 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
716 | } | 716 | } |
717 | 717 | ||
718 | 718 | ||
719 | bool OWaveLanPacket::usesPowerManagement() const | 719 | bool OWaveLanPacket::usesPowerManagement() const |
720 | { | 720 | { |
721 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 721 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
722 | } | 722 | } |
723 | 723 | ||
724 | 724 | ||
725 | bool OWaveLanPacket::usesWep() const | 725 | bool OWaveLanPacket::usesWep() const |
726 | { | 726 | { |
727 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 727 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
728 | } | 728 | } |
729 | 729 | ||
730 | 730 | ||
731 | /*====================================================================================== | 731 | /*====================================================================================== |
732 | * OWaveLanManagementPacket | 732 | * OWaveLanManagementPacket |
733 | *======================================================================================*/ | 733 | *======================================================================================*/ |
734 | 734 | ||
735 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 735 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
736 | :QObject( parent, "802.11 Management" ), _header( data ), | 736 | :QObject( parent, "802.11 Management" ), _header( data ), |
737 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 737 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
738 | { | 738 | { |
739 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; | 739 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; |
740 | odebug << "Detected subtype is " << managementType() << oendl; | 740 | odebug << "Detected subtype is " << managementType() << oendl; |
741 | 741 | ||
742 | // Grab tagged values. | 742 | // Grab tagged values. |
743 | // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, | 743 | // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, |
744 | // Other management frames don't - which is why we have to inspect the subtype here. | 744 | // Other management frames don't - which is why we have to inspect the subtype here. |
745 | 745 | ||
746 | const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); | 746 | const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); |
747 | 747 | ||
748 | while (ptr < end) | 748 | while (ptr < end) |
749 | { | 749 | { |
750 | switch ( *ptr ) | 750 | switch ( *ptr ) |
751 | { | 751 | { |
752 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | 752 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; |
753 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | 753 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; |
754 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | 754 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; |
755 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | 755 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; |
756 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | 756 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; |
757 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | 757 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; |
758 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | 758 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; |
759 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | 759 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; |
760 | } | 760 | } |
761 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | 761 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value |
762 | ptr+= 2; // skip tag ID and length | 762 | ptr+= 2; // skip tag ID and length |
763 | } | 763 | } |
764 | } | 764 | } |
765 | 765 | ||
766 | 766 | ||
767 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 767 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
768 | { | 768 | { |
769 | } | 769 | } |
770 | 770 | ||
771 | 771 | ||
772 | QString OWaveLanManagementPacket::managementType() const | 772 | QString OWaveLanManagementPacket::managementType() const |
773 | { | 773 | { |
774 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 774 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
775 | { | 775 | { |
776 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 776 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
777 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 777 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
778 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 778 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
779 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 779 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
780 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 780 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 9e718d5..149e573 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -1,733 +1,733 @@ | |||
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 by Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef OPCAP_H | 31 | #ifndef OPCAP_H |
32 | #define OPCAP_H | 32 | #define OPCAP_H |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/onetutils.h> | 35 | #include <opie2/onetutils.h> |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | #include <qevent.h> | 38 | #include <qevent.h> |
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include <qhostaddress.h> | 40 | #include <qhostaddress.h> |
41 | #include <qobject.h> | 41 | #include <qobject.h> |
42 | #include <qstring.h> | 42 | #include <qstring.h> |
43 | #include <qtextstream.h> | 43 | #include <qtextstream.h> |
44 | #include <qmap.h> | 44 | #include <qmap.h> |
45 | 45 | ||
46 | /* STD */ | 46 | /* STD */ |
47 | extern "C" // work around a bpf/pcap conflict in recent headers | 47 | extern "C" // work around a bpf/pcap conflict in recent headers |
48 | { | 48 | { |
49 | #include <pcap.h> | 49 | #include <pcap.h> |
50 | } | 50 | } |
51 | #include <netinet/ether.h> | 51 | #include <netinet/ether.h> |
52 | #include <netinet/ip.h> | 52 | #include <netinet/ip.h> |
53 | #include <netinet/udp.h> | 53 | #include <netinet/udp.h> |
54 | #include <netinet/tcp.h> | 54 | #include <netinet/tcp.h> |
55 | #include <time.h> | 55 | #include <time.h> |
56 | 56 | ||
57 | /* Custom Network Includes (must go here, don't reorder!) */ | 57 | /* Custom Network Includes (must go here, don't reorder!) */ |
58 | #include "802_11_user.h" | 58 | #include "802_11_user.h" |
59 | #include "dhcp.h" | 59 | #include "dhcp.h" |
60 | 60 | ||
61 | 61 | ||
62 | /* TYPEDEFS */ | 62 | /* TYPEDEFS */ |
63 | typedef struct timeval timevalstruct; | 63 | typedef struct timeval timevalstruct; |
64 | typedef struct pcap_pkthdr packetheaderstruct; | 64 | typedef struct pcap_pkthdr packetheaderstruct; |
65 | 65 | ||
66 | /* FORWARDS */ | 66 | /* FORWARDS */ |
67 | class QSocketNotifier; | 67 | class QSocketNotifier; |
68 | namespace Opie { | 68 | namespace Opie { |
69 | namespace Net { | 69 | namespace Net { |
70 | class OPacketCapturer; | 70 | class OPacketCapturer; |
71 | 71 | ||
72 | /*====================================================================================== | 72 | /*====================================================================================== |
73 | * OPacket - A frame on the wire | 73 | * OPacket - A frame on the wire |
74 | *======================================================================================*/ | 74 | *======================================================================================*/ |
75 | 75 | ||
76 | /** @brief A class representing a data frame on the wire. | 76 | /** @brief A class representing a data frame on the wire. |
77 | * | 77 | * |
78 | * The whole family of the packet classes are used when capturing frames from a network. | 78 | * The whole family of the packet classes are used when capturing frames from a network. |
79 | * Most standard network protocols in use share a common architecture, which mostly is | 79 | * Most standard network protocols in use share a common architecture, which mostly is |
80 | * a packet header and then the packet payload. In layered architectures, each lower layer | 80 | * a packet header and then the packet payload. In layered architectures, each lower layer |
81 | * encapsulates data from its upper layer - that is it | 81 | * encapsulates data from its upper layer - that is it |
82 | * treats the data from its upper layer as payload and prepends an own header to the packet, | 82 | * treats the data from its upper layer as payload and prepends an own header to the packet, |
83 | * which - again - is treated as the payload for the layer below. The figure below is an | 83 | * which - again - is treated as the payload for the layer below. The figure below is an |
84 | * example for how such a data frame is composed out of packets, e.g. when sending a mail. | 84 | * example for how such a data frame is composed out of packets, e.g. when sending a mail. |
85 | * | 85 | * |
86 | * <pre> | 86 | * <pre> |
87 | * | User Data | == Mail Data | 87 | * | User Data | == Mail Data |
88 | * | SMTP Header | User Data | == SMTP | 88 | * | SMTP Header | User Data | == SMTP |
89 | * | TCP Header | SMTP Header | User Data | == TCP | 89 | * | TCP Header | SMTP Header | User Data | == TCP |
90 | * | IP Header | TCP Header | SMTP Header | User Data | == IP | 90 | * | IP Header | TCP Header | SMTP Header | User Data | == IP |
91 | * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC | 91 | * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC |
92 | * | 92 | * |
93 | * </pre> | 93 | * </pre> |
94 | * | 94 | * |
95 | * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer | 95 | * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer |
96 | * also contains a few more levels of encapsulation. | 96 | * also contains a few more levels of encapsulation. |
97 | * Since the type of the payload is more or less independent from the encapsulating protocol, | 97 | * Since the type of the payload is more or less independent from the encapsulating protocol, |
98 | * the header must be inspected before attempting to decode the payload. Hence, the | 98 | * the header must be inspected before attempting to decode the payload. Hence, the |
99 | * encapsulation level varies and can't be deduced without actually looking into the packets. | 99 | * encapsulation level varies and can't be deduced without actually looking into the packets. |
100 | * | 100 | * |
101 | * For actually working with captured frames, it's useful to identify the packets via names and | 101 | * For actually working with captured frames, it's useful to identify the packets via names and |
102 | * insert them into a parent/child - relationship based on the encapsulation. This is why | 102 | * insert them into a parent/child - relationship based on the encapsulation. This is why |
103 | * all packet classes derive from QObject. The amount of overhead caused by the QObject is | 103 | * all packet classes derive from QObject. The amount of overhead caused by the QObject is |
104 | * not a problem in this case, because we're talking about a theoratical maximum of about | 104 | * not a problem in this case, because we're talking about a theoratical maximum of about |
105 | * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the | 105 | * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the |
106 | * QObject also cares about destroying the sub-, (child-) packets. | 106 | * QObject also cares about destroying the sub-, (child-) packets. |
107 | * | 107 | * |
108 | * This enables us to perform a simple look for packets of a certain type: | 108 | * This enables us to perform a simple look for packets of a certain type: |
109 | * @code | 109 | * @code |
110 | * OPacketCapturer* pcap = new OPacketCapturer(); | 110 | * OPacketCapturer* pcap = new OPacketCapturer(); |
111 | * pcap->open( "eth0" ); | 111 | * pcap->open( "eth0" ); |
112 | * OPacket* p = pcap->next(); | 112 | * OPacket* p = pcap->next(); |
113 | * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists | 113 | * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists |
114 | * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; | 114 | * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; |
115 | * | 115 | * |
116 | */ | 116 | */ |
117 | 117 | ||
118 | class OPacket : public QObject | 118 | class OPacket : public QObject |
119 | { | 119 | { |
120 | Q_OBJECT | 120 | Q_OBJECT |
121 | 121 | ||
122 | friend class OPacketCapturer; | 122 | friend class OPacketCapturer; |
123 | friend QTextStream& operator<<( QTextStream& s, const OPacket& p ); | 123 | friend QTextStream& operator<<( QTextStream& s, const OPacket& p ); |
124 | 124 | ||
125 | public: | 125 | public: |
126 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); | 126 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); |
127 | virtual ~OPacket(); | 127 | virtual ~OPacket(); |
128 | 128 | ||
129 | timevalstruct timeval() const; | 129 | timevalstruct timeval() const; |
130 | 130 | ||
131 | int caplen() const; | 131 | int caplen() const; |
132 | int len() const; | 132 | int len() const; |
133 | QString dump( int = 32 ) const; //FIXME: remove that | 133 | QString dump( int = 32 ) const; //FIXME: remove that |
134 | 134 | ||
135 | void updateStats( QMap<QString,int>&, QObjectList* ); //FIXME: Revise | 135 | void updateStats( QMap<QString,int>&, QObjectList* ); //FIXME: Revise |
136 | 136 | ||
137 | QString dumpStructure() const; //FIXME: Revise | 137 | QString dumpStructure() const; //FIXME: Revise |
138 | private: | 138 | private: |
139 | QString _dumpStructure( QObjectList* ) const; //FIXME: Revise | 139 | QString _dumpStructure( QObjectList* ) const; //FIXME: Revise |
140 | 140 | ||
141 | private: | 141 | private: |
142 | const packetheaderstruct _hdr; // pcap packet header | 142 | const packetheaderstruct _hdr; // pcap packet header |
143 | const unsigned char* _data; // pcap packet data | 143 | const unsigned char* _data; // pcap packet data |
144 | const unsigned char* _end; // end of pcap packet data | 144 | const unsigned char* _end; // end of pcap packet data |
145 | private: | 145 | private: |
146 | class Private; | 146 | class Private; |
147 | Private *d; | 147 | Private *d; |
148 | }; | 148 | }; |
149 | 149 | ||
150 | QTextStream& operator<<( QTextStream& s, const OPacket& p ); //FIXME: Revise | 150 | QTextStream& operator<<( QTextStream& s, const OPacket& p ); //FIXME: Revise |
151 | 151 | ||
152 | /*====================================================================================== | 152 | /*====================================================================================== |
153 | * OEthernetPacket - DLT_EN10MB frame | 153 | * OEthernetPacket - DLT_EN10MB frame |
154 | *======================================================================================*/ | 154 | *======================================================================================*/ |
155 | 155 | ||
156 | class OEthernetPacket : public QObject | 156 | class OEthernetPacket : public QObject |
157 | { | 157 | { |
158 | Q_OBJECT | 158 | Q_OBJECT |
159 | 159 | ||
160 | public: | 160 | public: |
161 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); | 161 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
162 | virtual ~OEthernetPacket(); | 162 | virtual ~OEthernetPacket(); |
163 | 163 | ||
164 | OMacAddress sourceAddress() const; | 164 | OMacAddress sourceAddress() const; |
165 | OMacAddress destinationAddress() const; | 165 | OMacAddress destinationAddress() const; |
166 | int type() const; | 166 | int type() const; |
167 | 167 | ||
168 | private: | 168 | private: |
169 | const struct ether_header* _ether; | 169 | const struct ether_header* _ether; |
170 | private: | 170 | private: |
171 | class Private; | 171 | class Private; |
172 | Private *d; | 172 | Private *d; |
173 | }; | 173 | }; |
174 | 174 | ||
175 | /*====================================================================================== | 175 | /*====================================================================================== |
176 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame | 176 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame |
177 | *======================================================================================*/ | 177 | *======================================================================================*/ |
178 | 178 | ||
179 | class OPrismHeaderPacket : public QObject | 179 | class OPrismHeaderPacket : public QObject |
180 | { | 180 | { |
181 | Q_OBJECT | 181 | Q_OBJECT |
182 | 182 | ||
183 | public: | 183 | public: |
184 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); | 184 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); |
185 | virtual ~OPrismHeaderPacket(); | 185 | virtual ~OPrismHeaderPacket(); |
186 | 186 | ||
187 | unsigned int signalStrength() const; | 187 | unsigned int signalStrength() const; |
188 | 188 | ||
189 | private: | 189 | private: |
190 | const struct prism_hdr* _header; | 190 | const struct prism_hdr* _header; |
191 | class Private; | 191 | class Private; |
192 | Private *d; | 192 | Private *d; |
193 | }; | 193 | }; |
194 | 194 | ||
195 | /*====================================================================================== | 195 | /*====================================================================================== |
196 | * OWaveLanPacket - DLT_IEEE802_11 frame | 196 | * OWaveLanPacket - DLT_IEEE802_11 frame |
197 | *======================================================================================*/ | 197 | *======================================================================================*/ |
198 | 198 | ||
199 | class OWaveLanPacket : public QObject | 199 | class OWaveLanPacket : public QObject |
200 | { | 200 | { |
201 | Q_OBJECT | 201 | Q_OBJECT |
202 | 202 | ||
203 | public: | 203 | public: |
204 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); | 204 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); |
205 | virtual ~OWaveLanPacket(); | 205 | virtual ~OWaveLanPacket(); |
206 | 206 | ||
207 | int duration() const; | 207 | int duration() const; |
208 | bool fromDS() const; | 208 | bool fromDS() const; |
209 | bool toDS() const; | 209 | bool toDS() const; |
210 | virtual OMacAddress macAddress1() const; | 210 | virtual OMacAddress macAddress1() const; |
211 | virtual OMacAddress macAddress2() const; | 211 | virtual OMacAddress macAddress2() const; |
212 | virtual OMacAddress macAddress3() const; | 212 | virtual OMacAddress macAddress3() const; |
213 | virtual OMacAddress macAddress4() const; | 213 | virtual OMacAddress macAddress4() const; |
214 | bool usesPowerManagement() const; | 214 | bool usesPowerManagement() const; |
215 | int type() const; | 215 | int type() const; |
216 | int subType() const; | 216 | int subType() const; |
217 | int version() const; | 217 | int version() const; |
218 | bool usesWep() const; | 218 | bool usesWep() const; |
219 | 219 | ||
220 | private: | 220 | private: |
221 | const struct ieee_802_11_header* _wlanhdr; | 221 | const struct ieee_802_11_header* _wlanhdr; |
222 | class Private; | 222 | class Private; |
223 | Private *d; | 223 | Private *d; |
224 | }; | 224 | }; |
225 | 225 | ||
226 | 226 | ||
227 | /*====================================================================================== | 227 | /*====================================================================================== |
228 | * OWaveLanManagementPacket - type: management (T_MGMT) | 228 | * OWaveLanManagementPacket - type: management (T_MGMT) |
229 | *======================================================================================*/ | 229 | *======================================================================================*/ |
230 | 230 | ||
231 | class OWaveLanManagementPacket : public QObject | 231 | class OWaveLanManagementPacket : public QObject |
232 | { | 232 | { |
233 | Q_OBJECT | 233 | Q_OBJECT |
234 | 234 | ||
235 | public: | 235 | public: |
236 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); | 236 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); |
237 | virtual ~OWaveLanManagementPacket(); | 237 | virtual ~OWaveLanManagementPacket(); |
238 | 238 | ||
239 | QString managementType() const; | 239 | QString managementType() const; |
240 | 240 | ||
241 | int beaconInterval() const; | 241 | int beaconInterval() const; |
242 | int capabilities() const; // generic | 242 | int capabilities() const; // generic |
243 | 243 | ||
244 | bool canESS() const; | 244 | bool canESS() const; |
245 | bool canIBSS() const; | 245 | bool canIBSS() const; |
246 | bool canCFP() const; | 246 | bool canCFP() const; |
247 | bool canCFP_REQ() const; | 247 | bool canCFP_REQ() const; |
248 | bool canPrivacy() const; | 248 | bool canPrivacy() const; |
249 | 249 | ||
250 | private: | 250 | private: |
251 | const struct ieee_802_11_mgmt_header* _header; | 251 | const struct ieee_802_11_mgmt_header* _header; |
252 | const struct ieee_802_11_mgmt_body* _body; | 252 | const struct ieee_802_11_mgmt_body* _body; |
253 | class Private; | 253 | class Private; |
254 | Private *d; | 254 | Private *d; |
255 | }; | 255 | }; |
256 | 256 | ||
257 | 257 | ||
258 | /*====================================================================================== | 258 | /*====================================================================================== |
259 | * OWaveLanManagementSSID | 259 | * OWaveLanManagementSSID |
260 | *======================================================================================*/ | 260 | *======================================================================================*/ |
261 | 261 | ||
262 | class OWaveLanManagementSSID : public QObject | 262 | class OWaveLanManagementSSID : public QObject |
263 | { | 263 | { |
264 | Q_OBJECT | 264 | Q_OBJECT |
265 | 265 | ||
266 | public: | 266 | public: |
267 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); | 267 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); |
268 | virtual ~OWaveLanManagementSSID(); | 268 | virtual ~OWaveLanManagementSSID(); |
269 | 269 | ||
270 | QString ID( bool decloak = false ) const; | 270 | QString ID( bool decloak = false ) const; |
271 | 271 | ||
272 | private: | 272 | private: |
273 | const struct ssid_t* _data; | 273 | const struct ssid_t* _data; |
274 | class Private; | 274 | class Private; |
275 | Private *d; | 275 | Private *d; |
276 | }; | 276 | }; |
277 | 277 | ||
278 | /*====================================================================================== | 278 | /*====================================================================================== |
279 | * OWaveLanManagementRates | 279 | * OWaveLanManagementRates |
280 | *======================================================================================*/ | 280 | *======================================================================================*/ |
281 | 281 | ||
282 | class OWaveLanManagementRates : public QObject | 282 | class OWaveLanManagementRates : public QObject |
283 | { | 283 | { |
284 | Q_OBJECT | 284 | Q_OBJECT |
285 | 285 | ||
286 | public: | 286 | public: |
287 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); | 287 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); |
288 | virtual ~OWaveLanManagementRates(); | 288 | virtual ~OWaveLanManagementRates(); |
289 | 289 | ||
290 | private: | 290 | private: |
291 | const struct rates_t* _data; | 291 | const struct rates_t* _data; |
292 | class Private; | 292 | class Private; |
293 | Private *d; | 293 | Private *d; |
294 | }; | 294 | }; |
295 | 295 | ||
296 | /*====================================================================================== | 296 | /*====================================================================================== |
297 | * OWaveLanManagementCF | 297 | * OWaveLanManagementCF |
298 | *======================================================================================*/ | 298 | *======================================================================================*/ |
299 | 299 | ||
300 | class OWaveLanManagementCF : public QObject | 300 | class OWaveLanManagementCF : public QObject |
301 | { | 301 | { |
302 | Q_OBJECT | 302 | Q_OBJECT |
303 | 303 | ||
304 | public: | 304 | public: |
305 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); | 305 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); |
306 | virtual ~OWaveLanManagementCF(); | 306 | virtual ~OWaveLanManagementCF(); |
307 | 307 | ||
308 | private: | 308 | private: |
309 | const struct cf_t* _data; | 309 | const struct cf_t* _data; |
310 | class Private; | 310 | class Private; |
311 | Private *d; | 311 | Private *d; |
312 | }; | 312 | }; |
313 | 313 | ||
314 | /*====================================================================================== | 314 | /*====================================================================================== |
315 | * OWaveLanManagementFH | 315 | * OWaveLanManagementFH |
316 | *======================================================================================*/ | 316 | *======================================================================================*/ |
317 | 317 | ||
318 | class OWaveLanManagementFH : public QObject | 318 | class OWaveLanManagementFH : public QObject |
319 | { | 319 | { |
320 | Q_OBJECT | 320 | Q_OBJECT |
321 | 321 | ||
322 | public: | 322 | public: |
323 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); | 323 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); |
324 | virtual ~OWaveLanManagementFH(); | 324 | virtual ~OWaveLanManagementFH(); |
325 | 325 | ||
326 | private: | 326 | private: |
327 | const struct fh_t* _data; | 327 | const struct fh_t* _data; |
328 | class Private; | 328 | class Private; |
329 | Private *d; | 329 | Private *d; |
330 | }; | 330 | }; |
331 | 331 | ||
332 | /*====================================================================================== | 332 | /*====================================================================================== |
333 | * OWaveLanManagementDS | 333 | * OWaveLanManagementDS |
334 | *======================================================================================*/ | 334 | *======================================================================================*/ |
335 | 335 | ||
336 | class OWaveLanManagementDS : public QObject | 336 | class OWaveLanManagementDS : public QObject |
337 | { | 337 | { |
338 | Q_OBJECT | 338 | Q_OBJECT |
339 | 339 | ||
340 | public: | 340 | public: |
341 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); | 341 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); |
342 | virtual ~OWaveLanManagementDS(); | 342 | virtual ~OWaveLanManagementDS(); |
343 | 343 | ||
344 | int channel() const; | 344 | int channel() const; |
345 | 345 | ||
346 | private: | 346 | private: |
347 | const struct ds_t* _data; | 347 | const struct ds_t* _data; |
348 | class Private; | 348 | class Private; |
349 | Private *d; | 349 | Private *d; |
350 | }; | 350 | }; |
351 | 351 | ||
352 | /*====================================================================================== | 352 | /*====================================================================================== |
353 | * OWaveLanManagementTim | 353 | * OWaveLanManagementTim |
354 | *======================================================================================*/ | 354 | *======================================================================================*/ |
355 | 355 | ||
356 | class OWaveLanManagementTim : public QObject | 356 | class OWaveLanManagementTim : public QObject |
357 | { | 357 | { |
358 | Q_OBJECT | 358 | Q_OBJECT |
359 | 359 | ||
360 | public: | 360 | public: |
361 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); | 361 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); |
362 | virtual ~OWaveLanManagementTim(); | 362 | virtual ~OWaveLanManagementTim(); |
363 | 363 | ||
364 | private: | 364 | private: |
365 | const struct tim_t* _data; | 365 | const struct tim_t* _data; |
366 | class Private; | 366 | class Private; |
367 | Private *d; | 367 | Private *d; |
368 | }; | 368 | }; |
369 | 369 | ||
370 | /*====================================================================================== | 370 | /*====================================================================================== |
371 | * OWaveLanManagementIBSS | 371 | * OWaveLanManagementIBSS |
372 | *======================================================================================*/ | 372 | *======================================================================================*/ |
373 | 373 | ||
374 | class OWaveLanManagementIBSS : public QObject | 374 | class OWaveLanManagementIBSS : public QObject |
375 | { | 375 | { |
376 | Q_OBJECT | 376 | Q_OBJECT |
377 | 377 | ||
378 | public: | 378 | public: |
379 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); | 379 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); |
380 | virtual ~OWaveLanManagementIBSS(); | 380 | virtual ~OWaveLanManagementIBSS(); |
381 | 381 | ||
382 | private: | 382 | private: |
383 | const struct ibss_t* _data; | 383 | const struct ibss_t* _data; |
384 | class Private; | 384 | class Private; |
385 | Private *d; | 385 | Private *d; |
386 | }; | 386 | }; |
387 | 387 | ||
388 | /*====================================================================================== | 388 | /*====================================================================================== |
389 | * OWaveLanManagementChallenge | 389 | * OWaveLanManagementChallenge |
390 | *======================================================================================*/ | 390 | *======================================================================================*/ |
391 | 391 | ||
392 | class OWaveLanManagementChallenge : public QObject | 392 | class OWaveLanManagementChallenge : public QObject |
393 | { | 393 | { |
394 | Q_OBJECT | 394 | Q_OBJECT |
395 | 395 | ||
396 | public: | 396 | public: |
397 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); | 397 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); |
398 | virtual ~OWaveLanManagementChallenge(); | 398 | virtual ~OWaveLanManagementChallenge(); |
399 | 399 | ||
400 | private: | 400 | private: |
401 | const struct challenge_t* _data; | 401 | const struct challenge_t* _data; |
402 | class Private; | 402 | class Private; |
403 | Private *d; | 403 | Private *d; |
404 | }; | 404 | }; |
405 | 405 | ||
406 | /*====================================================================================== | 406 | /*====================================================================================== |
407 | * OWaveLanDataPacket - type: data (T_DATA) | 407 | * OWaveLanDataPacket - type: data (T_DATA) |
408 | *======================================================================================*/ | 408 | *======================================================================================*/ |
409 | 409 | ||
410 | class OWaveLanDataPacket : public QObject | 410 | class OWaveLanDataPacket : public QObject |
411 | { | 411 | { |
412 | Q_OBJECT | 412 | Q_OBJECT |
413 | 413 | ||
414 | public: | 414 | public: |
415 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | 415 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); |
416 | virtual ~OWaveLanDataPacket(); | 416 | virtual ~OWaveLanDataPacket(); |
417 | 417 | ||
418 | private: | 418 | private: |
419 | const struct ieee_802_11_data_header* _header; | 419 | const struct ieee_802_11_data_header* _header; |
420 | class Private; | 420 | class Private; |
421 | Private *d; | 421 | Private *d; |
422 | }; | 422 | }; |
423 | 423 | ||
424 | /*====================================================================================== | 424 | /*====================================================================================== |
425 | * OWaveLanControlPacket - type: control (T_CTRL) | 425 | * OWaveLanControlPacket - type: control (T_CTRL) |
426 | *======================================================================================*/ | 426 | *======================================================================================*/ |
427 | 427 | ||
428 | class OWaveLanControlPacket : public QObject | 428 | class OWaveLanControlPacket : public QObject |
429 | { | 429 | { |
430 | Q_OBJECT | 430 | Q_OBJECT |
431 | 431 | ||
432 | public: | 432 | public: |
433 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); | 433 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); |
434 | virtual ~OWaveLanControlPacket(); | 434 | virtual ~OWaveLanControlPacket(); |
435 | 435 | ||
436 | QString controlType() const; | 436 | QString controlType() const; |
437 | 437 | ||
438 | private: | 438 | private: |
439 | const struct ieee_802_11_control_header* _header; | 439 | const struct ieee_802_11_control_header* _header; |
440 | class Private; | 440 | class Private; |
441 | Private *d; | 441 | Private *d; |
442 | }; | 442 | }; |
443 | 443 | ||
444 | /*====================================================================================== | 444 | /*====================================================================================== |
445 | * OLLCPacket - IEEE 802.2 Link Level Control | 445 | * OLLCPacket - IEEE 802.2 Link Level Control |
446 | *======================================================================================*/ | 446 | *======================================================================================*/ |
447 | 447 | ||
448 | class OLLCPacket : public QObject | 448 | class OLLCPacket : public QObject |
449 | { | 449 | { |
450 | Q_OBJECT | 450 | Q_OBJECT |
451 | 451 | ||
452 | public: | 452 | public: |
453 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | 453 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); |
454 | virtual ~OLLCPacket(); | 454 | virtual ~OLLCPacket(); |
455 | 455 | ||
456 | private: | 456 | private: |
457 | const struct ieee_802_11_802_2_header* _header; | 457 | const struct ieee_802_11_802_2_header* _header; |
458 | class Private; | 458 | class Private; |
459 | Private *d; | 459 | Private *d; |
460 | }; | 460 | }; |
461 | 461 | ||
462 | /*====================================================================================== | 462 | /*====================================================================================== |
463 | * OIPPacket | 463 | * OIPPacket |
464 | *======================================================================================*/ | 464 | *======================================================================================*/ |
465 | 465 | ||
466 | class OIPPacket : public QObject | 466 | class OIPPacket : public QObject |
467 | { | 467 | { |
468 | Q_OBJECT | 468 | Q_OBJECT |
469 | 469 | ||
470 | public: | 470 | public: |
471 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); | 471 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); |
472 | virtual ~OIPPacket(); | 472 | virtual ~OIPPacket(); |
473 | 473 | ||
474 | QHostAddress fromIPAddress() const; | 474 | QHostAddress fromIPAddress() const; |
475 | QHostAddress toIPAddress() const; | 475 | QHostAddress toIPAddress() const; |
476 | 476 | ||
477 | int tos() const; | 477 | int tos() const; |
478 | int len() const; | 478 | int len() const; |
479 | int id() const; | 479 | int id() const; |
480 | int offset() const; | 480 | int offset() const; |
481 | int ttl() const; | 481 | int ttl() const; |
482 | int protocol() const; | 482 | int protocol() const; |
483 | int checksum() const; | 483 | int checksum() const; |
484 | 484 | ||
485 | private: | 485 | private: |
486 | const struct iphdr* _iphdr; | 486 | const struct iphdr* _iphdr; |
487 | class Private; | 487 | class Private; |
488 | Private *d; | 488 | Private *d; |
489 | }; | 489 | }; |
490 | 490 | ||
491 | /*====================================================================================== | 491 | /*====================================================================================== |
492 | * OARPPacket | 492 | * OARPPacket |
493 | *======================================================================================*/ | 493 | *======================================================================================*/ |
494 | 494 | ||
495 | class OARPPacket : public QObject | 495 | class OARPPacket : public QObject |
496 | { | 496 | { |
497 | Q_OBJECT | 497 | Q_OBJECT |
498 | 498 | ||
499 | public: | 499 | public: |
500 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); | 500 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); |
501 | virtual ~OARPPacket(); | 501 | virtual ~OARPPacket(); |
502 | 502 | ||
503 | QHostAddress senderIPV4Address() const; | 503 | QHostAddress senderIPV4Address() const; |
504 | OMacAddress senderMacAddress() const; | 504 | OMacAddress senderMacAddress() const; |
505 | QHostAddress targetIPV4Address() const; | 505 | QHostAddress targetIPV4Address() const; |
506 | OMacAddress targetMacAddress() const; | 506 | OMacAddress targetMacAddress() const; |
507 | 507 | ||
508 | //int type() const; | 508 | //int type() const; |
509 | QString type() const; | 509 | QString type() const; |
510 | 510 | ||
511 | private: | 511 | private: |
512 | const struct myarphdr* _arphdr; | 512 | const struct myarphdr* _arphdr; |
513 | class Private; | 513 | class Private; |
514 | Private *d; | 514 | Private *d; |
515 | }; | 515 | }; |
516 | 516 | ||
517 | /*====================================================================================== | 517 | /*====================================================================================== |
518 | * OUDPPacket | 518 | * OUDPPacket |
519 | *======================================================================================*/ | 519 | *======================================================================================*/ |
520 | 520 | ||
521 | class OUDPPacket : public QObject | 521 | class OUDPPacket : public QObject |
522 | { | 522 | { |
523 | Q_OBJECT | 523 | Q_OBJECT |
524 | 524 | ||
525 | public: | 525 | public: |
526 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); | 526 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); |
527 | virtual ~OUDPPacket(); | 527 | virtual ~OUDPPacket(); |
528 | 528 | ||
529 | int fromPort() const; | 529 | int fromPort() const; |
530 | int toPort() const; | 530 | int toPort() const; |
531 | int length() const; | 531 | int length() const; |
532 | int checksum() const; | 532 | int checksum() const; |
533 | 533 | ||
534 | private: | 534 | private: |
535 | const struct udphdr* _udphdr; | 535 | const struct udphdr* _udphdr; |
536 | class Private; | 536 | class Private; |
537 | Private *d; | 537 | Private *d; |
538 | }; | 538 | }; |
539 | 539 | ||
540 | /*====================================================================================== | 540 | /*====================================================================================== |
541 | * ODHCPPacket | 541 | * ODHCPPacket |
542 | *======================================================================================*/ | 542 | *======================================================================================*/ |
543 | 543 | ||
544 | class ODHCPPacket : public QObject | 544 | class ODHCPPacket : public QObject |
545 | { | 545 | { |
546 | Q_OBJECT | 546 | Q_OBJECT |
547 | 547 | ||
548 | public: | 548 | public: |
549 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); | 549 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); |
550 | virtual ~ODHCPPacket(); | 550 | virtual ~ODHCPPacket(); |
551 | 551 | ||
552 | QHostAddress clientAddress() const; | 552 | QHostAddress clientAddress() const; |
553 | QHostAddress yourAddress() const; | 553 | QHostAddress yourAddress() const; |
554 | QHostAddress serverAddress() const; | 554 | QHostAddress serverAddress() const; |
555 | QHostAddress relayAddress() const; | 555 | QHostAddress relayAddress() const; |
556 | 556 | ||
557 | OMacAddress clientMacAddress() const; | 557 | OMacAddress clientMacAddress() const; |
558 | 558 | ||
559 | bool isRequest() const; | 559 | bool isRequest() const; |
560 | bool isReply() const; | 560 | bool isReply() const; |
561 | QString type() const; | 561 | QString type() const; |
562 | 562 | ||
563 | private: | 563 | private: |
564 | const struct dhcp_packet* _dhcphdr; | 564 | const struct dhcp_packet* _dhcphdr; |
565 | unsigned char _type; | 565 | unsigned char _type; |
566 | class Private; | 566 | class Private; |
567 | Private *d; | 567 | Private *d; |
568 | }; | 568 | }; |
569 | 569 | ||
570 | /*====================================================================================== | 570 | /*====================================================================================== |
571 | * OTCPPacket | 571 | * OTCPPacket |
572 | *======================================================================================*/ | 572 | *======================================================================================*/ |
573 | 573 | ||
574 | class OTCPPacket : public QObject | 574 | class OTCPPacket : public QObject |
575 | { | 575 | { |
576 | Q_OBJECT | 576 | Q_OBJECT |
577 | 577 | ||
578 | public: | 578 | public: |
579 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); | 579 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); |
580 | virtual ~OTCPPacket(); | 580 | virtual ~OTCPPacket(); |
581 | 581 | ||
582 | int fromPort() const; | 582 | int fromPort() const; |
583 | int toPort() const; | 583 | int toPort() const; |
584 | int seq() const; | 584 | int seq() const; |
585 | int ack() const; | 585 | int ack() const; |
586 | int window() const; | 586 | int window() const; |
587 | int checksum() const; | 587 | int checksum() const; |
588 | 588 | ||
589 | private: | 589 | private: |
590 | const struct tcphdr* _tcphdr; | 590 | const struct tcphdr* _tcphdr; |
591 | class Private; | 591 | class Private; |
592 | Private *d; | 592 | Private *d; |
593 | }; | 593 | }; |
594 | 594 | ||
595 | 595 | ||
596 | /*====================================================================================== | 596 | /*====================================================================================== |
597 | * OPacketCapturer | 597 | * OPacketCapturer |
598 | *======================================================================================*/ | 598 | *======================================================================================*/ |
599 | 599 | ||
600 | /** | 600 | /** |
601 | * @brief A class based wrapper for network packet capturing. | 601 | * @brief A class based wrapper for network packet capturing. |
602 | * | 602 | * |
603 | * This class is the base of a high-level interface to the well known packet capturing | 603 | * This class is the base of a high-level interface to the well known packet capturing |
604 | * library libpcap. | 604 | * library libpcap. |
605 | * @see http://tcpdump.org | 605 | * @see http://tcpdump.org |
606 | */ | 606 | */ |
607 | class OPacketCapturer : public QObject | 607 | class OPacketCapturer : public QObject |
608 | { | 608 | { |
609 | Q_OBJECT | 609 | Q_OBJECT |
610 | 610 | ||
611 | public: | 611 | public: |
612 | /** | 612 | /** |
613 | * Constructor. | 613 | * Constructor. |
614 | */ | 614 | */ |
615 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); | 615 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); |
616 | /** | 616 | /** |
617 | * Destructor. | 617 | * Destructor. |
618 | */ | 618 | */ |
619 | ~OPacketCapturer(); | 619 | ~OPacketCapturer(); |
620 | /** | 620 | /** |
621 | * Set the packet capturer to use blocking or non-blocking IO. This can be useful when | 621 | * Set the packet capturer to use blocking or non-blocking IO. This can be useful when |
622 | * not using the socket notifier, e.g. without an application object. | 622 | * not using the socket notifier, e.g. without an application object. |
623 | */ | 623 | */ |
624 | void setBlocking( bool ); | 624 | void setBlocking( bool ); |
625 | /** | 625 | /** |
626 | * @returns true if the packet capturer uses blocking IO calls. | 626 | * @returns true if the packet capturer uses blocking IO calls. |
627 | */ | 627 | */ |
628 | bool blocking() const; | 628 | bool blocking() const; |
629 | /** | 629 | /** |
630 | * Close the packet capturer. This is automatically done in the destructor. | 630 | * Close the packet capturer. This is automatically done in the destructor. |
631 | */ | 631 | */ |
632 | void close(); | 632 | void close(); |
633 | /** | 633 | /** |
634 | * Close the output capture file. | 634 | * Close the output capture file. |
635 | */ | 635 | */ |
636 | void closeDumpFile(); | 636 | void closeDumpFile(); |
637 | /** | 637 | /** |
638 | * @returns the data link type. | 638 | * @returns the data link type. |
639 | * @see <pcap.h> for possible values. | 639 | * @see <pcap.h> for possible values. |
640 | */ | 640 | */ |
641 | int dataLink() const; | 641 | int dataLink() const; |
642 | /** | 642 | /** |
643 | * Dump a packet to the output capture file. | 643 | * Dump a packet to the output capture file. |
644 | */ | 644 | */ |
645 | void dump( OPacket* ); | 645 | void dump( OPacket* ); |
646 | /** | 646 | /** |
647 | * @returns the file descriptor of the packet capturer. This is only useful, if | 647 | * @returns the file descriptor of the packet capturer. This is only useful, if |
648 | * not using the socket notifier, e.g. without an application object. | 648 | * not using the socket notifier, e.g. without an application object. |
649 | */ | 649 | */ |
650 | int fileno() const; | 650 | int fileno() const; |
651 | /** | 651 | /** |
652 | * @returns the next @ref OPacket from the packet capturer. | 652 | * @returns the next @ref OPacket from the packet capturer. |
653 | * @note If blocking mode is true then this call might block. | 653 | * @note If blocking mode is true then this call might block. |
654 | */ | 654 | */ |
655 | OPacket* next(); | 655 | OPacket* next(); |
656 | /** | 656 | /** |
657 | * @returns the next @ref OPacket from the packet capturer, if | 657 | * @returns the next @ref OPacket from the packet capturer, if |
658 | * one arrives within @a time milliseconds. | 658 | * one arrives within @a time milliseconds. |
659 | */ | 659 | */ |
660 | OPacket* next( int time ); | 660 | OPacket* next( int time ); |
661 | /** | 661 | /** |
662 | * Open the packet capturer to capture packets in live-mode from @a interface. | 662 | * Open the packet capturer to capture packets in live-mode from @a interface. |
663 | */ | 663 | */ |
664 | bool open( const QString& interface ); | 664 | bool open( const QString& interface ); |
665 | /** | 665 | /** |
666 | * Open the packet capturer to capture packets in offline-mode from @a filename. | 666 | * Open the packet capturer to capture packets in offline-mode from @a filename. |
667 | */ | 667 | */ |
668 | bool openCaptureFile( const QString& filename ); | 668 | bool openCaptureFile( const QString& filename ); |
669 | /** | 669 | /** |
670 | * Open a prerecorded tcpdump compatible capture file for use with @ref dump() | 670 | * Open a prerecorded tcpdump compatible capture file for use with @ref dump() |
671 | */ | 671 | */ |
672 | bool openDumpFile( const QString& filename ); | 672 | bool openDumpFile( const QString& filename ); |
673 | /** | 673 | /** |
674 | * @returns true if the packet capturer is open | 674 | * @returns true if the packet capturer is open |
675 | */ | 675 | */ |
676 | bool isOpen() const; | 676 | bool isOpen() const; |
677 | /** | 677 | /** |
678 | * @returns the snapshot length of this packet capturer | 678 | * @returns the snapshot length of this packet capturer |
679 | */ | 679 | */ |
680 | int snapShot() const; | 680 | int snapShot() const; |
681 | /** | 681 | /** |
682 | * @returns true if the input capture file has a different byte-order | 682 | * @returns true if the input capture file has a different byte-order |
683 | * than the byte-order of the running system. | 683 | * than the byte-order of the running system. |
684 | */ | 684 | */ |
685 | bool swapped() const; | 685 | bool swapped() const; |
686 | /** | 686 | /** |
687 | * @returns the libpcap version string used to write the input capture file. | 687 | * @returns the libpcap version string used to write the input capture file. |
688 | */ | 688 | */ |
689 | QString version() const; | 689 | QString version() const; |
690 | /** | 690 | /** |
691 | * @returns the packet statistic database. | 691 | * @returns the packet statistic database. |
692 | * @see QMap | 692 | * @see QMap |
693 | */ | 693 | */ |
694 | const QMap<QString,int>& statistics() const; | 694 | const QMap<QString,int>& statistics() const; |
695 | /** | 695 | /** |
696 | * Enable or disable the auto-delete option. | 696 | * Enable or disable the auto-delete option. |
697 | * If auto-delete is enabled, then the packet capturer will delete a packet right | 697 | * If auto-delete is enabled, then the packet capturer will delete a packet right |
698 | * after it has been emit'ted. This is the default, which is useful if the packet | 698 | * after it has been emit'ted. This is the default, which is useful if the packet |
699 | * capturer has the only reference to the packets. If you pass the packet for adding | 699 | * capturer has the only reference to the packets. If you pass the packet for adding |
700 | * into a collection or do processing after the SLOT, the auto delete must be disabled. | 700 | * into a collection or do processing after the SLOT, the auto delete must be disabled. |
701 | */ | 701 | */ |
702 | void setAutoDelete( bool enable ); | 702 | void setAutoDelete( bool enable ); |
703 | /** | 703 | /** |
704 | * @returns the auto-delete value. | 704 | * @returns the auto-delete value. |
705 | */ | 705 | */ |
706 | bool autoDelete() const; | 706 | bool autoDelete() const; |
707 | 707 | ||
708 | signals: | 708 | signals: |
709 | /** | 709 | /** |
710 | * This signal is emitted, when a packet has been received. | 710 | * This signal is emitted, when a packet has been received. |
711 | */ | 711 | */ |
712 | void receivedPacket( Opie::Net::OPacket* ); | 712 | void receivedPacket( Opie::Net::OPacket* ); |
713 | 713 | ||
714 | protected slots: | 714 | protected slots: |
715 | void readyToReceive(); | 715 | void readyToReceive(); |
716 | 716 | ||
717 | protected: | 717 | protected: |
718 | QString _name; // devicename | 718 | QString _name; // devicename |
719 | bool _open; // check this before doing pcap calls | 719 | bool _open; // check this before doing pcap calls |
720 | pcap_t* _pch; // pcap library handle | 720 | pcap_t* _pch; // pcap library handle |
721 | pcap_dumper_t* _pcd; // pcap dumper handle | 721 | pcap_dumper_t* _pcd; // pcap dumper handle |
722 | QSocketNotifier* _sn; // socket notifier for main loop | 722 | QSocketNotifier* _sn; // socket notifier for main loop |
723 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap | 723 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap |
724 | QMap<QString, int> _stats; // statistics; | 724 | QMap<QString, int> _stats; // statistics; |
725 | bool _autodelete; // if we auto delete packets after emit | 725 | bool _autodelete; // if we auto delete packets after emit |
726 | class Private; // Private Forward declaration | 726 | class Private; // Private Forward declaration |
727 | Private *d; // if we need to add data | 727 | Private *d; // if we need to add data |
728 | }; | 728 | }; |
729 | } | 729 | } |
730 | } | 730 | } |
731 | 731 | ||
732 | #endif // OPCAP_H | 732 | #endif // OPCAP_H |
733 | 733 | ||
diff --git a/libopie2/opienet/ostation.cpp b/libopie2/opienet/ostation.cpp index b5ac325..88ad808 100644 --- a/libopie2/opienet/ostation.cpp +++ b/libopie2/opienet/ostation.cpp | |||
@@ -1,72 +1,72 @@ | |||
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 by Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <opie2/ostation.h> | 31 | #include <opie2/ostation.h> |
32 | #include <opie2/odebug.h> | 32 | #include <opie2/odebug.h> |
33 | 33 | ||
34 | 34 | ||
35 | using namespace Opie::Core; | 35 | using namespace Opie::Core; |
36 | 36 | ||
37 | namespace Opie { | 37 | namespace Opie { |
38 | namespace Net { | 38 | namespace Net { |
39 | /*====================================================================================== | 39 | /*====================================================================================== |
40 | * OStation | 40 | * OStation |
41 | *======================================================================================*/ | 41 | *======================================================================================*/ |
42 | 42 | ||
43 | OStation::OStation() | 43 | OStation::OStation() |
44 | { | 44 | { |
45 | odebug << "OStation::OStation()" << oendl; | 45 | odebug << "OStation::OStation()" << oendl; |
46 | 46 | ||
47 | type = "<unknown>"; | 47 | type = "<unknown>"; |
48 | macAddress = OMacAddress::unknown; | 48 | macAddress = OMacAddress::unknown; |
49 | ssid = "<unknown>"; | 49 | ssid = "<unknown>"; |
50 | channel = 0; | 50 | channel = 0; |
51 | apAddress = OMacAddress::unknown; | 51 | apAddress = OMacAddress::unknown; |
52 | 52 | ||
53 | } | 53 | } |
54 | 54 | ||
55 | 55 | ||
56 | OStation::~OStation() | 56 | OStation::~OStation() |
57 | { | 57 | { |
58 | odebug << "OStation::~OStation()" << oendl; | 58 | odebug << "OStation::~OStation()" << oendl; |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | void OStation::dump() | 62 | void OStation::dump() |
63 | { | 63 | { |
64 | odebug << "------- OStation::dump() ------------" << oendl; | 64 | odebug << "------- OStation::dump() ------------" << oendl; |
65 | odebug << "type: " << type << "" << oendl; | 65 | odebug << "type: " << type << "" << oendl; |
66 | odebug << "mac: " << macAddress.toString() << "" << oendl; | 66 | odebug << "mac: " << macAddress.toString() << "" << oendl; |
67 | odebug << "ap: " << apAddress.toString() << "" << oendl; | 67 | odebug << "ap: " << apAddress.toString() << "" << oendl; |
68 | odebug << "ip: " << ipAddress.toString() << "" << oendl; | 68 | odebug << "ip: " << ipAddress.toString() << "" << oendl; |
69 | } | 69 | } |
70 | 70 | ||
71 | } | 71 | } |
72 | } | 72 | } |
diff --git a/libopie2/opienet/ostation.h b/libopie2/opienet/ostation.h index 68f1114..bdc653f 100644 --- a/libopie2/opienet/ostation.h +++ b/libopie2/opienet/ostation.h | |||
@@ -1,82 +1,82 @@ | |||
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 by Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef OSTATION_H | 31 | #ifndef OSTATION_H |
32 | #define OSTATION_H | 32 | #define OSTATION_H |
33 | 33 | ||
34 | #include <opie2/onetutils.h> | 34 | #include <opie2/onetutils.h> |
35 | 35 | ||
36 | #include <qlist.h> | 36 | #include <qlist.h> |
37 | #include <qstring.h> | 37 | #include <qstring.h> |
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 | namespace Opie { | 43 | namespace Opie { |
44 | namespace Net { | 44 | namespace Net { |
45 | 45 | ||
46 | class OStation; | 46 | class OStation; |
47 | 47 | ||
48 | 48 | ||
49 | typedef QList<OStation> OStationList; | 49 | typedef QList<OStation> OStationList; |
50 | 50 | ||
51 | /*====================================================================================== | 51 | /*====================================================================================== |
52 | * OStation | 52 | * OStation |
53 | *======================================================================================*/ | 53 | *======================================================================================*/ |
54 | 54 | ||
55 | class OStation | 55 | class OStation |
56 | { | 56 | { |
57 | public: | 57 | public: |
58 | OStation(); | 58 | OStation(); |
59 | ~OStation(); | 59 | ~OStation(); |
60 | 60 | ||
61 | void dump(); | 61 | void dump(); |
62 | 62 | ||
63 | /* Ethernet */ | 63 | /* Ethernet */ |
64 | QString type; | 64 | QString type; |
65 | OMacAddress macAddress; | 65 | OMacAddress macAddress; |
66 | QHostAddress ipAddress; | 66 | QHostAddress ipAddress; |
67 | 67 | ||
68 | /* WaveLan */ | 68 | /* WaveLan */ |
69 | QString ssid; | 69 | QString ssid; |
70 | OMacAddress apAddress; | 70 | OMacAddress apAddress; |
71 | int channel; | 71 | int channel; |
72 | bool encrypted; | 72 | bool encrypted; |
73 | private: | 73 | private: |
74 | class Private; | 74 | class Private; |
75 | Private *d; | 75 | Private *d; |
76 | }; | 76 | }; |
77 | 77 | ||
78 | } | 78 | } |
79 | } | 79 | } |
80 | 80 | ||
81 | #endif // OSTATION_H | 81 | #endif // OSTATION_H |
82 | 82 | ||