//-------编写客户端, 使用TFTP协议,完成文件上传及下载的功能----------
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
enum OPCODE{
RRQ = 1,
WRQ,
DATA,
ACK,
ERROR
};
int main(int argc, char const *argv[])
{
//检测命令行4个参数
if (4 != argc){
printf("<format>:%s [ipaddr] [mode] [filename]\n",argv[0]);
printf(" mode:\"get\" means get file by server.\n"); /* get 下载文件 */
printf(" \"put\" means put file to server.\n"); /* put 上传文件 */
return -1;
}
if( !(!strcmp(argv[2],"get") || !strcmp(argv[2],"put"))){
printf("[Error] **Invalid argument.\n");
printf("<format>:%s [ipaddr] [mode] [filename]
Linux UDP下C语言实现TFTP协议客户端,文件上传及下载的功能
最新推荐文章于 2023-02-23 23:30:07 发布