栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

计网:IP分组转发协议实验(c语言)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

计网:IP分组转发协议实验(c语言)

#include
#include
#include
#include
typedef struct ip{
	unsigned char one;
	unsigned char two;
	unsigned char three;
	unsigned char four;
}IP;
typedef struct message{
	IP sourceIP;
	IP targetIP;
	unsigned int data;
}MG;
typedef struct routertable{
	IP ip;
	unsigned char port;
	IP mask;
}RTAB;
typedef struct router{
	unsigned char id;
	IP ip1;
	IP ip2;
	RTAB rtab[100];
	unsigned char len;
}ROT;
void init(ROT *R,int len);
int main(){
	MG msg;
	ROT R[2];
	unsigned char t=10;
	init(R,2);
	msg.sourceIP.one=23;
	msg.sourceIP.two=24;
	msg.sourceIP.three=25;
	msg.sourceIP.four=26;
	while(t--){
		Sleep(1000);
		srand((unsigned)time(NULL));
		switch(rand()%3){
			case 0:{
				msg.data=t;
				msg.targetIP.one=58;
				msg.targetIP.two=rand()%256;
				msg.targetIP.three=rand()%256;
				msg.targetIP.four=rand()%256;
				break;
			}
			case 1:{
				msg.data=t;
				msg.targetIP.one=192;
				msg.targetIP.two=32;
				msg.targetIP.three=63;
				msg.targetIP.four=rand()%256;
				break;
			}
			case 2:{
				msg.data=t;
				msg.targetIP.one=128;
				msg.targetIP.two=54;
				msg.targetIP.three=rand()%256;
				msg.targetIP.four=rand()%256;
				break;
			}
			default :{
				msg.data=t;
				msg.targetIP.one=rand()%254+1;
				msg.targetIP.two=rand()%254+1;
				msg.targetIP.three=rand()%254+1;
				msg.targetIP.four=rand()%254+1;
				break;
			};
		}
		printf("%d号消息开始发送:n",10-t);
		printf("源IP地址:%d.%d.%d.%dn",msg.sourceIP.one,msg.sourceIP.two,msg.sourceIP.three,msg.sourceIP.four);
		printf("目的IP地址:%d.%d.%d.%dn",msg.targetIP.one,msg.targetIP.two,msg.targetIP.three,msg.targetIP.four);
		
		int i,sig=0;
		printf("到达路由器%cn",R[0].id);
		for(i=0;i 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/869908.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号