#include <iostream>
using namespace std;
int main()
{
FILE * fp = NULL:
FILE * fp2=NULL:
if( !(fp = fopen("./wang.pcap","r+")))
{
cout << "open file error!" << endl;
return -1;
}
if( !(fp2 = fopen("./wang.txt","w+")))
{
cout << "create file error!" << endl;
return -1;
}
char sBuf[512]={0}; //read a line
char sTmp[512]={0}; //cache result
char *pBeg=NULL:
char *pEnd=NULL;
while(fgets(sBuf,sizeof(sBuf),fp))
{
//new line
pBeg=NULL:
memset(sTmp,0x00,sizeof(sTmp));
//find SELECT
if( (pBeg=strstr(sBuf,"SELECT")) || (pBeg=strstr(sBuf,"select")) ||
(pBeg=strstr(sBuf,"LECT")) || (pBeg=strstr(sBuf,"lect")) )
{
if(pEnd=strchar(pBeg,';'))
{
if(*pBeg == 'L')
{
strncpy(sTmp,"SE",2);
strncpy(sTmp+2,pBeg,pEnd-pBeg);
}
if(*pBeg == 'l')
{
strncpy(sTmp,"se",2);
strncpy(sTmp+2,pBeg,pEnd-pBeg);
}
else
{
strncpy(sTmp,pBeg,pEnd-pBeg);
}
//check
if(!strstr(sTmp,"from") && !strstr(sTmp,"FROM"))
{
continue;
}
//save one result
fprintf(fp2,"%s\n",sTmp);
}
else
{
// ; is in next line?
pEnd=sBuf+strlen(sBuf)-1;
strncpy(sTmp,pBeg,pEnd-pBeg);
memset(sBuf,0x00,sizeof(sBuf));
fgets(sBuf,sizeof(sBuf),fp);
if(pEnd=strchar(sBuf,';'))
{
}
else
{
memset(sTmp,0x00,sizeof(sTmp));
continue;
}
}
}
//find not
else
{
}
}
return 0;
}
using namespace std;
int main()
{
FILE * fp = NULL:
FILE * fp2=NULL:
if( !(fp = fopen("./wang.pcap","r+")))
{
cout << "open file error!" << endl;
return -1;
}
if( !(fp2 = fopen("./wang.txt","w+")))
{
cout << "create file error!" << endl;
return -1;
}
char sBuf[512]={0}; //read a line
char sTmp[512]={0}; //cache result
char *pBeg=NULL:
char *pEnd=NULL;
while(fgets(sBuf,sizeof(sBuf),fp))
{
//new line
pBeg=NULL:
memset(sTmp,0x00,sizeof(sTmp));
//find SELECT
if( (pBeg=strstr(sBuf,"SELECT")) || (pBeg=strstr(sBuf,"select")) ||
(pBeg=strstr(sBuf,"LECT")) || (pBeg=strstr(sBuf,"lect")) )
{
if(pEnd=strchar(pBeg,';'))
{
if(*pBeg == 'L')
{
strncpy(sTmp,"SE",2);
strncpy(sTmp+2,pBeg,pEnd-pBeg);
}
if(*pBeg == 'l')
{
strncpy(sTmp,"se",2);
strncpy(sTmp+2,pBeg,pEnd-pBeg);
}
else
{
strncpy(sTmp,pBeg,pEnd-pBeg);
}
//check
if(!strstr(sTmp,"from") && !strstr(sTmp,"FROM"))
{
continue;
}
//save one result
fprintf(fp2,"%s\n",sTmp);
}
else
{
// ; is in next line?
pEnd=sBuf+strlen(sBuf)-1;
strncpy(sTmp,pBeg,pEnd-pBeg);
memset(sBuf,0x00,sizeof(sBuf));
fgets(sBuf,sizeof(sBuf),fp);
if(pEnd=strchar(sBuf,';'))
{
}
else
{
memset(sTmp,0x00,sizeof(sTmp));
continue;
}
}
}
//find not
else
{
}
}
return 0;
}