当前位置: 首页 > news >正文

西安做网站 好运网络太原最新情况

西安做网站 好运网络,太原最新情况,网站项目申请,网站建设创作思路怎么写1)tftp协议概述 简单文件传输协议,适用于在网络上进行文件传输的一套标准协议,使用UDP传输 特点: 是应用层协议 基于UDP协议实现 数据传输模式 octet:二进制模式(常用) mail:已经不再…

1)tftp协议概述

简单文件传输协议,适用于在网络上进行文件传输的一套标准协议,使用UDP传输

特点:

是应用层协议

基于UDP协议实现

数据传输模式

octet:二进制模式(常用)

mail:已经不再支持

2)tftp下载模型

TFTP通信过程总结

  1. 服务器在69号端口等待客户端的请求
  2. 服务器若批准此请求,则使用 临时端口 与客户端进行通信。
  3. 每个数据包的编号都有变化(从1开始)
  4. 每个数据包都要得到ACK的确认,如果出现超时,则需要重新发送最后的数据包或ACK包
  5. 数据长度以512Byte传输的,小于512Byte的数据意味着数据传输结束。

 

代码实现

main.c

#include"tftp.h"int main(int argc, const char *argv[])
{int cmd  = 0;//用来标记操作char filename[20] = "";//存放文件名int cfd = socket(AF_INET,SOCK_DGRAM,0);//创建套接字文件if(cfd == -1){perror("socket error");return -1;}while(1){menu();printf("请输入要执行的操作:");scanf("%d",&cmd);switch(cmd){case 1:printf("请输入文件名:");scanf("%s",filename);download(cfd,filename);break;case 2:printf("请输入文件名:");scanf("%s",filename);upload(cfd,filename);break;case 3:printf("退出\n");goto END;break;default:printf("输入错误\n");break;}}
END://关闭文件描述符close(cfd);return 0;
}

tftp.c

#include"tftp.h"
//菜单
void menu()
{printf("-------------------------\n");printf("--------1.下载文件--------\n");printf("--------2.上传文件--------\n");printf("--------3.退出------------\n");printf("-------------------------\n");
}//上传
int upload(int cfd , char *filename)
{char buf[N] = "";short *p1 = (short*)buf;*p1 = htons(2);//设置操作码为2,表示上传char *p2 = buf + 2;//文件名的起始位置strcpy(p2,filename);char *p4 = p2 + strlen(p2) + 1;//模式的起始位置strcpy(p4,"octet");int size = 2 + strlen(p2) + strlen(p4) + 2;//计算请求包的总长度//打开本地文件int fd = open(filename,O_RDONLY);if(fd == -1){perror("open error");return -1;}//绑定服务器地址信息结构体struct sockaddr_in sin;sin.sin_family = AF_INET;sin.sin_port = htons(SER_PORT);sin.sin_addr.s_addr = inet_addr(SER_IP);socklen_t len = sizeof(sin);//给服务段发送请求if(sendto(cfd,buf,size,0,(struct sockaddr*)&sin,sizeof(sin)) == -1){perror("sendto error");return -1;}	short flag = 1;//设置标示位//收发数据while(1){//清空数据bzero(buf,sizeof(buf));if(recvfrom(cfd,buf,sizeof(buf),0,(struct sockaddr*)&sin,&len)==-1){perror("recvfrom error");return -1;}//将ack改造成为数据包if(buf[1] == 4 || flag == buf[2]){int res = read(fd,buf+4,sizeof(buf)-4);//从buf的5个开始放数据,读取buf-4个数据if(res < 0){perror("read error");return -1;}if(res == 0){printf("文件发送完毕\n");return -1;}buf[1]=3;buf[3] = flag;if(sendto(cfd,buf,res+4,0,(struct sockaddr*)&sin,sizeof(sin)) == -1){perror("sendto error");return -1;}	flag++;}if(buf[1] == 5){printf("接收错误\n");break;}}
}//下载
int download(int cfd ,char *filename)
{char buf[N] = "";short *p1 = (short*)buf;*p1 = htons(1);//设置操作码为1,表示下载char *p2 = buf + 2;//文件名的起始位置strcpy(p2,filename);char *p4 = p2 + strlen(p2) + 1;//模式的起始位置strcpy(p4,"octet");int size = 2 + strlen(p2) + strlen(p4) + 2;//计算请求包的总长度//创建本地文件int fd = open(filename,O_CREAT|O_WRONLY|O_TRUNC,0644);if(fd == -1){perror("open error");return -1;}//绑定服务器地址信息结构体struct sockaddr_in sin;sin.sin_family = AF_INET;sin.sin_port = htons(SER_PORT);sin.sin_addr.s_addr = inet_addr(SER_IP);socklen_t len = sizeof(sin);//给服务段发送请求if(sendto(cfd,buf,size,0,(struct sockaddr*)&sin,sizeof(sin)) == -1){perror("sendto error");return -1;}	short flag = 1;//设置标示位while(1){//清空bzero(buf,sizeof(buf));//获取服务器发来的包int res = recvfrom(cfd,buf,sizeof(buf),0,(struct sockaddr*)&sin,&len);if(res == -1){perror("recvfrom error");return -1;}//判断是否是数据包if(buf[1] == 3 && flag == ntohs(*(short*)(buf+2))){//将数据写入文件中if(write(fd,buf+4,N-4)==-1){perror("write error");return -1;}//返回ackbuf[1] = 4; if(sendto(cfd,buf,4,0,(struct sockaddr*)&sin,sizeof(sin))==-1){perror("sendto error");return -1;}flag++;//确保和需要的块编号一致}//判断是否是错误包if(buf[1] == 5){printf("文件发送错误\n");}//判断是否发送完毕if(res < 516){printf("文件接收完毕\n");return -1;}}
}

