tftp linux 源码,tftp 客户端源码实现

#include#include#include#include#include#include#include#include#include#include#include#include//add zyf#define tftp_debug 1#define ERROR -1#define TIMEOUT 2000 /*amount of time to wait for an ACK/D...
摘要由CSDN通过智能技术生成

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

//add zyf

#define  tftp_debug 1

#define ERROR -1

#define TIMEOUT 2000 /*amount of time to wait for an ACK/Data Packet in 1000microseconds 1000 = 1 second*/

#define MAXDATASIZE 1024 /* Maximum data size allowed */

int datasize = 512;

unsigned short int ackfreq = 1;

#define RETRIES 3 /* Number of times to resend a data OR ack packet beforing giving up */

#define DEFAULT_TFTP_HOST "192.168.1.140"

//end

/*

*This function is called when the client would like to download a file from the server.

*/

void

tget (char *pFilename, struct sockaddr_in server, char *pMode, int sock)

{

/* local variables */

int len, server_len, opcode, i, j, n, tid = 0, flag = 1;

unsigned short int count = 0, rcount = 0;

unsigned char filebuf[MAXDATASIZE + 1];

unsigned char packetbuf[MAXDATASIZE + 12];

extern int errno;

char filename[128], mode[12], *bufindex, ackbuf[512];

struct sockaddr_in data;

FILE *fp;/* pointer to the file we will be getting */

strcpy (filename, pFilename);//copy the pointer to the filename into a real array

strcpy (mode, pMode);//same as above

if (tftp_debug)

printf ("branched to file receive function\n");

fp = fopen (filename, "w");/* open the file for writing */

if (fp == NULL)

{//if the pointer is null then the file can't be opened - Bad perms

if (tftp_debug)

printf ("Client requested bad file: cannot open for writing (%s)\n",

filename);

return;

}

else/* File is open and ready to be written to */

{

if (tftp_debug)

printf ("Getting file... (destination: %s) \n", filename);

}

/* zero the buffer before we begin */

memset (filebuf, 0, sizeof (filebuf));

n = datasize + 4;

do

{

/* zero buffers so if there are any errors only NULLs will be exposed */

memset (packetbuf, 0, sizeof (packetbuf));

memset (ackbuf, 0, sizeof (ackbuf));

printf ("enter %d \n",count);

if (n !&#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值