⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ip.c

📁 增加了tftp功能的vivi代码
💻 C
字号:

#include <string.h>
#include "net.h"
u16 ipID=0;
u8 board_IP_address[4]={192,168,1,190};
u8 host_IP_address[4]={192,168,1,10};

struct IP_packet{
u8 IP_version;
u8 type_of_service;
u16 total_length;
u16 ID;
u16 fragment_offset;
u8 time_to_live;
u8 protocol;
u16 checksum;
u8 souce_IP[4];
u8 destination_IP[4];
u8 IP_data[600];
};


s32 unpack_IP(u8 * packet,s32 packet_length)
{
 struct IP_packet * p;
 p=(struct IP_packet *)packet;
 if(packet[9]!=0x11)return -2;
 if(check(packet,20))return -2;
 else return shift16(p->total_length);
}


s32 pack_IP(u8 * packet,s32 packet_length)
{ u8 data[600];
  struct IP_packet *ippack;
  int i;
  ipID++;
  ippack=(struct IP_packet *)data;
  ippack->IP_version=0x45;
  ippack->type_of_service=0x0;
  ippack->total_length=shift16(20+(u16)packet_length);
  ippack->ID=shift16(ipID);
  ippack->fragment_offset=0;
  ippack->time_to_live=0x80;
  ippack->protocol=0x11;
  ippack->checksum=0;
  for(i=0;i<4;i++)
     ippack->souce_IP[i]=board_IP_address[i];
  for(i=0;i<4;i++)
     ippack->destination_IP[i]=host_IP_address[i];
  for(i=0;i<packet_length;i++)
	   ippack->IP_data[i]=*(packet+i);
  ippack->checksum=shift16(check(data,20));
  for(i=0;i<packet_length+20;i++)
	  transmit_packet[i]=data[i];
   return packet_length+20;
  
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -