此帖出自Linux与安卓论坛
最新回复
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
struct sockaddr_in addr;
char buf[516] = "";
int addrlen = sizeof(addr);
int sockfd;
int buflen;
int fd;
char command;
char serial = 0;
if(argc < 3)
{
printf("input error!\n");
exit(0);
}
addr.sin_family = AF_INET;
addr.sin_port = htons(69);
addr.sin_addr.s_addr = inet_addr(argv[1]);
sockfd = socket(AF_INET,SOCK_DGRAM,0);
buflen = sprintf(buf,"%c%c%s%c%s%c",0,1,argv[2],0,"octet",0);
sendto(sockfd,buf,buflen,0,(struct sockaddr *)&addr,sizeof(addr));
fd = open(argv[2],O_WRONLY|O_CREAT,0666);
if(fd == -1)
{
perror("open");
exit(1);
}
do{
buflen = recvfrom(sockfd,buf,516,0,(struct sockaddr *)&addr,&addrlen);
if(buflen == -1)
{
perror("recvfrom");
}
command = buf[1];
if(command == 3)
{
if(serial < buf[3])
{
serial = buf[3];
write(fd,buf+4,buflen-4);
}
buf[1] = 4;
sendto(sockfd,buf,4,0,(struct sockaddr *)&addr,sizeof(addr));
}
else if(command == 5)
{
close(fd);
close(sockfd);
unlink(argv[2]);
printf("recv error serial!\n");
}
}while(buflen == 516);
close(fd);
close(sockfd);
return 0;
}
[ 本帖最后由 于思 于 2011-9-14 17:14 编辑 ]
详情
回复
发表于 2011-9-14 17:13
| ||
|
||
| |
|
|
TFTP客户端
此帖出自Linux与安卓论坛
| ||
|
||
EEWorld Datasheet 技术支持