-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtftp_client.h
More file actions
94 lines (71 loc) · 2.13 KB
/
tftp_client.h
File metadata and controls
94 lines (71 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef TFTPCLIENT
#define TFTPCLIENT
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fcntl.h>
#include "tftp_packet.h"
#include <iostream>
#include <string.h>
#include <fstream>
#include "net_com.h"
#define TFTP_CLIENT_SERVER_TIMEOUT 2000
#define TFTP_CLIENT_ERROR_TIMEOUT 0
#define TFTP_CLIENT_ERROR_SELECT 1
#define TFTP_CLIENT_ERROR_CONNECTION_CLOSED 2
#define TFTP_CLIENT_ERROR_RECEIVE 3
#define TFTP_CLIENT_ERROR_NO_ERROR 4
#define TFTP_CLIENT_ERROR_PACKET_UNEXPECTED 5
#define TFTP_ERROR_0 "Not defined, see error message (if any)"
#define TFTP_ERROR_1 "File not found"
#define TFTP_ERROR_2 "Access violation"
#define TFTP_ERROR_3 "Disk full or allocation exceeded"
#define TFTP_ERROR_4 "Illegal TFTP operation"
#define TFTP_ERROR_5 "Unknown transfer ID"
#define TFTP_ERROR_6 "File already exists"
#define TFTP_ERROR_7 "No such user"
#define SOCKET_ERROR -1
class TFTPClient
{
private:
char* server_ip;
int server_port;
//- kliento socketo descriptorius
int socket_descriptor;
//- socket'o endpoint'u strukturos
struct sockaddr_in client_address;
struct sockaddr_in server_address;
int connection;
TFTP_Packet received_packet;
Net_com m_net;
protected:
int sendBuffer(char *);
int sendPacket(TFTP_Packet* packet);
public:
TFTPClient(char* ip, int port);
~TFTPClient();
int connectToServer();
bool getFile(char* filename, char* destination);
bool sendFile(char* filename, char* destination);
int waitForPacket(TFTP_Packet* packet, int timeout_ms = TFTP_CLIENT_SERVER_TIMEOUT);
bool waitForPacketACK(int packet_number, int timeout_ms = TFTP_CLIENT_SERVER_TIMEOUT);
int waitForPacketData(int packet_number, int timeout_ms = TFTP_CLIENT_SERVER_TIMEOUT);
void errorReceived(TFTP_Packet* packet);
};
class ETFTPSocketCreate: public std::exception
{
virtual const char* what() const throw()
{
return "Unable to create a socket";
}
};
class ETFTPSocketInitialize: public std::exception {
virtual const char* what() const throw() {
return "Unable to find socket library";
}
};
void DEBUGMSG(char*);
#endif