Linux下C语言网络编程tcp.h头文件问题,求帮助

jch64899426 jch64899426 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
各位大大,我最近在写一个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的都可以。实在是不知道为什么,请各位帮帮忙吧,谢谢了
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
jch64899426
C语言 70,040 成员 243,237 内容