main.c

来自「这是TFTP 协议的最新源代码 很辛苦的」· C语言 代码 · 共 86 行

C
86
字号
/*	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 "baselib.h"#include "timer.h"#if TFTPNAIVE_TIMEREQUESTstatic void getTime (){	int ts, h, m, s;		/* send a timestamp request to the TFTP server,	 * to get it's GMT time of the day */	if (tftp_req) {		if ((ts = netTimestampRequest (tftp_req->server)) != 0) {			ts = (ts + 500) / 1000;	/* round to secs */			h = (ts / 3600) % 24;			m = (ts / 60) % 60;			s = ts % 60;			setTime (h, m, s);			printf ("GMT time is %d:%d:%d\n", h, m, s);		}	}}#endifint main (void){	int error;	timerInit ();	/* initialize the network chip, loop until it's ready */	while ((error = netUp ()) != 0) {		if (error != ERR_LINK)			printf ("Network interface init failed: code %d\n", error);		else			printf ("No network, cable problem ?\n");		usleep (1000000);	}	while (1) {		/* request an IP address through BOOTP */		netRequestIP ();#if TFTPNAIVE_TIMEREQUEST		getTime ();#endif		/* bootstrap using TFTP */		if (netBoot () == 0)			break;	}	/* shutdown the network chip */	netDown ();	/* if the download is successfull and	 * a start address has been given, jump to it	 */	if (tftp_req && tftp_req->sts > 0 && tftp_req->strtf) {		jump ((void *) tftp_req->strt);		/* not reached */	}	return 0;}

⌨️ 快捷键说明

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