?? tftpmain.c
字號:
#include "..\config.h"
#include "skbuff.h"
#include "eth.h"
#include "arp.h"
#include "ip.h"
#include "udp.h"
#include "utils.h"
#include "console.h"
#ifdef TFTP_SUPPORT
int DownLoadEnd;
extern unsigned long downloadAddress, downloadFileSize;
extern void start_kernel(unsigned long addr, unsigned initrd);
extern unsigned long this_machine_ip; //defined in start.s
//unsigned long this_machine_ip = (192<<24)|(168<<16)|(16<<8)|(100);
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);
{
// int i;
// char *p = (char *)eth_hdr;
// for(i=0; i<32; i++)
// printf("%x,", p[i]);
// printf("\n----%x", eth_hdr->h_proto);
}
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;
}
#include "params.h"
void tftp_main(unsigned long addr, int dummy)
{
unsigned char eth_addr[ETH_ALEN];
unsigned char *s = (unsigned char *)&this_machine_ip;
printf("Mini TFTP Server 1.0 (IP : %d.%d.%d.%d PORT: %d)\n", s[3], s[2], s[1], s[0], TFTP);
puts("Please select download which?\n1 : kernel\n2 : initrd\n");
while(1) {
char c = getch();
if(c=='1') {
downloadAddress = LINUX_ZIMAGE_ADDR;
break;
} else if(c=='2') {
downloadAddress = INITRD_START;
break;
}
}
downloadFileSize = 0;
DownLoadEnd = 0;
puts("Load image file from host\n");
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");
if(eth_init()) {
puts("eth_init fail, exit!\n");
return;
}
eth_get_addr(eth_addr);
arp_init();
ip_init(this_machine_ip);
udp_init();
arp_add_entry(eth_addr, this_machine_ip);
while (1) {
net_handle();
if (kbhit()&&(getch()==0x1b)) {
puts("\nESC Aborted!\n");
return;
}
if(DownLoadEnd) {
printf("\nTFTP download completed, 0x%08x Bytes received.\n", downloadFileSize);
if(downloadAddress!=LINUX_ZIMAGE_ADDR)
return;
puts("Do you want to run it ?\n1: boot without initrd\n2: boot wiht initrd\nEsc: exit\n");
while(1) {
char c = getch();
if(c==0x1b)
break;
if((c=='1')||(c=='2'))
start_kernel(downloadAddress, (c=='1')?0:INITRD_START);
}
return;
}
}
}
#else
void tftp_main(unsigned long addr, int dummy) {}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -