问题描述
我需要做一个抓包器,代码如下,我的主机ip地址是192.168.1.110,可是结果却是sudo./sniffall0157.55.56.161192.168.1.105192.168.1.105157.55.56.161157.55.56.161192.168.1.105192.168.1.105157.55.56.161157.55.56.161192.168.1.105这个不对吧?之前我尝试过用netinet/ip.h和netinet/ether.h下面的structip和structether来算offset,可是结果的ip更奇怪了,大家看看是哪里出了问题,谢谢!#include<pcap.h>#include<stdio.h>#include<stdlib.h>#include<netinet/in.h>#include<arpa/inet.h>//#include<netinet/ip.h>//#include<netinet/if_ether.h>//#include<netinet/ether.h>structether_header{u_int8_tether_dhost[6];u_int8_tether_shost[6];u_int16_tether_type;};typedefu_int32_tin_addr_t;structip_header{#ifdefWORDS_BIGENDIANu_int8_tip_version:4;u_int8_tip_header_length:4;#elseu_int8_tip_header_length:4;u_int8_tip_version:4;#endifu_int8_tip_tos;u_int16_tip_length;u_int16_tip_id;u_int16_tip_off;u_int8_tip_ttl;u_int8_tip_protocol;u_int16_tip_checksum;structin_addrip_source_address;structin_addrip_destination_address;};voidgetPacket(u_char*args,conststructpcap_pkthdr*pkthdr,constu_char*packet){structip_header*ip;ip=(structip_header*)(packet+sizeof(structether_header));char*src=inet_ntoa(ip->ip_source_address);printf("%s",src);char*dst=inet_ntoa(ip->ip_destination_address);printf("%sn",dst);}