#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