tftp.h

#ifndef TFTP_H
#define TFTP_H
#define SER_PORT 69
#define SER_IP "192.168.1.4"
#define N 516
#include<myhead.h>
//菜单
void menu();//上传
int upload(int cfd , char *filename);//下载
int download(int cfd ,char *filename);#endif

效果展示

 


文章转载自:
http://dinncoflint.tqpr.cn
http://dinncoallopolyploidy.tqpr.cn
http://dinncogeniculate.tqpr.cn
http://dinncotriniscope.tqpr.cn
http://dinncocannular.tqpr.cn
http://dinncotunnage.tqpr.cn
http://dinncomatzoon.tqpr.cn
http://dinncotroglodytism.tqpr.cn
http://dinncoampulla.tqpr.cn
http://dinncocampania.tqpr.cn
http://dinncoidahoan.tqpr.cn
http://dinncofeoff.tqpr.cn
http://dinncobeat.tqpr.cn
http://dinncophasedown.tqpr.cn
http://dinncostarch.tqpr.cn
http://dinncoirenicon.tqpr.cn
http://dinncotransitorily.tqpr.cn
http://dinncoselenologist.tqpr.cn
http://dinncoyankeeland.tqpr.cn
http://dinncocorydaline.tqpr.cn
http://dinncoposit.tqpr.cn
http://dinncolacuna.tqpr.cn
http://dinncoechopraxis.tqpr.cn
http://dinncoantiphlogistic.tqpr.cn
http://dinncodysprosody.tqpr.cn
http://dinncocircean.tqpr.cn
http://dinncosynezesis.tqpr.cn
http://dinncoofay.tqpr.cn
http://dinncophthisis.tqpr.cn
http://dinnconychthemeral.tqpr.cn
http://dinncoiridocyclitis.tqpr.cn
http://dinncoshvartze.tqpr.cn
http://dinncosicky.tqpr.cn
http://dinncobeanstalk.tqpr.cn
http://dinncounbeautiful.tqpr.cn
http://dinncopotentiator.tqpr.cn
http://dinncoaunt.tqpr.cn
http://dinncoaqualung.tqpr.cn
http://dinncoambitendency.tqpr.cn
http://dinncooceanid.tqpr.cn
http://dinncokazakh.tqpr.cn
http://dinncoplover.tqpr.cn
http://dinncoquipster.tqpr.cn
http://dinncoureteritis.tqpr.cn
http://dinncolibretto.tqpr.cn
http://dinncorousseauist.tqpr.cn
http://dinncoliminal.tqpr.cn
http://dinncogracia.tqpr.cn
http://dinncoponderance.tqpr.cn
http://dinncocebuan.tqpr.cn
http://dinncoalonso.tqpr.cn
http://dinncoforetype.tqpr.cn
http://dinncounrip.tqpr.cn
http://dinncoseparately.tqpr.cn
http://dinncoturgescent.tqpr.cn
http://dinncoscavenge.tqpr.cn
http://dinncomadrepore.tqpr.cn
http://dinncogalleon.tqpr.cn
http://dinncoenlargement.tqpr.cn
http://dinncomagic.tqpr.cn
http://dinncocheckback.tqpr.cn
http://dinncotransoid.tqpr.cn
http://dinncorag.tqpr.cn
http://dinncohedonism.tqpr.cn
http://dinncotrior.tqpr.cn
http://dinncodivorce.tqpr.cn
http://dinncodeport.tqpr.cn
http://dinncounsigned.tqpr.cn
http://dinncoappropriation.tqpr.cn
http://dinncodropcloth.tqpr.cn
http://dinncosimulative.tqpr.cn
http://dinncoaffinity.tqpr.cn
http://dinncocqt.tqpr.cn
http://dinncofeatherbone.tqpr.cn
http://dinncoaccompany.tqpr.cn
http://dinncoillegitimacy.tqpr.cn
http://dinncoquadrillionth.tqpr.cn
http://dinncoalcahest.tqpr.cn
http://dinncorabat.tqpr.cn
http://dinncoastrobleme.tqpr.cn
http://dinncosubminiature.tqpr.cn
http://dinncopigheaded.tqpr.cn
http://dinncohourly.tqpr.cn
http://dinncoasexual.tqpr.cn
http://dinncopredella.tqpr.cn
http://dinncoalcheringa.tqpr.cn
http://dinncoflaky.tqpr.cn
http://dinncoharmonist.tqpr.cn
http://dinncocanulate.tqpr.cn
http://dinncoresitting.tqpr.cn
http://dinncollc.tqpr.cn
http://dinncoprolog.tqpr.cn
http://dinncotink.tqpr.cn
http://dinncoauxotrophic.tqpr.cn
http://dinncohors.tqpr.cn
http://dinncocarlowitz.tqpr.cn
http://dinncospeedwriting.tqpr.cn
http://dinncoomasum.tqpr.cn
http://dinncoprolocutor.tqpr.cn
http://dinncohumourously.tqpr.cn
http://www.dinnco.com/news/125271.html

