中等模拟 | 北邮OJ | 98. IP数据包解析
https://vpn.bupt.edu.cn/http/10.105.242.80/problem/p/98/
IP头部
TCP头部
数据解析
45 00 00 34 //0034表示总长度, 即52B, 5表示首部长度, 5*4B
7a 67 40 00
40 06 63 5a
0a cd 0a f4 //源地址 10.205.10.244
7d 38 ca 09 //目的地址 125.56.202.9cd f6 00 50 //源端口, 目的端口
b4 d7 ae 1c
9b cf f2 40
80 10 ff 3d
fd d0 00 00Case #1
Total length = 52 bytes
Source = 10.205.10.244
Destination = 125.56.202.9
Source Port = 52726
Destination Port = 80
AC代码
有点意思, 码量较大
需要训练做模拟题的速度
#include <bits/stdc++.h>
#define FF(a,b) for(int a=0;a<b;a++)
#define F(a,b) for(int a=1;a<=b;a++)
#define LEN 100
#define INF 1000000
#define bug(x) cout<<#x<<"="<<x<<endl;using namespace std;
typedef long long ll;char buf[1000];
char str[100][10];int hex2int(char ch){if(ch>='a'){return ch-'a'+10;}else{return ch-'0';}
}int hex2int(char *ch){int n=strlen(ch);int ans=0;int base=1;for(int i=n-1,j=0;i>=0;i--,j++) //脑子秀逗了, 其实写个单循环就好了{ans+=hex2int(ch[i])*base;base*=16;}return ans;
}int main()
{// freopen("./in","r",stdin);int N;scanf("%d",&N);FF(i,N){//gets(buf); 可以用gets读入带空格的一行int n=0;while(1){scanf("%s",str[n++]);char pd=getchar();if(pd=='\n' || pd==EOF)break;}int IPlen=hex2int(str[0][1]);strcat(str[2],str[3]);int TOTlen=hex2int(str[2]);printf("Case #%d\n",i+1);printf("Total length = %d bytes\n",TOTlen);printf("Source = %d.%d.%d.%d\n",hex2int(str[12]),hex2int(str[13]),hex2int(str[14]),hex2int(str[15]));printf("Destination = %d.%d.%d.%d\n",hex2int(str[16]),hex2int(str[17]),hex2int(str[18]),hex2int(str[19]));strcat(str[IPlen*4],str[IPlen*4+1]);strcat(str[IPlen*4+2],str[IPlen*4+3]);printf("Source Port = %d\n",hex2int(str[IPlen*4]));printf("Destination Port = %d\n",hex2int(str[IPlen*4+2]));puts("");}return 0;
}
//Case #1
//Total length = 52 bytes
//Source = 10.205.10.244
//Destination = 125.56.202.9
//Source Port = 52726
//Destination Port = 80
中等模拟 | 北邮OJ | 98. IP数据包解析相关推荐
- 计算机网络ip数据包分析题,计算机网络课程设计-IP数据包解析实验报告
计算机网络课程设计-IP数据包解析实验报告 解析 IP数据报实验报告目录目录 21.课程设计目的 .22.课程设计要求 .23.相关知识 .24.课程设计分析 .64.1 网卡设置64.2 使用套接字 ...
- 九度题库 1475:IP数据包解析(北京邮电大学2012机试)
http://ac.jobdu.com/problem.php?pid=1475 题目描述: 我们都学习过计算机网络,知道网络层IP协议数据包的头部格式如下: 其中IHL表示IP头的长度,单位是4字节 ...
- 字符串处理 | 北邮OJ | 101. IP地址
https://vpn.bupt.edu.cn/http/10.105.242.80/problem/p/101/ 方法一. split 我编写了一个专用的split函数.但是要特判123.123.1 ...
- 简单模拟 | 北邮OJ | 87. 日期
https://vpn.bupt.edu.cn/http/10.105.242.80/problem/p/87/ 逗号打成句号wa了半天, 可以说是相当惊人了 /* USER_ID: test#shi ...
- 简单模拟 | 北邮OJ | 90. 字符串转换
https://vpn.bupt.edu.cn/http/10.105.242.80/problem/p/90/ 自己写得low代码 #include <bits/stdc++.h> #d ...
- ibm aix 抓包命令_在IBM AIX上模拟丢弃的TCP / IP数据包
本文介绍: AIX内核扩展,允许来往于指定主机的指定百分比的TCP / IP数据包被随机丢弃,以模拟不利的网络状况. 加载,激活和卸载内核扩展的实用程序. C和Java™实用程序,用于监视到达目标主机 ...
- 北邮oj题库刷题计划(更新ing)
北邮oj题库刷题计划(更新ing) 83. A + B Problem 84 Single Number 85. Three Points On A Line 120 日期 121 最值问题 122 ...
- 北邮OJ 141 虚数
北邮OJ 虚数 #include <bits/stdc++.h> using namespace std; typedef struct fushu{int x; //实部 int y; ...
- 校外如何登陆北邮oj
由于北邮oj不对外开放,准备复试的我需要进入北邮oj:其他小朋友也有这个想法.故写此博客. 先找北邮土著借北邮账号,包括一些认识的同学,直系学长学姐,他们都很乐意帮助的~ 下面是校外进北邮校内网的方法 ...
最新文章
- Mac解决中文matplotlib乱码问题
- Locality Sensitive Hashing(局部敏感哈希)
- 查看Linux中硬链的所有文件路径
- Sinew Ex深度发掘金融衍生品市场价值
- Android 双击返回键退出程序 实现
- 转载:C++ list 类学习笔记
- EnableAutoConfiguration自动配置底层原理
- @RequestMapping 和 @GetMapping @PostMapping 区别
- EntityFramework Core 2.0执行原始查询如何防止SQL注入?
- 分布式架构的王者?Kubernetes凭什么
- 王学丹 确定测试原始需求
- vs2015 hiredis编译使用
- 记录一个对外接口签名问题
- JS如何判断一个对象是否为JSON对象
- 高斯计传感器使用的霍尔传感器原理
- html情侣相册,浪漫的情侣相册名字
- osworkflow简单教程
- jupyter notebook 打开md文件
- Matlab中求程序运行时间三种方法
- C++中fread函数和fwrite函数的用法
热门文章
- 水质检测传感器在不同行业中的应用
- LINUX安装虚拟机时安装步骤和进入bios解决intel vt -x
- Android Git忽略文件未生效的解决方案
- 解决 ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (61) 超详细
- Spring Cloud介绍
- Golang,一道春天的闪电
- 免费的激光雷达数据的下载方法
- crashlands中文安卓下载_崩溃大陆安卓中文版
- Backrooms-level1
- 一个不小心就串场了 ~ mingw32-gcc和tdm-gcc的一处不同引起的依赖错误