2010-05-31 55 views
2

我們正在構建一個NAT程序,我們更改來自我們內部子網的每個數據包, 通過libnet函數更改它的源IP地址(使用libpcap捕獲數據包,將其放入 sniff結構並使用libnet構建新數據包)在libnet(tcp數據包)中建立一個http數據包,請儘快幫助我們。我們被卡住!

通過TCP,syn/ack數據包在更改後良好,並且當HTTP-GET請求到來時,我們可以通過wireshark看到校驗和字段中存在錯誤。 所有其他字段均爲與原始數據包完全一樣。

有人知道會導致這個問題嗎? 在其他包新的校驗和計算,因爲它應該是.. 但它不是HTTP數據包..

+1

這是功課?或 'plz向德codez' ......可你至少附上一些代碼對我們來說我們不介意,如果讀者... – t0mm13b 2010-05-31 10:15:43

+0

(IP-> ip_p == IP_TYPE_TCP) \t \t { \t \t \t協議= 0; (ip-> ip_len)-TH_OFF(tcp)* 4 -IP_HL(ip)* 4;其中, \t \t \t \t \t \t如果(payload_s) \t \t \t \t有效載荷=(字符*)(分組+ SIZE_ETHERNET + TH_OFF(TCP)* 4 + IP_HL(IP)* 4); \t \t \t別的 \t \t \t \t有效載荷= NULL; \t \t \t \t } – Hila 2010-05-31 10:35:51

+0

l = libnet_init(LIBNET_RAW4,config。extNIC,errbuf); 如果(協議== 0)// TCP { \t \t如果(TH_OFF(TCP)* 4> TCP_HEADER_SIZE) \t \t { \t \t \t選項=(字符*)數據包+ 54; \t \t \t options_s = TH_OFF(tcp)* 4 - TCP_HEADER_SIZE; \t \t \t popt = libnet_build_tcp_options((u_int8_t *)options,options_s,1,0); \t \t } \t \t \t \t pTAG中= libnet_build_tcp( \t srcPort,//源端口 \t ntohs和(TCP-> th_dport),//目的端口 \t htonl(TCP-> th_seq),//序列號 \t再用ntohl(TCP-> th_ack),// ACK號 \t TCP-> th_flags,//標誌 – Hila 2010-05-31 10:36:57

回答

2

現代的以太網卡可以在計算硬件校驗,所以TCP協議棧往往卸載作業卡片。因此,在Wireshark中校驗和是無效的。

邊注:有一個在Wireshark的一個選項,以驗證校驗:

Edit 
    Preferences 
    Protocols 
     TCP 
     Validate the TCP checksum if possible 

關閉這個功能停止Wireshark的嘮叨你與校驗。

+0

如果我們更改wireshark,校驗和看起來不錯, 但我們仍然沒有從服務器得到任何我們的HTTP-GET數據包的答案... – Hila 2010-05-31 10:33:17

0

這實際上是否造成問題 - 即帶有「錯誤校驗和」的數據包是否被丟棄或處理不正確?或者你只是擔心「錯誤的校驗和」通知?如果數據包處理正常,這可能只是校驗和卸載,無需擔心。

Wireshark documentation說:

如果接收校驗是錯誤的,Wireshark的甚至不會看到該數據包,因爲以太網硬件內部扔掉的包。

+0

我們需要爲這個http-get數據包得到答案,因爲我們將它發送給應該回答我們的服務器。 .. 在服務器端,我們看到wireshark與校驗和錯誤的數據包..我們沒有得到答案,因爲我們認爲httpget數據包不好... – Hila 2010-05-31 10:31:30

+0

「沒有迴應」 - 所以,只是爲了澄清:您從客戶端發送SYN,服務器發回SYN/ACK,客戶端發送ACK,客戶端發送第一個數據包,沒有更多的數據包從服務器接收 - 這是正確的嗎? 1)你是單獨發送ACK還是數據包,還是一個包? 2)您是否發送完整的GET請求? (服務器在看到請求標頭結束之前不會響應) 3)如果您發出GET請求,您是否會得到正常響應通過瀏覽器? – Piskvor 2010-05-31 11:34:12

0

嘿,回答她的名字。 GET和ACK是分開的,GET請求是完全發送的,這是基於數據包是由Firefox或Wget發送的。我們不創建數據包,也不創建服務器(這是Apache)的響應。

