当前位置:网站首页>educoder -- IP协议解析
educoder -- IP协议解析
2022-04-22 01:14:00 【CTYring】
任务描述
本次实验的目标主要分为两部分
1.实现对IP数据包的内容进行解析,获取IP地址、数据包长度等信息
2.实现对IP数据包内容的校验,确认收到的数据是正确可靠的
任务目标
获取IP包中的源地址
获取IP包中的目的地址
获取IP包总长度
计算IP包的数据长度
计算校验和
注意事项!!!
第五个任务要实现的是返回计算IP数据包后的校验和,而非IP包本身的校验和,即:
模拟设备收到IP包后对数据进行校验
#include"network_protocol.h"
/*从以太网帧中获取ip包的源地址,以网络字节顺序返回 */
uint32 get_src_ip(byte *eth){
/********* Begin 1 ***************/
// uint32 num = (eth[12] << 0) + (eth[13] << 8) + (eth[14] << 16) + (eth[15] << 24);
uint32 num = eth[26] + (eth[27] << 8) + (eth[28] << 16) + (eth[29] << 24);
return num;
// return eth[12];
/********** End 1 *****************/
}
/*从以太网帧中获取ip包的目的地址,以网络字节顺序返回 */
uint32 get_dst_ip(byte *eth){
/********* Begin 2 ***************/
uint32 num = eth[30] + (eth[31] << 8) + (eth[32] << 16) + (eth[33] << 24);
return num;
/********** End 2 *****************/
}
/*从以太网帧中获取ip包的总长度,以本地节顺序返回 */
short get_ip_total_len(byte *eth){
/********* Begin 3 ***************/
return eth[17];
/********** End3*****************/
}
/*从以太网帧中获取ip包的数据长度,以本地节顺序返回 */
short get_ip_data_len(byte *eth){
/********* Begin 4 ***************/
return eth[17] - 20;
/********** End 4 *****************/
}
/*计算以太网帧中的ip包首部检验,以本地节顺序返回 */
uint16 ipcksum( struct IpPkt* ip){
uint16 *hptr; /* Ptr to 16-bit header values */
int32 i; /* Counts 16-bit values in hdr */
uint16 word; /* One 16-bit word */
uint32 cksum; /* Computed value of checksum */
hptr= (uint16 *) ip;
/* Sum 16-bit words in the packet */
cksum = 0;
for (i=0; i<10; i++) {
word = *(hptr+i);
cksum += (uint32) ntohs(word);
}
/* Add in carry, and take the ones-complement */
cksum = (cksum >> 16) + (cksum&0xffff);
cksum += (cksum >> 16);
return (uint16) (0xffff & ~cksum);
}
版权声明
本文为[CTYring]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_51029409/article/details/124242338
边栏推荐
- PMSM或IM12扇区模型预测转矩控制
- Pytoch installation and troubleshooting of groupspatialsoftmax errors
- cybox靶机渗透测试
- It's enough to study butterfly theme beautification
- Solve the problem that the idea web project does not have small blue dots
- 网络协议分析总结
- 代码源每日一题 div1 (201-207)
- Thales
- [PRANET] paper code interpretation (loss function) - Blank
- Wonderful review | deepnova x iceberg meetup online "building a real-time data Lake based on iceberg"
猜你喜欢

Zabbix深度监控:多款开源工具构建企业监控新架构

计算机网络安全技术学习总结

Matlab: simulate the control system and use ode45 to solve the LC circuit

PR如何调整导出的数据速率和总比特率

算法面试经典100题,冲刺7天拿下Offer

安装包签名检测

【PraNet】论文代码解读(损失函数部分)——Blank

How does PR adjust the exported data rate and total bit rate

Can avi recorded by OBS be opened by ImageJ?

【Pranet】论文及代码解读——cfsong
随机推荐
如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题
Thales
The WPF control created through WinForm control cannot be input
2022年Redis最新面试题第1篇 - Redis基础知识
为什么PR导出来的视频,偏紫色?
Solve the problem that the idea web project does not have small blue dots
Embedded GUI inventory - how many do you know?
Pytoch installation and troubleshooting of groupspatialsoftmax errors
Redis personal notes: redis application scenario, redis common commands, redis cache breakdown and penetration, redis distributed lock implementation scheme, spike design idea, redis message queue, Re
Simple understanding of variable structure assignment
Tencent team strength to create an introduction course to fluent, 1-3 years of Android Development Engineer Interview Experience Sharing
Thales
【服务器数据恢复】服务器进水后的数据恢复成功案例
代码源每日一题 div1 (501-507)
Detailed explanation of network model LSTM model content
Installation package signature detection
(9) The edit of jvcl is combined with opening file, opening directory, selecting time, button, calculator and IP address
CH4INRULZ靶机渗透测试
贼厉害,最新Android面试合集
The AOV function of R language is used for one-way ANOVA, the normality of the dependent variable of ANOVA is evaluated by Q-Q diagram, the equality (homogeneity) of Bartlett's verification variance,