summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-10-04 01:34:13 (UTC)
committer mickeyl <mickeyl>2003-10-04 01:34:13 (UTC)
commita4793f5226e9eb5c8a718cca9335c23530e08b08 (patch) (side-by-side diff)
tree9e18d900f9c0a96170c8221ba4e60e7b7937cf39
parente2716e3862915582d0ce48aaacc967f5b0cf6550 (diff)
downloadopie-a4793f5226e9eb5c8a718cca9335c23530e08b08.zip
opie-a4793f5226e9eb5c8a718cca9335c23530e08b08.tar.gz
opie-a4793f5226e9eb5c8a718cca9335c23530e08b08.tar.bz2
Although not yet complete, the DHCP decoding is now usable
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp82
-rw-r--r--libopie2/opienet/opcap.h10
2 files changed, 92 insertions, 0 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index f1f2b4b..7a6f61b 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -409,6 +409,36 @@ ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* da
{
qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." );
+ qDebug( "DHCP opcode seems to be %02d - '%s'", _dhcphdr->op, isRequest() ? "REQUEST" : "REPLY" );
+ qDebug( "clientAddress: %s", (const char*) clientAddress().toString() );
+ qDebug( " yourAddress: %s", (const char*) yourAddress().toString() );
+ qDebug( "serverAddress: %s", (const char*) serverAddress().toString() );
+ qDebug( " relayAddress: %s", (const char*) relayAddress().toString() );
+ qDebug( "parsing DHCP options..." );
+
+ _type = 0;
+
+ const unsigned char* option = &_dhcphdr->options[4];
+ char tag = -1;
+ char len = -1;
+
+ while ( ( tag = *option++ ) != -1 /* end of option field */ )
+ {
+ len = *option++;
+ qDebug( "recognized DHCP option #%d, length %d", tag, len );
+
+ if ( tag == DHO_DHCP_MESSAGE_TYPE )
+ _type = *option;
+
+ option += len;
+ if ( option >= end )
+ {
+ qWarning( "DHCP parsing ERROR: sanity check says the packet is at its end!" );
+ break;
+ }
+ }
+
+ qDebug( "DHCP type seems to be '%s'", (const char*) type() );
}
@@ -417,6 +447,58 @@ ODHCPPacket::~ODHCPPacket()
}
+bool ODHCPPacket::isRequest() const
+{
+ return ( _dhcphdr->op == 01 );
+}
+
+
+bool ODHCPPacket::isReply() const
+{
+ return ( _dhcphdr->op == 02 );
+}
+
+
+QString ODHCPPacket::type() const
+{
+ switch ( _type )
+ {
+ case 1: return "DISCOVER";
+ case 2: return "OFFER";
+ case 3: return "REQUEST";
+ case 4: return "DECLINE";
+ case 5: return "ACK";
+ case 6: return "NAK";
+ case 7: return "RELEASE";
+ case 8: return "INFORM";
+ default: qWarning( "ODHCPPacket::type(): invalid DHCP type (%d) !", _dhcphdr->op ); return "<unknown>";
+ }
+}
+
+
+QHostAddress ODHCPPacket::clientAddress() const
+{
+ return EXTRACT_32BITS( &_dhcphdr->ciaddr );
+}
+
+
+QHostAddress ODHCPPacket::yourAddress() const
+{
+ return EXTRACT_32BITS( &_dhcphdr->yiaddr );
+}
+
+
+QHostAddress ODHCPPacket::serverAddress() const
+{
+ return EXTRACT_32BITS( &_dhcphdr->siaddr );
+}
+
+
+QHostAddress ODHCPPacket::relayAddress() const
+{
+ return EXTRACT_32BITS( &_dhcphdr->giaddr );
+}
+
/*======================================================================================
* OTCPPacket
*======================================================================================*/
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index 0c9e7da..a031dd1 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -499,8 +499,18 @@ class ODHCPPacket : public QObject
ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 );
virtual ~ODHCPPacket();
+ QHostAddress clientAddress() const;
+ QHostAddress yourAddress() const;
+ QHostAddress serverAddress() const;
+ QHostAddress relayAddress() const;
+
+ bool isRequest() const;
+ bool isReply() const;
+ QString type() const;
+
private:
const struct dhcp_packet* _dhcphdr;
+ unsigned char _type;
};
/*======================================================================================