tests/test_tcp_listnocase.c

Go to the documentation of this file.
00001 #include "test_tcp_listnocase.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 "../engine/parse_config.h"
00009 #include <arpa/inet.h>
00010 
00011 extern GlobalVars       Globals;
00012 
00013 typedef struct tcp_nocase_data{
00014         unsigned char   tcp_content[MAX_CONTENT_LEN];
00015 } TCPListNoCaseData;
00016 
00017 //#define DEBUG
00018 //#define DEBUGMATCH
00019 
00020 int                     TCPDecoderID;
00021 JTree                   TCPListNoCaseTree;
00022 
00023 /******************************************
00024 * Apply the Test
00025 ******************************************/
00026 int TestTCPListNoCase(int PacketSlot, TestNode* Nodes){
00027         PacketRec*                      p;
00028 #ifdef DEBUGMATCH       
00029         int                                     i;
00030 #endif  
00031 
00032 #ifdef DEBUGPATH
00033         printf("In TestTCPListNoCase\n");
00034 #endif
00035 
00036 #ifdef DEBUG
00037         printf("Testing TCP ListNoCase\n");
00038 #endif  
00039 
00040         p=&Globals.Packets[PacketSlot];
00041         
00042         if (!Nodes) return FALSE;
00043         
00044 #ifdef DEBUGMATCH
00045         printf("**************************************\n");
00046         printf("Before applying tcp no case tests\n");
00047         for (i=0;i<Globals.NumRules;i++)
00048         if (RuleIsActive(PacketSlot,i))
00049                 printf("Rule %i is active\n",i);
00050         else
00051                 printf("Rule %i is inactive\n",i);
00052         printf("**************************************\n");
00053 #endif  
00054 
00055         MatchStrings(&TCPListNoCaseTree, p->RuleBits, p->RawPacket+p->BeginData, p->PacketLen - p->BeginData);
00056         
00057 #ifdef DEBUGMATCH
00058         printf("**************************************\n");
00059         for (i=0;i<Globals.NumRules;i++)
00060         if (RuleIsActive(PacketSlot,i))
00061                 printf("Rule %i is active\n",i);
00062         else
00063                 printf("Rule %i is inactive\n",i);
00064         printf("**************************************\n");
00065 #endif  
00066                 
00067         return TRUE;
00068 }
00069 
00070 /******************************************
00071 * Add a rule node to this test
00072 * Args is the file name of the word list
00073 ******************************************/
00074 int TCPListNoCaseAddNode(int TestID, int RuleID, char* Args){
00075         TCPListNoCaseData*      data;
00076         FILE*                   listf;
00077         char                    LineBuff[10240];
00078 
00079 #ifdef DEBUGPATH
00080         printf("In TCPListNoCaseAddNode\n");
00081 #endif
00082 
00083         listf = fopen(Args, "r");
00084         if (!listf){
00085                 printf("Couldn't open file %s for 'tcp listnocase' test\n", Args);
00086                 return FALSE;
00087         }
00088 
00089 #ifdef DEBUG
00090         printf("Adding a Node with args from file %s\n", Args);
00091 #endif
00092 
00093 //                      data=calloc(sizeof(TCPListNoCaseData),1);
00094 //                      snprintf(data->tcp_content, MAX_CONTENT_LEN, "%s", Args);
00095         data=NULL;
00096 
00097         while (GetLine(listf, LineBuff, 10240)) {
00098 #ifdef DEBUG
00099                         printf("Adding: %s\n", LineBuff);
00100 #endif
00101 
00102                         if (!AddStringJTree(&TCPListNoCaseTree, LineBuff, strlen(LineBuff), RuleID)) {
00103                                         printf("Failed to add to tree\n");
00104 //                                      free(data);
00105 //                                      data=NULL;
00106                                         return FALSE;
00107                         }
00108         }
00109 
00110         fclose(listf);
00111         
00112         return TestAddNode(TestID, RuleID, (void*)data);
00113 }
00114 
00115 /****************************************
00116 * Called when we're all done adding rules
00117 ****************************************/
00118 int TestTCPListNoCaseFinishedSetup(){
00119 #ifdef DEBUGPATH
00120         printf("In TestTCPListNoCaseFinishedSetup\n");
00121 #endif
00122 
00123         return FinalizeJTree(&TCPListNoCaseTree);
00124 }
00125 
00126 
00127 /****************************************
00128 * Set up the test of the TCP NoCase
00129 *****************************************/
00130 int InitTestTCPListNoCase(){
00131         int     TestID;
00132 
00133 #ifdef DEBUGPATH
00134         printf("In InitTestTCPListNoCase\n");
00135 #endif
00136 
00137         InitJTree(&TCPListNoCaseTree, TRUE);
00138 
00139         TestID=CreateTest("TCPListNoCase");
00140         if (TestID==TEST_NONE) return FALSE;
00141         
00142         if (!BindTestToDecoder(TestID, "TCP")){
00143                 printf("Failed to Bind to TCP\n");
00144                 return FALSE;
00145         } 
00146         
00147         snprintf(Globals.Tests[TestID].ShortName, MAX_NAME_LEN, "listnocase");
00148         Globals.Tests[TestID].AddNode=TCPListNoCaseAddNode;
00149         Globals.Tests[TestID].TestFunc=TestTCPListNoCase;
00150         Globals.Tests[TestID].FinishedSetup=TestTCPListNoCaseFinishedSetup;
00151         
00152         TCPDecoderID=GetDecoderByName("TCP");
00153 
00154         return TRUE;
00155 }

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