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的都可以。实在是不知道为什么,请各位帮帮忙吧,谢谢了
我就包含了
#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的都可以。实在是不知道为什么,请各位帮帮忙吧,谢谢了
...全文
相关推荐
linux下C语言网络编程会话聊天室
在Linux环境下,C语言网络编程是一项基础且重要的技能,它能帮助开发者构建高效、可靠的网络应用。
linux C语言 网络编程教程及源码
linux C语言 网络编程教程及源码一、网络应用层编程1、Linux网络编程01——网络协议入门2、Linux网络编程02——无连接和面向连接的区别3、Linux网络编程03——字节序和地址转换4、
linux环境C语言tcp聊天室
在Ubuntu这样的Linux环境中,开发C语言程序通常需要包含相应的头文件(如`<sys/socket.h>`,`<netinet/in.h>`等)并链接必要的库(如`-lsocket`和`-lnsl
Linux下C语言socket网络编程简例
【资源摘要信息】: "本资源提供了一个简单的Linux下C语言实现的TCP socket网络编程示例,涵盖了服务端和客户端的基本操作。"在Linux系统中,C语言进行socket网络编程通常涉及T
linux下网络编程TCP客户端和服务器端数据传输代码
在Linux环境下进行网络编程,TCP协议是最常用的传输层协议之一,因为它提供了面向连接、可靠的数据传输服务。本篇文章将深入探讨如何使用C语言在Linux下编写TCP客户端和服务器端的数据传输代码。


