00001 #include "decode_udp.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 udp decoding 00016 ****************************************/ 00017 void* DecodeUDP(int PacketSlot){ 00018 UDPData* data; 00019 IPData* ip_data; 00020 unsigned char ip_proto; 00021 PacketRec* p; 00022 00023 DEBUGPATH; 00024 00025 #ifdef DEBUG 00026 printf("Decoding UDP 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_UDP){ 00039 #ifdef DEBUG 00040 printf("IP doesn't think this is an udp packet %02x\n",ip_proto); 00041 #endif 00042 return NULL; 00043 } 00044 00045 data=malloc(sizeof(UDPData)); 00046 data->Header=(UDPHdr*)(p->RawPacket+p->BeginData); 00047 p->BeginData+=sizeof(UDPHdr); 00048 00049 #ifdef DEBUG 00050 printf("UDP %u->%u\n",ntohs(data->Header->source), ntohs(data->Header->dest)); 00051 #endif 00052 00053 return data; 00054 } 00055 00056 /************************************* 00057 * Set up the decoder 00058 *************************************/ 00059 int InitDecoderUDP(){ 00060 int DecoderID; 00061 00062 DEBUGPATH; 00063 00064 if ((DecoderID=CreateDecoder("UDP"))==DECODER_NONE){ 00065 #ifdef DEBUG 00066 printf("Couldn't Allocate UDP Decoder\n"); 00067 #endif 00068 return FALSE; 00069 } 00070 00071 Globals.Decoders[DecoderID].DecodeFunc=DecodeUDP; 00072 if (!DecoderAddDecoder(GetDecoderByName("IP"), DecoderID)){ 00073 printf("Failed to Bind UDP Decoder to IPDefrag Decoder\n"); 00074 return FALSE; 00075 } 00076 00077 IPDecoderID=GetDecoderByName("IP"); 00078 00079 return TRUE; 00080 }