bootp.c

来自「2410 boot loader,usb ftp」· C语言 代码 · 共 92 行

C
92
字号
/*	Copyright 2001-2004 Georges Menie (www.menie.org)	This file is part of Tftpnaive.    Tftpnaive is free software; you can redistribute it and/or modify    it under the terms of the GNU Lesser General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    Tftpnaive is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public License    along with Tftpnaive; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include "tftpnaive.h"#include "net.h"#include "baselib.h"static BootData bdata;BootData *tftp_req;void processBOOTP (BOOTPpkt * bp){		// Translate network data to host data    bp->op_type = ntoh(bp->op_type);    bp->adr_hop = ntoh(bp->adr_hop);    bp->id = ntoh4(bp->id);    bp->sec = ntoh4(bp->sec);    bp->your_ip = ntoh4(bp->your_ip);    bp->srv_ip = ntoh4(bp->srv_ip);    			if (bp->op_type == BOOTP_ETH_REPLY && bp->id == BOOT_RQ_ID		&& tftp_req == 0 && !memcmp (netif.IEEEIA, bp->hw_addr, 6)) {		int l;		Uart_Printf ("BOOTP: ");		Uart_Printf ("IP %d.%d.%d.%d, ",				(bp->your_ip >> 24) & 0xff,				(bp->your_ip >> 16) & 0xff,				(bp->your_ip >> 8) & 0xff,				bp->your_ip & 0xff);		Uart_Printf ("server %d.%d.%d.%d, ",				(bp->srv_ip >> 24) & 0xff,				(bp->srv_ip >> 16) & 0xff,				(bp->srv_ip >> 8) & 0xff,				bp->srv_ip & 0xff);		Uart_Printf ("boot file '%s'\n", bp->boot_filename);		netif.ip = bp->your_ip;		l = strlen ((char *)bp->boot_filename);		if (l > 0 && l < 128) {			memset (&bdata, 0, sizeof bdata);			tftp_req = &bdata;			tftp_req->server = bp->srv_ip;			strcpy (tftp_req->file, (char *)bp->boot_filename);		}	}}int sendBOOTPRequest (void){	BOOTPpkt bootp_pkt;	tftp_req = 0;	memset (&bootp_pkt, 0, sizeof(bootp_pkt));	bootp_pkt.op_type = hton(BOOTP_ETH_REQUEST);	bootp_pkt.adr_hop = hton(0x600);	bootp_pkt.id = hton4(BOOT_RQ_ID);	bootp_pkt.sec = hton4(BOOT_RQ_SEC);	memcpy (&bootp_pkt.hw_addr, netif.IEEEIA, 6);	return sendUDP ((UDPpkt *) & bootp_pkt,					sizeof(bootp_pkt) - sizeof (UDPpkt), -1, BOOTP_CLI_PORT,					BOOTP_SRV_PORT);}void directBOOTP(unsigned int myip, unsigned int srvip, char *file){	netif.ip = myip;	memset (&bdata, 0, sizeof bdata);	tftp_req = &bdata;	tftp_req->server = srvip;	strcpy (tftp_req->file, file);	}

⌨️ 快捷键说明

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