Qt - 错误:无效使用成员函数(你忘了'()'吗?)

时间:2014-05-22 12:37:08

标签: c++ qt

你好,我是Qt开发新手,

我只想将一些c ++代码移植到Qt。在c ++上它可以成功构建,但是当我尝试将代码移植到Qt时它会显示

错误:无效使用会员功能(您是否忘记了'()'?)

这是我的错误代码:

capture_loop(pdev, packets, (pcap_handler)parse_packet);

这是我的职责:

void MainWindow::capture_loop(pcap_t* pdev, int packets, pcap_handler func){
int linktype;

// Determine the datalink layer type.
if ((linktype = pcap_datalink(pdev)) < 0)
{
    printf("pcap_datalink(): %s\n", pcap_geterr(pdev));
    return;
}

// Set the datalink layer header size.
switch (linktype)
{
case DLT_NULL:
        linkhdrlen = 4;
    break;

case DLT_EN10MB:
    linkhdrlen = 14;
    break;

case DLT_SLIP:
case DLT_PPP:
    linkhdrlen = 24;
    break;

default:
    printf("Unsupported datalink (%d)\n", linktype);
    return;
}

// Start capturing packets.
if (pcap_loop(pdev, packets, func, 0) < 0)
    printf("pcap_loop failed: %s\n", pcap_geterr(pdev));}
void MainWindow::parse_packet(u_char *user, struct pcap_pkthdr *packethdr,u_char *packetptr){
struct ip* iphdr;
struct icmphdr* icmphdr;
struct tcphdr* tcphdr;
struct udphdr* udphdr;
char iphdrInfo[256], srcip[256], dstip[256];
unsigned short id, seq;

// Skip the datalink layer header and get the IP header fields.
packetptr += linkhdrlen;
iphdr = (struct ip*)packetptr;
strcpy(srcip, inet_ntoa(iphdr->ip_src));
strcpy(dstip, inet_ntoa(iphdr->ip_dst));
sprintf(iphdrInfo, "ID:%d TOS:0x%x, TTL:%d IpLen:%d DgLen:%d",ntohs(iphdr->ip_id), iphdr->ip_tos, iphdr->ip_ttl,4*iphdr->ip_hl, ntohs(iphdr->ip_len));

// Advance to the transport layer header then parse and display
// the fields based on the type of hearder: tcp, udp or icmp.
packetptr += 4*iphdr->ip_hl;
switch (iphdr->ip_p)
{
case IPPROTO_TCP:
    tcphdr = (struct tcphdr*)packetptr;
    printf("TCP  %s:%d -> %s:%d\n", srcip, ntohs(tcphdr->source),dstip, ntohs(tcphdr->dest));
    printf("%s\n", iphdrInfo);
    printf("%c%c%c%c%c%c Seq: 0x%x Ack: 0x%x Win: 0x%x TcpLen: %d\n",
           (tcphdr->urg ? 'U' : '*'),
           (tcphdr->ack ? 'A' : '*'),
           (tcphdr->psh ? 'P' : '*'),
           (tcphdr->rst ? 'R' : '*'),
           (tcphdr->syn ? 'S' : '*'),
           (tcphdr->fin ? 'F' : '*'),
           ntohl(tcphdr->seq), ntohl(tcphdr->ack_seq),
           ntohs(tcphdr->window), 4*tcphdr->doff);
    break;

case IPPROTO_UDP:
    udphdr = (struct udphdr*)packetptr;
    printf("UDP  %s:%d -> %s:%d\n", srcip, ntohs(udphdr->source),
           dstip, ntohs(udphdr->dest));
    printf("%s\n", iphdrInfo);
    break;

case IPPROTO_ICMP:
    icmphdr = (struct icmphdr*)packetptr;
    printf("ICMP %s -> %s\n", srcip, dstip);
    printf("%s\n", iphdrInfo);
    memcpy(&id, (u_char*)icmphdr+4, 2);
    memcpy(&seq, (u_char*)icmphdr+6, 2);
    printf("Type:%d Code:%d ID:%d Seq:%d\n", icmphdr->type, icmphdr->code,
           ntohs(id), ntohs(seq));
    break;
}
printf("=============================================================\n\n");}

0 个答案:

没有答案