我們的代碼只是在中間運行。除了客戶機和服務器之外,我們還有第三臺機器,並且所有這三臺機器都是虛擬機(在VMWare Server [NAT,Client = Ubuntu; Server = Fedora]中)。它有2個NIC(每個NIC都相應連接到每個子網),目標是更改源IP和源端口字段(在網絡流量的兩個方向上)。

感謝有關TCP校驗和卸載的解釋,這是由wireshark推測發生的,但在我看來並非如此,因爲錯誤也出現在服務器端(不是100%確定是否排除了這種可能性,想法?)。 如果我是對的,可能是校驗和不正確的原因是什麼?

下面是當前的代碼的鏈接: http://rapidshare.com/files/393704745/13.5.10.tar.gz

非常感謝, 特拉維夫。

如果它是作爲代碼更好的在這裏,你去那裏:






#include "./main.h" 


int main(int argc, char **argv) 
{ 
    pcap_t *pcapInt, *pcapExt;      /* pcap descriptor */ 
    u_char *intPacket, *extPacket; 
    int i; 
    struct pcap_pkthdr intPkthdr, extPkthdr; 
    char errbuf[PCAP_ERRBUF_SIZE]; 
    struct bpf_program filter_code; 
    bpf_u_int32 intLocalNet, intNetmask, extLocalNet; 

    for(i=0;i to quit\n"); 

    /* read the configuration file and store it's data in an array */ 
    LIBXML_TEST_VERSION 
    xmlNode *cur_node = xmlDocGetRootElement(xmlReadFile(((argv[1]) != NULL ? argv[1] : "conf.xml"), NULL, 0)); 
    strcpy(config.filter, ""); 

    XMLtoConf(cur_node); 
    strcat(config.filter, " and not src host 192.168.191.137"); 
    printf("FILTER: %s\n", config.filter); 


    /* get network number and mask associated with the internal capture device */ 
    if (pcap_lookupnet(config.intNIC, &intLocalNet, &intNetmask, errbuf) == -1) { 
     fprintf(stderr, "Couldn't get netmask for device %s: %s\n", 
      config.intNIC, errbuf); 
     intLocalNet = 0; 
     intNetmask = 0; 
    } 

    /* open internal capture device */ 
    pcapInt = pcap_open_live(config.intNIC, SNAP_LEN, 1, 1000, errbuf); 
    if (pcapInt == NULL) { 
     fprintf(stderr, "Couldn't open device %s: %s\n", config.intNIC, errbuf); 
     exit(EXIT_FAILURE); 
    } 
    /* open external capture device */ 
    pcapExt = pcap_open_live(config.extNIC, SNAP_LEN, 1, 1000, errbuf); 
    if (pcapExt == NULL) { 
     fprintf(stderr, "Couldn't open device %s: %s\n", config.extNIC, errbuf); 
     exit(EXIT_FAILURE); 
    } 

    /* make sure we're capturing on an Ethernet device [2] */ 
    if (pcap_datalink(pcapInt) != DLT_EN10MB) { 
     fprintf(stderr, "%s is not an Ethernet\n", config.intNIC); 
     exit(EXIT_FAILURE); 
    } 
    if (pcap_datalink(pcapExt) != DLT_EN10MB) { 
     fprintf(stderr, "%s is not an Ethernet\n", config.extNIC); 
     exit(EXIT_FAILURE); 
    } 

    /* compile the internal filter expression */ 
    if (pcap_compile(pcapInt, &filter_code, config.filter, 1, intLocalNet) == -1) { //adsvfhakdhvkahdvkadh 
     fprintf(stderr, "Couldn't parse filter %s: %s\n", 
      argv[1], pcap_geterr(pcapInt)); 
     exit(EXIT_FAILURE); 
    } 
    /* compile the external filter expression */ 
    if (pcap_compile(pcapExt, &filter_code, NULL, 1, extLocalNet) == -1) { //adsvfhakdhvkahdvkadh 
     fprintf(stderr, "Couldn't parse filter %s: %s\n", 
      argv[1], pcap_geterr(pcapExt)); 
     exit(EXIT_FAILURE); 
    } 

    /* apply the compiled internal filter */ 
    if (pcap_setfilter(pcapInt, &filter_code) == -1) { 
     fprintf(stderr, "Couldn't install filter %s: %s\n", 
      argv[1], pcap_geterr(pcapInt)); 
     exit(EXIT_FAILURE); 
    } 
    //apply the compiled external filter 
    if (pcap_setfilter(pcapExt, &filter_code) == -1) { 
     fprintf(stderr, "Couldn't install filter %s: %s\n", 
      argv[1], pcap_geterr(pcapExt)); 
     exit(EXIT_FAILURE); 
    } 
    while (1 == 1) 
    {  
     intPacket = (u_char*)pcap_next(pcapInt, &intPkthdr); 
     extPacket = (u_char*)pcap_next(pcapExt, &extPkthdr); 
     if (intPacket != NULL) 
     { 
      sniff(intPacket,0); 
     } 
     if (extPacket != NULL) 
     { 
      sniff(extPacket,1); 
     } 
    } 

    printf("\nCapture complete.\n"); 
    /* cleanup */ 
    pcap_freecode(&filter_code); 
    pcap_close(pcapInt); 
    return (EXIT_SUCCESS); 
} 

int isStrBlank(unsigned char *s) 
{ 
    if (!s || strcmp((char *)s, "") == 0) return 1; 

    while(*s) { 
    if ((' ' != *s) && ('\n' != *s) && ('\r' != *s) && ('\t' != *s)) return 0; 
    ++s; 
    } 
    return 1; 
} 

static void XMLtoConf(xmlNode* node) 
{ 
    /* 
    * this initialize the library and check potential ABI mismatches 
    * between the version it was compiled for and the actual shared 
    * library used. 
    */ 
    LIBXML_TEST_VERSION 
    xmlNode *cur_node = node; 
    int i,flag=0; 
    for (; cur_node; cur_node = cur_node->next) { 
     if (cur_node->type == XML_ELEMENT_NODE) { 
       //if (isStrBlank(cur_node->children->content) == 1) continue; 

       if (strcmp((char *)cur_node->name, "subnet_address") == 0){ 
        strcat(config.filter, "src net "); 
        strcat(config.filter,(char *)cur_node->children->content); 
       } 
       //printf("1: %s", config.filter); 
       if (strcmp((char *)cur_node->name, "NIC") == 0){ 
        if (strcmp((char *)cur_node->parent->name, "internal") == 0){ 
         config.intNIC = strdup((char *)cur_node->children->content); 
        } 
        else{ 
         config.extNIC = strdup((char *)cur_node->children->content); 
        } 
       } 
       for (i = 0; strncmp((char *)cur_node->name, "machine_", 8) == 0; i++){ 

        strcat(config.filter, " and not"); 
        strcat(config.filter, " src host "); 
        flag=1; 
        strcat(config.filter, (char *)cur_node->children->content); 
        cur_node = cur_node->next; 
       } 


     } 
     XMLtoConf(cur_node->children); 
    } 
    /* 
    *Free the global variables that may 
    *have been allocated by the parser. 
    */ 
    xmlCleanupParser(); 
    /* 
    * If device is NULL, that means the user did not specify one and is 
    * leaving it up libpcap to find one. 
    */ 
} 


void sniff(const u_char *packet , int flag) 
{ 
    int i,x,tcpOpen=0; 
    int protocol=-1; // 0- tcp, 1- udp, 2 -icmp 
    tcp = (struct sniff_tcp*)(packet + 34); //skipping the ethernet and IP layers 
    udp = (struct sniff_udp *)(packet + 34); //skipping the ethernet and IP layers 
    ip = (struct sniff_ip *)(packet + SIZE_ETHERNET); 
    icmp = (struct sniff_icmp *)(packet+ 34); 
    ether = (struct sniff_ethernet *)(packet); 

    printf("/n1--%d/n",IP_HL(ip)*4); 
    //if(ntohs(tcp->th_sport) == 80 || ntohs(tcp->th_dport) == 80) 
     //{ 

     if(ip->ip_p==IP_TYPE_TCP) 
     { 
      protocol = 0; 
      payload_s = ntohs(ip->ip_len) - TH_OFF(tcp)*4 - IP_HL(ip)*4; 

      if (payload_s) 
       payload = (char*)(packet + SIZE_ETHERNET + TH_OFF(tcp)*4 + IP_HL(ip)*4); 
      else 
       payload = NULL; 

     } 
     else if(ip->ip_p == IP_TYPE_UDP){ 
      protocol = 1; 
      payload_s = ntohs(ip->ip_len) - ntohs(udp->udp_len) - IP_HL(ip)*4; 

      if (payload_s) 
       payload = (char*)(packet + SIZE_ETHERNET + ntohs(udp->udp_len) + IP_HL(ip)*4); 
      else 
       payload = NULL; 
     } 
     else if(ip->ip_p == IP_TYPE_ICMP) 
     { 
      protocol = 2; 
      payload_s = ntohs(ip->ip_len) - 8 - IP_HL(ip)*4; 

      if (payload_s) 
       payload = (char*)(packet + SIZE_ETHERNET + 8 + IP_HL(ip)*4); 
      else 
       payload = NULL; 
     } 


      if(flag == 0)// we got a packet from the internal 
      { 
       if(ip->ip_p == IP_TYPE_TCP) 
       { 
        for(i=0;iip_p) 
           if(nTable[i].ip_src.s_addr == ip->ip_src.s_addr) 
            if(nTable[i].ip_dst.s_addr == ip->ip_dst.s_addr) 
             if(ntohs(nTable[i].srcPort) == ntohs(tcp->th_sport)) 
              if(ntohs(nTable[i].dstPort) == ntohs(tcp->th_dport)) 
              { 
               printf("we are in an open connection \n"); 
               changeSrcPacket(packet ,(i+2000)%8000 ,protocol); 
               tcpOpen = 1; 
               break; 
              } 
        }   
       } 
       if(tcpOpen == 0) 
       { 
        for(i=0;iip_p == IP_TYPE_UDP ||ip->ip_p == IP_TYPE_TCP ) 
         { 
          if(nTable[i].free==0) 
          { 
           nTable[i].free=1; 
           nTable[i].ip_src = ip->ip_src; 
           nTable[i].ip_dst = ip->ip_dst; 
           nTable[i].srcPort = tcp->th_sport; 
           nTable[i].dstPort = tcp->th_dport; 
           nTable[i].protocol = ip->ip_p; 
           //printf("index : %d ipsrc : %s srcport : %d\n",i,inet_ntoa(nTable[i].ip_src),ntohs(nTable[i].srcPort)); 
           ////////////change packet and send it with the src ip of the nat machine 
           ///////////and the src port is (i+2000)%8000 
           changeSrcPacket(packet ,(i+2000)%8000 ,protocol); 
           break; 
          } 
         } 
         else 
         { 
          if(icmpTable[i].free == 0) 
          { 
           icmpTable[i].free=1; 
           icmpTable[i].ip_src = ip->ip_src; 
           icmpTable[i].ip_dst = ip->ip_dst; 
           icmpTable[i].protocol = ip->ip_p; 
           icmpTable[i].icmp_type = icmp->icmp_type; 
           icmpTable[i].icmp_id1 = icmp->icmp_id1; 
           changeSrcPacket(packet ,-1 ,protocol); 
           break; 
          } 
         } 
        } 
       } 
      } 
      else // flag = 1 
      { 
      // we got a packet from the external. we want to send it to the right 
      // place in the internal 

      //nTable[(tcp->th_dport-2000)%8000]; 

      //printf("dst: %d , src: %d \n",ntohs(tcp->th_dport),ntohs(tcp->th_sport)); 

       if(ip->ip_p== IP_TYPE_ICMP) 
       { 
        changeDstPacket (packet,-1,protocol); 
       } 
       else 
       { 
        for(x=0;xip_p == IP_TYPE_TCP) 
         { 
          if(((int)(ntohs(tcp->th_dport))-2000)%8000 == x && nTable[x].free == 1) 
          { 
           changeDstPacket (packet,x,protocol); 
           break; 
          } 
         } 
         else 
         { 
          if(((int)(ntohs(udp->udp_destport))-2000)%8000 == x && nTable[x].free == 1) 
          { 
           changeDstPacket (packet,x,protocol); 
           break; 
          } 

         } 
        } 
       }  
      // we create a packet with thw same src ip and port as we got 
      // and only the dst port and ip will be the ones that are 
      //saved in nTable[(tcp->th_dport-2000)%8000] 
      // now if it is in udp we will put 0 in nTable[(tcp->th_dport-2000)%8000].free 


      } 

} 

