当前位置:网站首页>educoder -- ip分片重组
educoder -- ip分片重组
2022-04-22 01:14:00 【CTYring】
任务说明
将收到ip分片重组为完整的ip包。
struct IpPkt* CombinIp(struct IpPktList *ip_list)
注意:参数中给出的分片顺序可能是乱序的,与前一关任务中返回的链表会存在不同。
#include"network_protocol.h"
#include <malloc.h>
//ip分片重组
struct IpPkt* CombinIp(struct IpPktList *ip_list){
struct IpPkt *ip=NULL;
/********* Begin 1 **********/
//如果只有一个分片,直接复制ip
if(ip_list->next == NULL){
return ip_list->ip;
}
//找到最后分片,确定ip的长度,其标志为000,片偏移不为0
struct IpPktList *t = (struct IpPktList*)malloc(sizeof(struct IpPktList));
t = ip_list;
struct IpPkt *tempip;
short len = t->ip->ip_len;
while(t!=NULL){
tempip = t->ip;
short fragoff = ntohs(tempip->ip_fragoff);
if((fragoff & 0xe000) == 0 && (fragoff & 0x1fff) > 0){
// printf("%d\n", fragoff);
len = (fragoff << 3) + ntohs(tempip->ip_len) - 20;
break;
}
t = t->next;
}
// printf("%d\n", len);
//按片偏移进行重组,注意最后的ip长度,偏移标志字段,校验要重新计算
ip = (struct IpPkt*)malloc(20 + len);
*ip = *(t->ip);
ip->ip_len = htons(len + 20);
ip->ip_cksum = 0;
ip->ip_fragoff = 0;
ip->ip_cksum = htons(ipcksum(ip));
t = ip_list;
while(t != NULL){
tempip = t->ip;
short fragoff = ntohs(tempip->ip_fragoff);
short offset = fragoff << 3;
len = ntohs(tempip->ip_len) - 20;
for(int i = 0; i < len; i++){
ip->ip_data[offset + 1] = tempip->ip_data[i];
}
t = t->next;
}
/********* End 1 **********/
return ip;
}
版权声明
本文为[CTYring]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_51029409/article/details/124249665
边栏推荐
- Evolution of investment system
- 【Pranet】论文及代码解读(Res2Net部分)——peiheng jia
- Essai de pénétration de la cible Investigator
- 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,
- 春招高频面试题:怎样设计秒杀系统?
- Faster R-CNN代码详解 标注数据形状
- Boutique: thousand word long text teaches you to use byte beating volcanic engine imagex
- 如何善待自己和家人
- Vnpy chapter of quantitative trading - synchronization module avoids self transaction risk and adds synchronization completion prompt
- R language ggplot2 visualizes scatter plot, highlights the specified data points based on combination rules, sets the size and color of data points
猜你喜欢
![[PRANET] paper and code interpretation -- cfsong](/img/a3/440319214f5373adfa2213e45b9da1.png)
[PRANET] paper and code interpretation -- cfsong

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

The Sandbox 与 Design Egg 达成合作,将共同建立虚拟空间 Como 小小世界

It's enough to study butterfly theme beautification

CLion中“This file does not belong to any project, code insight features might not work properly”的报错

sql server 2008使用over(PARTITION BY..ORDER BY.. ) 显示有语法错误

【Pranet】论文及代码解读(Res2Net部分)——peiheng jia
天边的彩虹很美丽

Embedded GUI inventory - how many do you know?
![[PRANET] interpretation of main architecture ------- wmilk](/img/48/5459fc54809db4c8b71d16f1fae7f9.png)
[PRANET] interpretation of main architecture ------- wmilk
随机推荐
Compiled vs interpreted, dynamic vs static
【PraNet】论文代码解读(损失函数部分)——Blank
R language uses lmperm package to apply to the replacement method of linear model (replacement test, permutation tests), one-way covariance analysis (one-way ANCOVA) on the same data set, and one-way
[PRANET] paper code interpretation (loss function) - Blank
BSides-Vancouver-2018-Workshop靶机渗透测试
Mr robot靶机渗透测试
(9) The edit of jvcl is combined with opening file, opening directory, selecting time, button, calculator and IP address
Simple understanding of variable structure assignment
MySQL creates and authorizes remote login users
Tencent T3 team sorted out and was forced to start gnawing at the underlying technology
R language MANOVA function robust one-way MANOVA, Wilks in rrcov package Test function robust one-way MANOVA, Adonis function of vegan package, nonparametric MANOVA equivalent
Detailed explanation of network model LSTM model content
js查找数组下标
Redis个人笔记:Redis应用场景,Redis常见命令,Reids缓存击穿穿透,Redis分布式锁实现方案,秒杀设计思路,Redis消息队列,Reids持久化,Redis主从哨兵分片集群
The WPF control created through WinForm control cannot be input
flask-基础代码
通过WinForm控件创建的WPF控件无法输入的问题
2022年年金险有哪些好的产品呢?
Faster R-CNN代码详解 标注数据形状
PR如何调整导出的数据速率和总比特率