Linux下C语言网络编程tcp.h头文件问题,求帮助
各位大大,我最近在写一个Linux下的端口扫描软件,需要自己设置发送包的ip和tcp首部内容。
我就包含了
#include <netinet/ip.h>
#include <netinet/tcp.h>这两个文件。然后在后面的程序中,用到了如下代码:
iph->ip_hl = 5;
iph->ip_v = 4;
iph->ip_tos = 0;
iph->ip_len = sizeof (struct ip) + sizeof (struct tcphdr);
iph->ip_id = htonl (54321);
iph->ip_off = 0;
iph->ip_ttl = 255;
iph->ip_p = 6;
iph->ip_sum = 0;
iph->ip_src = *(struct in_addr *)phost->h_addr_list[0];
iph->ip_dst.s_addr = sin.sin_addr.s_addr;
tcph->th_sport = htons (5554);
tcph->th_dport = htons (Port);
tcph->th_seq = random ();
tcph->th_ack = 0;
tcph->th_x2 = 0;
tcph->th_off = 0;
tcph->th_flags = TH_SYN;
tcph->th_win = htonl (65535);
tcph->th_sum = 0;
tcph->th_urp = 0;
用GCC编译发生错误,提示
structure has no member named "th_sport"
structure has no member named "th_dport"
structure has no member named "th_seq"
.
.
.
就是tcp.h定义的所有的变量都用不了,但是ip.h的都可以。实在是不知道为什么,请各位帮帮忙吧,谢谢了