tests/test_tcp_nocase.c

Go to the documentation of this file.
00001 #include "test_tcp_nocase.h"
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include <stdlib.h>
00005 #include "../decoders/decode_tcp.h"
00006 #include "../packets/packet.h"
00007 #include "../engine/jtree.h"
00008 #include <arpa/inet.h>
00009 
00010 extern GlobalVars       Globals;
00011 
00012 typedef struct tcp_nocase_data{
00013         unsigned char   tcp_content[MAX_CONTENT_LEN];
00014 } TCPNoCaseData;
00015 
00016 //#define DEBUG
00017 //#define DEBUGMATCH
00018 
00019 int                     TCPDecoderID;
00020 JTree                   TCPNoCaseTree;
00021 
00025 int TestTCPNoCase(int PacketSlot, TestNode* Nodes)
00026 {
00027         PacketRec*                      p;
00028         TCPNoCaseData* data;
00029 #ifdef DEBUGMATCH       
00030         int                                     i;
00031 #endif  
00032 
00033         DEBUGPATH;
00034 
00035         p = &Globals.Packets[PacketSlot];
00036         
00037         if (!Nodes) return FALSE;
00038         
00039 #ifdef DEBUGMATCH
00040         printf("**************************************\n");
00041         printf("Before applying tcp no case tests\n");
00042         for (i=0;i<Globals.NumRules;i++)
00043         if (RuleIsActive(PacketSlot,i))
00044                 printf("Rule %i is active\n",i);
00045         else
00046                 printf("Rule %i is inactive\n",i);
00047         printf("**************************************\n");
00048 #endif  
00049         MatchStrings(&TCPNoCaseTree, p->RuleBits, p->RawPacket+p->BeginData, p->PacketLen - p->BeginData);
00050         
00051 #ifdef DEBUGMATCH
00052         printf("**************************************\n");
00053         for (i=0;i<Globals.NumRules;i++)
00054         if (RuleIsActive(PacketSlot,i))
00055                 printf("Rule %i is active\n",i);
00056         else
00057                 printf("Rule %i is inactive\n",i);
00058         printf("**************************************\n");
00059 #endif  
00060                 
00061         return TRUE;
00062 }
00063 
00064 /******************************************
00065 * Add a rule node to this test
00066 ******************************************/
00067 int TCPNoCaseAddNode(int TestID, int RuleID, char* Args){
00068         TCPNoCaseData*          data;
00069 
00070 #ifdef DEBUGPATH
00071         printf("In TCPNoCaseAddNode\n");
00072 #endif
00073 
00074 #ifdef DEBUG
00075         printf("Addding a Node with args %s\n",Args);
00076 #endif
00077 
00078         data=calloc(sizeof(TCPNoCaseData),1);
00079         snprintf(data->tcp_content, MAX_CONTENT_LEN, "%s", Args);
00080 
00081         if (!AddStringJTree(&TCPNoCaseTree, Args, strlen(Args), RuleID)){
00082                 printf("Failed to add to tree\n");
00083                 free(data);
00084                 data=NULL;
00085                 return FALSE;
00086         }
00087         
00088         return TestAddNode(TestID, RuleID, (void*)data);
00089 }
00090 
00094 int TestTCPNoCaseFinishedSetup()
00095 {
00096 #ifdef DEBUGPATH
00097         printf("In TestTCPNocaseFinishedSetup\n");
00098 #endif
00099 
00100         return FinalizeJTree(&TCPNoCaseTree);
00101 }
00102 
00106 int InitTestTCPNoCase()
00107 {
00108         int     TestID;
00109 
00110 #ifdef DEBUGPATH
00111         printf("In InitTestTCPNoCase\n");
00112 #endif
00113 
00114         InitJTree(&TCPNoCaseTree, TRUE);
00115 
00116         TestID=CreateTest("TCPNoCase");
00117         if (TestID==TEST_NONE) return FALSE;
00118         
00119         if (!BindTestToDecoder(TestID, "TCP")){
00120                 printf("Failed to Bind to TCP\n");
00121                 return FALSE;
00122         } 
00123         
00124         snprintf(Globals.Tests[TestID].ShortName, MAX_NAME_LEN, "nocase");
00125         Globals.Tests[TestID].AddNode=TCPNoCaseAddNode;
00126         Globals.Tests[TestID].TestFunc=TestTCPNoCase;
00127         Globals.Tests[TestID].FinishedSetup=TestTCPNoCaseFinishedSetup;
00128         
00129         TCPDecoderID=GetDecoderByName("TCP");
00130 
00131         return TRUE;
00132 }

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