arp-tracer.cc

00001 /*
00002  * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00014  *    names of its contributors may be used to endorse or promote products 
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "arp-tracer.h"
00031 #include <sap.h>
00032 #include <address.h>
00033 #include <mac.h>
00034 #include <mac-802_11.h>
00035 
00036 
00037 
00038 ARP_Tracer::ARP_Tracer() : Tracer(5) {}
00039 
00040 void ARP_Tracer::format(Packet *p, SAP *sap)
00041 {
00042         hdr_cmn *ch = hdr_cmn::access(p);
00043         if(ch->ptype() != PT_ARP)
00044                 return;
00045         
00046         struct hdr_arp *ah = HDR_ARP(p);
00047         
00048         /*
00049         writeTrace(sap, " --ARP-- [%s %d/%d %d/%d]",
00050                         ah->arp_op == ARPOP_REQUEST ?  "REQUEST" : "REPLY",
00051                         ah->arp_sha,
00052                         ah->arp_spa,
00053                         ah->arp_tha,
00054                         ah->arp_tpa
00055                         );
00056         */
00057         switch (ah->arp_op) 
00058           {
00059           case ARPOP_REQUEST:
00060             writeTrace(sap, " -- ARP -- [Who has %d.%d.%d.%d? Tell %d.%d.%d.%d at %02x:%02x:%02x:%02x]",
00061                        (ah->arp_tpa & 0xff000000)>>24,
00062                        (ah->arp_tpa & 0x00ff0000)>>16,
00063                        (ah->arp_tpa & 0x0000ff00)>>8,
00064                        (ah->arp_tpa & 0x000000ff),
00065                        (ah->arp_spa & 0xff000000)>>24,
00066                        (ah->arp_spa & 0x00ff0000)>>16,
00067                        (ah->arp_spa & 0x0000ff00)>>8,
00068                        (ah->arp_spa & 0x000000ff),
00069                        (ah->arp_sha & 0xff000000)>>24,
00070                        (ah->arp_sha & 0x00ff0000)>>16,
00071                        (ah->arp_sha & 0x0000ff00)>>8,
00072                        (ah->arp_sha & 0x000000ff)
00073                        );
00074             break;
00075 
00076           case ARPOP_REPLY: 
00077             writeTrace(sap, " -- ARP -- [%d.%d.%d.%d is at %02x:%02x:%02x:%02x]",
00078                        (ah->arp_spa & 0xff000000)>>24,
00079                        (ah->arp_spa & 0x00ff0000)>>16,
00080                        (ah->arp_spa & 0x0000ff00)>>8,
00081                        (ah->arp_spa & 0x000000ff),
00082                        (ah->arp_sha & 0xff000000)>>24,
00083                        (ah->arp_sha & 0x00ff0000)>>16,
00084                        (ah->arp_sha & 0x0000ff00)>>8,
00085                        (ah->arp_sha & 0x000000ff)
00086                        );
00087             break;
00088             
00089           case ARPOP_REVREQUEST:
00090             writeTrace(sap, " -- ARP -- [REVREQUEST]");
00091             break;
00092 
00093           case ARPOP_REVREPLY:
00094             writeTrace(sap, " -- ARP -- [REVREPLY]");
00095             break;
00096             
00097           case ARPOP_INVREQUEST:
00098             writeTrace(sap, " -- ARP -- [INVREQUEST]");
00099             break;
00100             
00101 
00102           case ARPOP_INVREPLY:
00103             writeTrace(sap, " -- ARP -- [INVREPLY]");
00104             break;
00105           }
00106             
00107 }
00108 
00109               
00110 extern "C" int Arptracer_Init()
00111 {
00112   /*
00113    * Put here all the commands which must be execute when the library
00114    * is loaded (i.e. TCL script execution)  
00115    * Remember to return 0 if all is OK, otherwise return 1
00116   */
00117         
00118         SAP::addTracer(new ARP_Tracer);
00119         return 0;
00120 }
00121 extern "C" int  Cygarptracer_Init()
00122 {
00123   Arptracer_Init();
00124 }
00125 
00126 

Generated on Wed Nov 26 15:47:28 2008 for NS-MIRACLE library by  doxygen 1.5.2