2015-05-09 40 views
-3

之前的預期「)」我有這樣的代碼:錯誤:「包」

void addSpammer(honeypot_command_packet packet){ 
      hashtable_put(spammer_table, packet->ip_source_address_big_endian, packet); 
     } 
    void addVulnerable(honeypot_command_packet packet){ 
     hashtable_put(vulnerable_table, packet->udp_dest_port_big_endian, packet); 
    } 

    void addEvil(honeypot_command_packet packet){ 
     hashtable_put(evil_table, packet, packet); 
    } 

    void rmSpammer(honeypot_command_packet packet){ 
     hashtable_remove(spammer_table, packet->ip_source_address_big_endian); 
    } 

    void rmVulnerable(honeypot_command_packet packet){ 
     hashtable_remove(vulnerable_table, packet->udp_dest_port_big_endian); 
    } 

    void rmEvil(honeypot_command_packet packet){ 
     hashtable_remove(evil_table, packet); 
    } 

    void print_stats(){ 
     puts("Printing stats..."); 
    } 

    void handle_packet_table(honeypot_command_packet pack){ 

      if(pack->secret_big_endian == HONEYPOT_SECRET){ 

        printf_m("This is a command packet %x \n", pack->cmd); 

        if(pack->cmd == HONEYPOT_ADD_SPAMMER){ 
          // handle addint a spammer 
          addSpammer(pack); 

        }else if(pack->cmd == HONEYPOT_ADD_EVIL){ 
          // handle adding an evil packet hash 
          addEvil(pack); 

        }else if(pack->cmd == HONEYPOT_ADD_VULNERABLE){ 
          // handle addint a vunlerable port 
          addVulnerable(pack); 

        }else if(pack->cmd == HONEYPOT_DEL_SPAMMER){ 
          // handle removing a spammer 
          rmSpammer(ip_source_address_big_endian); 

        }else if(pack->cmd == HONEYPOT_DEL_EVIL){ 
          //handle removing an evil packet 
          rmEvil(ip_source_address_big_endian); 

        }else if(pack->cmd == HONEYPOT_DEL_VULNERABLE){ 
          //handle removing a vulnurable port 
          rmVulnerable(udp_dest_port_big_endian); 

        }else if(pack->cmd == HONEYPOT_PRINT){ 
          print_stats(); 
          //handle printing from the packet 
        }else{ 
          printf_m("there is a problem with the data field \n"); 
        } 

      } 
      else{ 
       // the packet is not anything 
       //check if it is in any of the lists then increment the number of packets processed 
       void* *item; 
       if (hashtable_get(spammer_table, pack->ip_source_address_big_endian, *item) == 0){ 
       addSpammer(pack); 
       } 

       if (hashtable_get(vulnerable_table, pack->udp_dest_port_big_endian, *item) == 0){ 
       addVulnerable(pack); 
       } 

       if (hashtable_get(evil_table, pack, *item) == 0){ 
       addEvil(pack); 
       } 
       else{ 
       hashtable_put(good_table, pack, pack); 
       } 
      } 

      packets_arrived++; 
      bytes_arrived+=sizeof(pack); 
    } 

,我得到了以下錯誤:

network.c:94: error: expected ‘)’ before ‘packet’

network.c:98: error: expected ‘)’ before ‘packet’

network.c:102: error: expected ‘)’ before ‘packet’

network.c:106: error: expected ‘)’ before ‘packet’

network.c:110: error: expected ‘)’ before ‘packet’

network.c:114: error: expected ‘)’ before ‘packet’

network.c:122: error: expected ‘)’ before ‘pack’

我真的不知道如何解決這些問題,我檢查了parens已經匹配了。

+0

「honeypot_command_packet」定義在哪裏? –

+1

您的示例中沒有行號,很難說清楚。此外,還有關於您正在使用的類型的信息。請發佈一個展示失敗的簡單例子。 –

+0

這些只有88行,對吧?我可能錯過了一兩次,但沒有更多。 – usr2564301

回答

1

問題是您正在嘗試使用honeypot_command_packet類型,但您顯然沒有先前定義該類型。也許你錯過了需要的#include,或者該類型需要被認定爲some_namespace::hoenypot_command_packet

+2

應用'c'標記,但不應用'C++'標記。我會假定命名空間不是問題。可能缺少'#include'。 –

1

編譯器被honeypot_command_packet弄糊塗了。 @ChrisDodd已經回答了這個問題,我的答案增加了一個有效的例子。我得到了更多的MSVC編譯器錯誤消息,但第一個就像OP的每個錯誤消息honeypot_command_packet一樣。

void addEvil(honeypot_command_packet packet) { 
} 

int main() { 
    return 0; 
} 

MSVC編譯器輸出:

test.c 
test.c(1) : error C2146: syntax error : missing ')' before identifier 'packet' 
test.c(1) : error C2061: syntax error : identifier 'packet' 
test.c(1) : error C2059: syntax error : ';' 
test.c(1) : error C2059: syntax error : ')' 
test.c(1) : error C2449: found '{' at file scope (missing function header?) 
test.c(2) : error C2059: syntax error : '}' 
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.EXE"' :return code '0x2' 
Stop. 

但是,當我加入這行

typedef char *honeypot_command_packet; 

它完全編譯。