错误:在“数据包”之前预期')'

时间:2015-05-09 19:31:11

标签: c gcc syntax

我有这段代码:

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:错误:预期')'在'数据包'之前

     

network.c:98:错误:预期')'在'数据包'之前

     

network.c:102:错误:预期')'在'数据包'之前

     

network.c:106:错误:预期')'在'数据包'之前

     

network.c:110:错误:预期')'在'数据包'之前

     

network.c:114:错误:预期')'在'数据包'之前

     

network.c:122:错误:预期')'在'pack'之前

我不确定如何解决这些问题,我检查了这些问题已经匹配了。

2 个答案:

答案 0 :(得分:1)

问题在于您尝试使用类型honeypot_command_packet,但您之前显然没有定义该类型。也许您错过了所需的#include,或者类型需要被限定为some_namespace::hoenypot_command_packet

答案 1 :(得分:1)

编译器被honeypot_command_packet搞糊涂了。 @ChrisDodd已经回答了这个问题,我的回答增加了一个有用的例子。我得到更多的MSVC编译器错误消息,但第一个是像honeypot_command_packet每次出现时OP的单个错误消息。

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;

它干净利落地编译。