📄 tftpmain.c
字号:
#include "config.h"
#include "skbuff.h"
#include "eth.h"
#include "arp.h"
#include "ip.h"
#include "udp.h"
#include "utils.h"
#include "board.h"
#ifdef TFTP_DOWNLOAD_SUPPORT
char TftpLoadEnd;
char TftpPutBegin;
char TftpPutMark;
int net_handle(void)
{
struct sk_buff *skb;
struct ethhdr *eth_hdr;
skb = alloc_skb(ETH_FRAME_LEN);
if (eth_rcv(skb) != -1) {
eth_hdr = (struct ethhdr *)(skb->data);
skb_pull(skb, ETH_HLEN);
if (ntohs(eth_hdr->h_proto) == ETH_P_ARP)
arp_rcv_packet(skb);
else if(ntohs(eth_hdr->h_proto) == ETH_P_IP)
ip_rcv_packet(skb);
}
free_skb(skb);
return 0;
}
#define LOCAL_IP_ADDR ((192UL<<24)|(168<<16)|(0<<8)|100)
extern unsigned long download_len;
extern unsigned long download_addr;
int NetLoadFile(U32 addr, U32 give_ip, U32 a3, U32 a4)
{
unsigned char eth_addr[ETH_ALEN];
unsigned char *s;
give_ip = LOCAL_IP_ADDR;
s = (unsigned char *)&give_ip;
printf("Mini TFTP Server 1.0 (IP : %d.%d.%d.%d PORT: %d)\n", s[3], s[2], s[1], s[0], TFTP);
printf("Type tftp -i %d.%d.%d.%d put filename at the host PC\n", s[3], s[2], s[1], s[0]);
puts("Press ESC key to exit\n");
eth_init();
if(eth_lnk_stat())
return 0;
eth_get_addr(eth_addr);
ip_init(give_ip);
udp_init();
arp_add_entry(eth_addr, give_ip);
TftpLoadEnd = 0;
TftpPutMark = 0;
TftpPutBegin = 0;
download_addr = 0x30008000;
download_len = 0;
while ((getkey()!=ESC_KEY)&&!TftpLoadEnd) {
net_handle();
if(TftpPutBegin) {
puts("Starting the TFTP download...\n");
TftpPutBegin = 0;
}
if(TftpPutMark) {
putch('.');
TftpPutMark = 0;
}
}
if(TftpLoadEnd) {
printf("\ndownload 0x%x bytes to 0x%08x\n\n", download_len, download_addr);
return download_len;
}
return 0;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -