关于数据包的ip头,tcp头,UDP头的几个参数意义.

YouHikari 2009-03-18 01:39:39
typedef struct tcpheader
{
unsigned short int sport;//信源端口
unsigned short int dport;//信宿端口
unsigned int th_seq;//序列号
unsigned int th_ack;//确认号
unsigned char th_x2:4;//
unsigned char th_off:4;//数据偏移,长度为4位
unsigned char Flags;//标志位
unsigned short int th_win;//窗口域
unsigned short int th_sum;//校验和
unsigned short int th_urp;//紧急指针
}TCP;

typedef struct ipheader
{
unsigned char ip_hl:4, ip_v:4; //IP头长度和IP版本号,各4位
unsigned char ip_tos;//服务类型
unsigned short int ip_len;//总长度
unsigned short int ip_id;//标识符
unsigned short int ip_off;//片偏移
unsigned char ip_ttl;//生存时间
unsigned char ip_p;//协议
unsigned short int ip_sum;//头校验和

unsigned int ip_sr;//信源端口 ;
unsigned int ip_ds;//信宿端口 ;
}IP;

typedef struct udphdr
{
unsigned short spor;//信源端口;
unsigned short dpor;//信宿端口 ;
unsigned short le;//总长度 ;
unsigned short cksu;//校验和 ;
}UDP; //8

其中那个参数标示的是数据包的发送IP和端口?

还有就是我在用原始套接字嗅探的时候
recv( ServerSock, buf, sizeof(buf),0);
本机向外发送的数据包也可以接收到,是吗?
...全文
277 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lin_style 2009-03-19
  • 打赏
  • 举报
回复
看了两遍,楞是没看明白什么意思。。。最近理解力很差。
expter 2009-03-19
  • 打赏
  • 举报
回复
抓包的话 用wpacp试一试。。。
YouHikari 2009-03-19
  • 打赏
  • 举报
回复
up,有人解释下吗?
YouHikari 2009-03-18
  • 打赏
  • 举报
回复
接受不到吗?我一开始也是这样以为的,但是我在分析我接受到的包的时候,提取出来的发送方的IP地址,就是ip_sr,有的时候是我自己的IP地址,而且跟一些嗅探软件抓的数据对比也能对上,这应该标示我发送的数据包也能被抓到啊.就下下面的2个包,我自己抓到的:
============================
03-18 15:36:30
接收IP:60.28.233.40
发送IP:192.168.0.101
接受Com:13228
发送Com:8000
方向:本机-->网络
协议:17
长度:69
Txt:﨎 B 9EIo€?僌?`-影x臓蓋g碩4f?i
Num:-2 66 0 0 66 2 11 0 57 69 73 111 -128 -34 -1 -125 79 -85 -86 -99 20 96 45 25 -81 -39 -45 -80 120 -60 -96 -55 119 103 -76 84 52 102 -43 37 105
============================
03-18 15:36:30
接收IP:192.168.0.101
发送IP:60.28.233.40
接受Com:8000
发送Com:13228
方向:网络-->本机
协议:17
长度:38
Txt:? #?9E
Num:-2 35 0 0 35 2 -121 0 57 69
沙漠里的海豚 2009-03-18
  • 打赏
  • 举报
回复
struct tcpheader中的sport
struct udphdr中的spor
分别表示发送方的端口


struct ipheader中的ip_sr表示发送方的IP地址

你调用recv时接收的数据是应用层的数据,本机通过ServerSock向外发送的数据包是接收不到的
YouHikari 2009-03-18
  • 打赏
  • 举报
回复
up

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