summaryrefslogtreecommitdiff
path: root/libopie2/opienet/opcap.cpp
authormickeyl <mickeyl>2003-05-04 20:38:24 (UTC)
committer mickeyl <mickeyl>2003-05-04 20:38:24 (UTC)
commit09dceae91b14a4b2d936ebfc6c7c276686c2b98c (patch) (side-by-side diff)
treeb8ebc6f92ca0008a90ef036c3c5ba873a2f59670 /libopie2/opienet/opcap.cpp
parent8409a251d52b59585889e1bcaa278a6b847db2fc (diff)
downloadopie-09dceae91b14a4b2d936ebfc6c7c276686c2b98c.zip
opie-09dceae91b14a4b2d936ebfc6c7c276686c2b98c.tar.gz
opie-09dceae91b14a4b2d936ebfc6c7c276686c2b98c.tar.bz2
add parsing of ARP packets
Diffstat (limited to 'libopie2/opienet/opcap.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp65
1 files changed, 62 insertions, 3 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 675818e..e2ab6d7 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -158,7 +158,6 @@ int OPacket::len() const
OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
:QObject( parent, "Ethernet" ), _ether( data )
-
{
qDebug( "Source = %s", (const char*) sourceAddress().toString() );
@@ -209,7 +208,6 @@ int OEthernetPacket::type() const
OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
:QObject( parent, "IP" ), _iphdr( data )
-
{
qDebug( "OIPPacket::OIPPacket(): decoding IP header..." );
@@ -287,6 +285,66 @@ int OIPPacket::checksum() const
}
/*======================================================================================
+ * OARPPacket
+ *======================================================================================*/
+
+
+OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent )
+ :QObject( parent, "ARP" ), _arphdr( data )
+{
+ qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." );
+ qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() );
+ qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() );
+ qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() );
+}
+
+
+OARPPacket::~OARPPacket()
+{
+}
+
+
+QString OARPPacket::type() const
+{
+ switch ( EXTRACT_16BITS( &_arphdr->ar_op ) )
+ {
+ case 1: return "REQUEST";
+ case 2: return "REPLY";
+ case 3: return "RREQUEST";
+ case 4: return "RREPLY";
+ case 8: return "InREQUEST";
+ case 9: return "InREPLY";
+ case 10: return "NAK";
+ default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>";
+ }
+}
+
+
+QHostAddress OARPPacket::senderIPV4Address() const
+{
+ return EXTRACT_32BITS( &_arphdr->ar_sip );
+}
+
+
+QHostAddress OARPPacket::targetIPV4Address() const
+{
+ return EXTRACT_32BITS( &_arphdr->ar_tip );
+}
+
+
+OMacAddress OARPPacket::senderMacAddress() const
+{
+ return OMacAddress( _arphdr->ar_sha );
+}
+
+
+OMacAddress OARPPacket::targetMacAddress() const
+{
+ return OMacAddress( _arphdr->ar_tha );
+}
+
+
+/*======================================================================================
* OUDPPacket
*======================================================================================*/
@@ -730,7 +788,8 @@ OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2
switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
{
case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
- default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" );
+ case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
+ default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) );
}
}