ubuntu 编译出错
1.udpcksum.h:2:18: fatal error: pcap.h: 没有那个文件或目录
安装库:
libpcap-1.9.1
libnet
执行以下命令:
sudo ./configure
sudo make
sudo make install
2.编译出错
senddnsquery-libnet.c:31:40: error: ‘LIBNET_DNSV4_H’ undeclared (first use in this function)
修改如下
int packet_size = LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + 24;
^
senddnsquery-libnet.c:44:12: error: too few arguments to function ‘libnet_build_dnsv4’
修改如下
dns_tag = libnet_build_dnsv4(LIBNET_UDP_DNSV4_H,
1234 /* identification */,
0x0100 /* flags: recursion desired */,
1 /* # questions */, 0 /* # answer RRs */,
0 /* # authority RRs */, 0 /* # additional RRs */,
(uint8_t *)qbuf /* query */, 24 /* length of query */, l, dns_tag);
3.定义结构体(如果需要的话)
struct ipovly {
caddr_t ih_next, ih_prev; /* for protocol sequence q‘s */
u_char ih_x1; /* (unused) */
u_char ih_pr; //协议域
short ih_len; //这个相当于IP头部,len = data Len + udp HeaderLen + ip header
struct in_addr ih_src; //源地址
struct in_addr ih_dst; //目标地址
};
struct udpiphdr {
struct ipovly ui_i; //模仿IP的实现,会有很多便利
struct udphdr ui_u; /* udp header */
};
#define ui_next ui_i.ih_next
#define ui_prev ui_i.ih_prev
#define ui_x1 ui_i.ih_x1
#define ui_pr ui_i.ih_pr
#define ui_len ui_i.ih_len
#define ui_src ui_i.ih_src
#define ui_dst ui_i.ih_dst
#define ui_sport ui_u.uh_sport
#define ui_dport ui_u.uh_dport
#define ui_ulen ui_u.uh_ulen
#define ui_sum ui_u.uh_sum
4.没有libpcap.so.1文件错误
locate libpcap.so
将特定目录下的/usr/lib/x86_64-linux-gnu/libpcap.so.1.7.4 添加到文件/etc/ld.so.conf.d
最终成功!!!!!!!