91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 10KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-16
  • 語言: 其他
  • 標簽: tftp升級??

資源簡介

該文檔實現tftp文件的傳輸,文檔中包括客戶端與服務端的代碼,供大家學習參考。

資源截圖

代碼片段和文件信息

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include?
#include
#include?

#include?
#include?
#include?
#include?
#include???
#include?
#include??

#include?“define.h“
#include?“makepack.h“

int?sock?=?-1;
char?desthost[256]?=?“127.0.0.1“; //目的主機地址,默認為本機
int??filemode?=?TFTP_OCTET; //發送模式為octet

typedef?void?(*?CMDFUNC)(char?[][256]int?pcount);

typedef?struct?_cmdnum{
char?*cmd; //命令代碼
int?num; //序號
int?paramcount; //參數個數
CMDFUNC?callback; //回調函數名
}CMDNUM*PCMDNUM;

/*定義幫助文檔*/
char?*helptext?=?“help:???? 顯示幫助信息\n\
connect?dest_ip: 連接服務器\n\
exit: 退出程序\n\
get?filename: 從服務器端下載文件\n\
put?local_fname?dest_fname: 向服務器上傳文件\n“;

void?showhelp (char?cmd[][256]int?pcount); //顯示幫助信息
void?connectto (char?cmd[][256]int?pcount); //連接目的主機
void?quit (char?cmd[][256]int?pcount); //退出
void?getfile (char?cmd[][256]int?pcount); //下載文件
void?putfile (char?cmd[][256]int?pcount); //上傳文件

/*定義一個存儲回調函數的命令代碼數組,其值與不同的命令相對應*/
CMDNUM?cmdlist[]?=?{
{“help“???10showhelp}
{“connect“21connectto}
{“exit“???30quit}
{“get“????41getfile}
{“put“????52putfile} };

//分開輸入的命令字符串得到命令代碼及參數
int?stripcmd(char?*schar?cmd[][256])
{
int?i=0;
char?*token=NULL;
char?seps[]?=?“?\t\n“;
token?=?strtok(?s?seps?); /*斷開命令與參數*/
while(token!=NULL){
if?(i>2)?break; /*因為回調函數的參數最多為3個,當識別出的參數多于2個時,忽略多于的*/?
strcpy(cmd[i]token);
token?=?strtok(?NULL?seps?);/*從s開頭開始的一個個被分割的串。當沒有被分割的串時則返回NULL。
  ??????????????????????????所有seps中包含的字符都會被濾掉,并將被濾掉的地方設為一處分割的節點*/
i++;
}
return?i;?
}

//獲取命令數組的下標
int??getcmdsubscript(char?*s)
{
int?i?=?0;
for(i=0;i if(strcasecmp(scmdlist[i].cmd)==0){
return?i;
}
}
return?-1;??
}

//解析命令回調相應命令處理函數
void?parsecmd(char?*s)
{
char?cmd[3][256];
int?pcount?=?0;
int?subscript?=?-1;
pcount?=?stripcmd(scmd); /*分開命令與參數,返回值為參數的個數加1*/
subscript=getcmdsubscript(cmd[0]); /*獲取下標*/
if(subscript==-1){
printf(“No?such?commond?\n“);
return;
}
else{
cmdlist[subscript].callback(cmdpcount-1);/*根據命令回調相應的函數*/
}
}


int?main(int?argc?char*?argv[])
{
printf(“**********************?Welcome!?**********************\n\n\
?????????????????This?is?a?TFTP_client?tool.\n\n“);
printf(helptext);???//顯示幫助信息
printf(“******************************************************\n\n“);

char?cmd[256];?????//cmd存放接收進來的命令字符?
memset(cmd?0?sizeof(cmd));
struct?sockaddr_in?addr;
memset(&addr?0?sizeof(struct?sockaddr_in));
????
????sock?=?socket(AF_INETSOCK_DGRAM0);
if(sock==-1)
{
printf(“創建SOCKET失敗\n“);
exit(0);
}

while(1)
{
ff

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-09-02?10:07??tftp_test\
?????目錄???????????0??2016-09-02?10:10??tftp_test\client\
?????文件?????????979??2016-07-13?14:33??tftp_test\client\define.h
?????文件????????1391??2009-09-04?10:10??tftp_test\client\makepack.h
?????文件???????13284??2016-09-02?10:10??tftp_test\client\tftpclient.c
?????文件?????????285??2016-07-16?16:19??tftp_test\readMe.txt
?????目錄???????????0??2016-09-02?10:09??tftp_test\server\
?????文件?????????980??2016-07-12?14:29??tftp_test\server\define.h
?????文件???????10523??2016-09-02?10:09??tftp_test\server\tftpServer.c

評論

共有 條評論

相關資源