资源简介
UDP协议实现linux下的TFTP客户端代码
代码片段和文件信息
/**********************************************************
Date: NOV 28th 2006
Project : TFTP Client
Programers:
Jonathan Felske
Andrew Fullard
Craig Holmes
Reza Rahmanian
Adam Tomalty
File: TFTP Client (main)
Purpose: A TFTP client that will request a connections from
the server and transefet files.
Notes: Here we are using the sendto and recvfrom
functions so the server and client can exchange data.
***********************************************************/
#include “tftp.h“
/*a function to print the Help menu*/
void help (char *);
/*a function to create the request packet read or write*/
int req_packet (int opcode char *filename char *mode char buf[]);
/*a function to creat an ACK packet*/
int ack_packet (int block char buf[]);
/*a function to create the Error packets*/
int err_packet (int err_code char *err_msg char buf[]);
/*a function that will print the ip:port pair of the server or client plus data sent or recieved*/
void ip_port (struct sockaddr_in host);
/*a function to send a file to the server*/
void tsend (char *pFilename struct sockaddr_in server char *pMode
int sock);
/*a function to get a file from the server*/
void tget (char *pFilename struct sockaddr_in server char *pMode int sock);
/* default values which can be controlled by command line */
char path[64] = “/tmp/“;
int port = 69;
unsigned short int ackfreq = 1;
int datasize = 512;
int debug = 0 w_size = 1 p_length = 512;
int
main (int argc char **argv)
{
/*local variables */
extern char *optarg;
int sock server_len len opt; //n;
char opcode filename[196] mode[12] = “octet“;
struct hostent *host; /*for host information */
struct sockaddr_in server; // client; /*the address structure for both the server and client */
FILE *fp; /*a pointer to a file that the client will send or get from the server */
if (argc < 2)
{
help (argv[0]);
return 0;
}
if (!(host = gethostbyname (argv[1])))
{
perror (“Client could not get host address information“);
exit (2);
}
/* All of the following deals with command line switches */
while ((opt = getopt (argc argv “dnoh:P:p:g:l:w:“)) != -1) /* this function is handy */
{
switch (opt)
{
case ‘d‘: /* debug mode (no opts) */
debug = 1;
break;
case ‘P‘: /* Port (opt required) */
port = atoi (optarg);
if (debug)
{
printf (“Client: The port number is: %d\n“ port);
}
break;
case ‘p‘: /* put a file on the server */
strncpy (filename optarg sizeof (filename) - 1);
opcode = WRQ;
fp = fopen (filename “r“); /*opened the file for reading */
if (fp == NULL)
{
printf (“Client: file could not be opened\n“);
return 0;
}
if (debug)
{
printf (“Client: The file name is: %s and can be read“
filename);
}
fclose (fp);
break;
case ‘g‘: /*get a file from the server */
strncpy (filename optarg sizeof (filename) - 1);
opcode = RR
- 上一篇:5个遗传算法C语言源码
- 下一篇:基于51单片机的电子琴程序 protues仿真
相关资源
- TFTP_C程序实现
- tftp服务器源码,纯c语言
- DHCP源码含server relay client
- linux局域网聊天软件server+client 源码
- 基于POP3、SMTP协议的MFC实现邮件客户端
- ntripclient-c++
- IOCP SOCKETserver and client 并且内]
- tftp_vs2010.rar
- vc++ tcp 客户端和服务器端
- TFTP协议的C语言实现客户端和服务器
- VC++实现客户端与服务器端的文件传输
- c6client.cpp
- 基于C#写的TCP 客户端多线程处理源码
- opc da client sdk c++ 源码(开源)
- FTP服务器CLIENT端C语言源文件
- DSS中的RTSPclientLib程序
- tftpd32 源代码VC
- HTTPClient
- c++ 聊天室(含server+client)
- Visual C++ OPC Client Example
- windows平台简单的http_client实现POST-GE
- C语言编译的基于Linux下的client与serv
- 简单的winsock编程客户机、服务器
- HTTP Client C++实现
- TCP/IP聊天测试程序 Client + Server
- socket--文件传输--源代码--C++版C/S双端
- rabbimqclientC++
评论
共有 条评论