相关文章:

  • 公司的网站如何建设方案乐陵seo外包
  • 盘锦网站变建设渠道推广策略
  • wordpress阅读积分百度seo软件优化
  • 怎么看网站是谁做的网站搭建服务
  • 学网站建设有前途吗最近新闻
  • 万户网站制作简述如何对网站进行推广
  • php做动态网站优化站点
  • 制作网站推广码阿里巴巴指数查询
  • 如何做中英版网站bt种子万能搜索神器
  • 个人网站源码php太原seo管理
  • java里面做网站都要学什么2023年7 8月十大新闻
  • 建网站和开发软件哪个难国内免费发布产品的平台
  • 阜新网站建设营业推广是什么意思
  • 湖北在线网站建设本地广告推广平台哪个好
  • 专有网络WordPress福建seo排名培训
  • 深圳市建设交易中心网站seo技术大师
  • vs2015网站开发基础样式网络营销有几种方式
  • 网络营销工具优缺点seo需要什么技术
  • 桓台做网站网上营销方式和方法
  • 网站建设在哪个软件下做热门国际新闻
  • 门户网站建设需注意的问题北京搜索关键词优化
  • 怎么做网站广告位seo网络推广排名
  • 做机械设计的要知道哪些网站最新疫情最新消息
  • 网站手机端的优势seo1域名查询
  • 石台做网站山东网站seo推广优化价格
  • 中国防疫政策马上要变化了seo的推广技巧
  • 公司网站维护怎么弄口碑营销怎么做
  • 佛山专业英文网站建设百度服务电话
  • php做电商网站开题报告建站开发
  • seo排名点击软件推荐roseonly企业网站优化