decoders/decode_ethernet.c

Go to the documentation of this file.
00001 #include "decode_ethernet.h"
00002 #include "decode_interface.h"
00003 #include "../packets/packet.h"
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <netinet/in.h>
00007 
00008 //#define DEBUG
00009 
00010 extern GlobalVars       Globals;
00011 
00012 /***************************************
00013 * Apply the Ethernet decoding
00014 ****************************************/
00015 void* DecodeEthernet(int PacketSlot){
00016         InterfaceRec*   r;
00017         EthernetData*   data;
00018         PacketRec*              p;
00019         
00020         DEBUGPATH;
00021 
00022         p=&Globals.Packets[PacketSlot];
00023 
00024         /*grab the interface to check the type*/
00025         /*The interface record is always the first on the stack*/
00026         r=((InterfaceData*)(p->DecoderInfo[0].Data))->r;
00027         
00028         if (r->Proto!=PACKET_PROTO_ETHERNET){
00029 #ifdef DEBUG
00030                 printf("This isn't an ethernet interface\n");
00031 #endif                  
00032                 return NULL;
00033         }
00034 
00035         data=malloc(sizeof(EthernetData));
00036         data->Header=(EtherHdr*)p->RawPacket;
00037         p->BeginData=sizeof(EtherHdr);
00038         
00039         return data;
00040 }
00041 
00042 /*************************************
00043 * Set up the decoder
00044 *************************************/
00045 int InitDecoderEthernet(){
00046         int DecoderID;
00047 
00048         DEBUGPATH;
00049         
00050         if ((DecoderID=CreateDecoder("Ethernet"))==DECODER_NONE){
00051 #ifdef DEBUG
00052                 printf("Couldn't Allocate Ethernet Decoder\n");
00053 #endif  
00054                 return FALSE;
00055         }
00056         
00057         Globals.Decoders[DecoderID].DecodeFunc=DecodeEthernet;
00058         if (!DecoderAddDecoder(GetDecoderByName("Interface"), DecoderID)){
00059                 printf("Failed to Bind Ethernet Decoder to Interface Decoder\n");
00060                 return FALSE;
00061         }
00062 
00063         return TRUE;
00064 }

Generated on Sat Jul 7 23:33:10 2007 for HLBR by  doxygen 1.5.2