-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtftp_server.h
More file actions
85 lines (64 loc) · 1.65 KB
/
tftp_server.h
File metadata and controls
85 lines (64 loc) · 1.65 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
#include <stdio.h>
#include <arpa/inet.h>
/**
* Set flag to 1 to enable debugging log messages.
*/
#define DEBUG 0
struct tftp_server {
int port;
int retries;
char *file;
};
/* typedef union { */
/* uint16_t opcode; */
/* struct { */
/* uint16_t opcode; /1* RRQ or WRQ *1/ */
/* uint8_t filename_and_mode[514]; */
/* } request; */
/* struct { */
/* uint16_t opcode; /1* DATA *1/ */
/* uint16_t block_number; */
/* uint8_t data[512]; */
/* } data; */
/* struct { */
/* uint16_t opcode; /1* ACK *1/ */
/* uint16_t block_number; */
/* } ack; */
/* struct { */
/* uint16_t opcode; /1* ERROR *1/ */
/* uint16_t error_code; */
/* uint8_t error_string[512]; */
/* } error; */
/* } tftp_message; */
typedef struct {
uint16_t opcode;
union {
struct {
char filename_and_mode[514];
char mode[8];
} request;
struct {
uint16_t block_number;
uint8_t data[512];
} data;
struct {
uint16_t block_number;
} ack;
struct {
uint16_t error_code;
uint8_t error_string[512];
} error;
};
} tftp_message;
int start_server(struct tftp_server *s);
/**
* Transfers the specified source file to the addressed client using the given
* client in BINARY mode transfer.
*
* @param src_file source file to be transferred;
* @param socket socket to be used to transfer the file to the recipient
* client;
* @param cli_addr address of the client requesting the file transfer.
*/
void transfer_binary_mode(FILE *src_file, int socket, struct sockaddr_in *cli_addr);
int parse_message(int socket_desc, tftp_message *m,struct sockaddr_in *client_addr);