int main() { char *filename = new char[100]; std::strcpy(filename,"out.txt"); int count = CountLines(filename); std::string first = ReturnString(filename,0); for (int i = 1;i < count;i ++) { std::string second = ReturnString(filename,count - i); char *buf = new char[1000000000]; std::strcpy(buf,second.c_str()); char *ptrn = new char[1000000000]; std::strcpy(ptrn,first.c_str()); int blen = strlen(buf); int plen = strlen(ptrn); int *skip = MakeSkip(ptrn,plen); int *shift = MakeShift(ptrn,plen); int result = BMSearch(buf, blen, ptrn, plen, skip, shift); printf("%d\t", result); delete []buf; delete []ptrn; } return 0; }
int main() { char *buf = "hellomyworld"; char *ptrn = "mywor"; int blen = strlen(buf); int plen = strlen(ptrn); int *skip = MakeSkip(ptrn,plen); int *shift = MakeShift(ptrn,plen); int result = BMSearch(buf, blen, ptrn, plen, skip, shift); printf("result = %d\n", result); return 0; }
static bool http_mt(const struct sk_buff *skb,const struct xt_action_param *par) { struct iphdr *iph; const struct tcphdr *tcph; char *payload; char *ptmp; unsigned char host_buf[66]; int host_len; char *all="all\0"; struct ipt_http_info *http_info; //unsigned int data_len=0; /* IP header checks: fragment. */ spin_lock_bh(&http_lock); if(!can_handle(skb)){ spin_unlock_bh(&http_lock); return false; } if(skb_is_nonlinear(skb)){ if(skb_linearize(skb) != 0){ if (net_ratelimit()) printk(KERN_ERR "http: failed to linearize " "packet, bailing.\n"); spin_unlock_bh(&http_lock); return false; } } http_info = (struct ipt_http_info *)par->matchinfo; iph = ip_hdr(skb); tcph = (void *)iph + (iph->ihl<<2); if(tcph !=NULL){ payload = (char *)tcph + (tcph->doff << 2); if(payload ==NULL){ spin_unlock_bh(&http_lock); return false; } }else{ spin_unlock_bh(&http_lock); return false; } if(ntohs(tcph->dest) == 80){ if(strstr(payload,"GET")||strstr(payload,"POST")){ //data_len = ntohs(iph->tot_len)-(iph->ihl*4)-(tcph->doff*4); ptmp = strstr(payload,"Host"); if(ptmp == NULL ){ spin_unlock_bh(&http_lock); return false; } if(!strncmp(http_info->pattern,all,strlen(all))){ spin_unlock_bh(&http_lock); return true; } memset(host_buf,0,66); host_len = get_host_name(ptmp+6,host_buf,sizeof(host_buf)); if(BMSearch(host_buf,host_len,http_info->pattern,strlen(http_info->pattern), MakeSkip(http_info->pattern,strlen(http_info->pattern)), MakeShift(http_info->pattern,strlen(http_info->pattern)))){ spin_unlock_bh(&http_lock); return true; } spin_unlock_bh(&http_lock); return false; }else{ spin_unlock_bh(&http_lock); return false; } } spin_unlock_bh(&http_lock); return false; }