00001 #include "decode_icmp.h" 00002 #include "decode_ip.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 int IPDecoderID; 00013 00014 /*************************************** 00015 * Apply the icmp decoding 00016 ****************************************/ 00017 void* DecodeICMP(int PacketSlot){ 00018 ICMPData* data; 00019 IPData* ip_data; 00020 unsigned char ip_proto; 00021 PacketRec* p; 00022 00023 DEBUGPATH; 00024 00025 #ifdef DEBUG 00026 printf("Decoding ICMP Header\n"); 00027 #endif 00028 00029 p=&Globals.Packets[PacketSlot]; 00030 00031 if (!GetDataByID(PacketSlot, IPDecoderID, (void**)&ip_data)){ 00032 printf("Failed to get IP header data\n"); 00033 return NULL; 00034 } 00035 00036 ip_proto=ip_data->Header->protocol; 00037 00038 if (ip_proto!=IP_PROTO_ICMP){ 00039 #ifdef DEBUG 00040 printf("IP doesn't think this is an icmp packet %02x\n",ip_proto); 00041 #endif 00042 return NULL; 00043 } 00044 00045 data=malloc(sizeof(ICMPData)); 00046 data->Header=(ICMPHdr*)(p->RawPacket+p->BeginData); 00047 p->BeginData+=sizeof(ICMPHdr); 00048 00049 #ifdef DEBUG 00050 printf("ICMP Type %u Code %u\n",data->Header->type, data->Header->code); 00051 #endif 00052 00053 return data; 00054 } 00055 00056 /************************************* 00057 * Set up the decoder 00058 *************************************/ 00059 int InitDecoderICMP(){ 00060 int DecoderID; 00061 00062 DEBUGPATH; 00063 00064 if ((DecoderID=CreateDecoder("ICMP"))==DECODER_NONE){ 00065 #ifdef DEBUG 00066 printf("Couldn't Allocate ICMP Decoder\n"); 00067 #endif 00068 return FALSE; 00069 } 00070 00071 Globals.Decoders[DecoderID].DecodeFunc=DecodeICMP; 00072 if (!DecoderAddDecoder(GetDecoderByName("IP"), DecoderID)){ 00073 printf("Failed to Bind ICMP Decoder to IPDefrag Decoder\n"); 00074 return FALSE; 00075 } 00076 00077 IPDecoderID=GetDecoderByName("IP"); 00078 00079 return TRUE; 00080 }