void changeSrcPacket(const u_char *packet , int srcPort, int protocol) 
{ 
    libnet_t *l; 
    libnet_ptag_t ipv, ptag, popt,icmp; 
    char errbuf[LIBNET_ERRBUF_SIZE]; 
    uint32_t nat_adder; 

    size_t ip_hlen=IP_HL(ip)*4; 
    size_t ip_len=ntohs(ip->ip_len); 

    size_t tcp_len = ip_len - ip_hlen; 

    printf("\n%d %d %d %d",IP_HL(ip),ip_hlen,ip_len,tcp_len); 


    icmp = ptag = ipv = LIBNET_PTAG_INITIALIZER; 


    nat_adder = libnet_name2addr4(l,"192.168.191.137",LIBNET_DONT_RESOLVE); 

    l = libnet_init(LIBNET_RAW4,config.extNIC, errbuf); 

    if(protocol == 0)//TCP 
    { 

     if(TH_OFF(tcp)*4 > TCP_HEADER_SIZE) 
     { 
       options = (char*)packet + 54; 
       options_s = TH_OFF(tcp)*4 - TCP_HEADER_SIZE; 
       popt = libnet_build_tcp_options((u_int8_t*)options,options_s, l,0);  
     } 

     ptag = libnet_build_tcp(
      srcPort, // source port 
      ntohs(tcp->th_dport), // dest port 
      htonl(tcp->th_seq), // sequence number 
      ntohl(tcp->th_ack), // ack number 
      tcp->th_flags, // flags 
      ntohs(tcp->th_win), // window size 
      0, // checksum 
      ntohs(tcp->th_urp), // urg ptr 
      TH_OFF(tcp)*4, // total length of the TCP packet 
      (u_int8_t*)payload, // response 
      payload_s, // response_length 
      l, // libnet_t pointer 
      ptag // ptag 
     ); 


      printf("%d, %d, %d, %d, %d\n", TH_OFF(tcp)*4, IP_HL(ip)*4, payload_s, ntohs(ip->ip_len),TH_OFF(tcp)*4); 
      if(ptag==-1) 
      { 
       fprintf(stderr, "Error building TCP header: %s\n",libnet_geterror(l)); 
       exit(1); 
      } 

    if (libnet_do_checksum(l, (u_int8_t*)ip,IPPROTO_TCP, TH_OFF(tcp)*4) udp_destport), /* destination port */ 
       udp->udp_len, /* packet length */ 
       0, /* checksum */ 
       (u_int8_t*)payload, /* payload */ 
       payload_s, /* payload size */ 
       l, /* libnet handle */ 
       ptag); /* libnet id */ 

      if(ptag==-1) 
      { 
      fprintf(stderr, "Error building UDP header: %s\n",libnet_geterror(l)); 
      exit(1); 
      } 

    } 

    // if(protocol == 2)//ICMP 
    //{ 
     ///add functions of icmp 
    // icmp = libnet_build_icmpv4_echo(
     //ICMP_ECHO, /* type */ 
     //0, /* code */ 
     //0, /* checksum */ 
     //icmp->icmp_id1, /* id */ 
     //icmp->icmp_seq1, /* sequence number */ 
     //payload, /* payload */ 
     //payload_s, /* payload size */ 
     //l, /* libnet context */ 
     //icmp); /* ptag */ 

     //if (icmp == -1) 
     //{ 
     // fprintf(stderr, "Can't build ICMP header: %s\n", 
     // libnet_geterror(l)); 

     //} 
    // } 


     ipv = libnet_build_ipv4(
               /* total length */ 
        ntohs(ip->ip_len), 
        ip->ip_tos,       /* type of service */ 
        ntohs(ip->ip_id),      /* identification */ 
        ntohs(ip->ip_off),       /* fragmentation */ 
        ip->ip_ttl,       /* time to live */ 
        ip->ip_p,    /* protocol */ 
        0,       /* checksum */ 
        nat_adder,      /* (Nat) source */ 
        ip->ip_dst.s_addr,      /* destination */ 
        NULL,      /* payload */ 
        0,       /* payload size */ 
        l,       /* libnet handle */ 
        0);       /* ptag */ 

     if(ipv == -1) 
     { 
      fprintf(stderr,"Error building IP header: %s\n", libnet_geterror(l)); 
      exit(1); 
     } 

     /*if (libnet_do_checksum(l, (u_int8_t*)l, IPPROTO_IP, ntohs(ip->ip_len) + payload_s) th_flags == 0x01) 
      { 
       nTable[index].fin++; 
      } 
      if(tcp->th_flags == 0x11 && nTable[index].fin == 1) 
      { 
       nTable[index].fin++; 
      } 
      if(tcp->th_flags == 0x10 && nTable[index].fin == 2) 
      { 
       nTable[index].free = 0; 
       nTable[index].fin = 0; 
      } 
     } 


     // Fix IP header checksum 
    // ip->ip_sum = 0; 
    if (libnet_do_checksum(l, (u_int8_t*)ip,IPPROTO_IP, IP_HL(ip)*4) th_sport),ntohs(nTable[index].srcPort)); 
    printf("src ip : %s dst ip: %s\n",inet_ntoa(ip->ip_src), inet_ntoa(nTable[index].ip_src)); 

    ptag = ipv = LIBNET_PTAG_INITIALIZER; 

    if(protocol == 0 || protocol == 1) // udp or tcp 
    { 

     if(nTable[index].free == 1) 
     { 
      l = libnet_init(LIBNET_RAW4,config.intNIC, errbuf); 

      if(protocol == 0) //TCP 
      { 

       if(TH_OFF(tcp)*4 > TCP_HEADER_SIZE) 
       { 
        options = (char*)packet + 54; 
        options_s = TH_OFF(tcp)*4 - TCP_HEADER_SIZE; 
        popt = libnet_build_tcp_options((u_int8_t*)options,options_s, l,0); 

       } 

        ptag = libnet_build_tcp(
        ntohs(tcp->th_sport), // source port 
        ntohs(nTable[index].srcPort), // dest port 
        ntohl(tcp->th_seq), // sequence number 
        ntohl(tcp->th_ack), // ack number 
        tcp->th_flags, // flags 
        ntohs(tcp->th_win), // window size 
        0, // checksum 
        ntohs(tcp->th_urp), // urg ptr 
        TH_OFF(tcp)*4, // total length of the TCP packet 
        (u_int8_t*)payload, // response 
        payload_s, // response_length 
        l, // libnet_t pointer 
        ptag // ptag 
       ); 

        if(ptag==-1) 
        { 
        fprintf(stderr, "Error building TCP header: %s\n",libnet_geterror(l)); 
        exit(1); 
        } 
      } 

      if(protocol == 1)// UDP 
      { 
       ptag = libnet_build_udp(
        ntohs(udp->udp_srcport), /* source port */ 
        ntohs(nTable[index].srcPort), /* destination port */ 
        udp->udp_len, /* packet length */ 
        0, /* checksum */ 
        (u_int8_t*)payload, /* payload */ 
        payload_s, /* payload size */ 
        l, /* libnet handle */ 
        ptag); /* libnet id */ 

       if(ptag==-1) 
       { 
        fprintf(stderr, "Error building UDP header: %s\n",libnet_geterror(l)); 
        exit(1); 
       } 
      } 
     } 
    } 
    if(protocol == 2) // ICMP 
    { 
     for(i=0;i icmp_type) 
        if(icmpTable[i].ip_dst.s_addr == ip->ip_src.s_addr) 
         if(icmpTable[i].icmp_id1 == icmp->icmp_id1) 
         { 
          index = i; 
          break; 
         } 

     } 

     ///add functions of icmp 

    } 

       ipv = libnet_build_ipv4(
                 /* total length */ 
          ntohs(ip->ip_len), 
          ip->ip_tos,       /* type of service */ 
          ntohs(ip->ip_id),      /* identification */ 
          ntohs(ip->ip_off),       /* fragmentation */ 
          ip->ip_ttl,       /* time to live */ 
          ip->ip_p,    /* protocol */ 
          0,       /* checksum */ 
          ip->ip_src.s_addr,      /* (Nat) source */ 
          nTable[index].ip_src.s_addr,      /* destination */ 
          NULL,      /* payload */ 
          0,       /* payload size */ 
          l,       /* libnet handle */ 
          0);       /* ptag */ 
       if(ipv == -1) 
       { 
       fprintf(stderr,"Error building IP header: %s\n", libnet_geterror(l)); 
       exit(1); 
       } 

      /*if (libnet_do_checksum(l, (u_int8_t*)l, IPPROTO_IP, ntohs(ip->ip_len) + payload_s) th_flags == 0x01) 
        { 
         nTable[index].fin++; 
        } 
        if(tcp->th_flags == 0x11 && nTable[index].fin == 1) 
        { 
         nTable[index].fin++; 
        } 
        if(tcp->th_flags == 0x10 && nTable[index].fin == 2) 
        { 
         nTable[index].free = 0; 
         nTable[index].fin = 0; 
        } 
       } 
       else 
       { 
        nTable[index].free = 0; 
        nTable[index].fin = 0; 
       } 
      } 


      if (libnet_write(l) == -1) 
         fprintf(stderr, "Error writing packet: %s\n",libnet_geterror(l)); 
      libnet_destroy(l); 

} 
+0

在這個線程的歡鬧刻痕!我讚賞你的幽默感:) – 2010-05-31 20:23:18

+0

謝謝。 任何有關錯誤的想法? =] – 2010-05-31 20:59:41