显示struct ip的IP地址

时间:2016-11-08 20:00:57

标签: c pcap

所以我在这里有这个代码:

void got_packet(u_char* args, struct pcap_pkhdr* hdr, const u_char* packet) {
    struct ether_header* eptr;
    eptr = (struct ether_header*)packet;
    struct ip* ip;
    ip = (struct ip*)(packet + sizeof(struct ether_header));

    printf("Source IP: %s\n", inet_ntoa(ip->ip_src));
}

如果我尝试打印以太网头(MAC地址),我没问题。 如果我尝试打印IP(最后一行代码),我得到这个:错误:错误:解除指向不完整类型的指针   printf("来源IP:%s \ n",inet_ntoa(ip-> ip_src));

谢谢!

0 个答案:

没有答案
相关问题