-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtftp.h
130 lines (98 loc) · 3.89 KB
/
tftp.h
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
Copyright (c) 2007 Sergio Castillo Pérez
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* ------------------------------------------------------------------------- */
#ifndef _TFTP_H_
#define _TFTP_H_
#define VERSION "0.1.0"
#define RFC1350_OP_RRQ 1 /* Read request */
#define RFC1350_OP_WRQ 2 /* Write request */
#define RFC1350_OP_DATA 3 /* Data */
#define RFC1350_OP_ACK 4 /* Acknowledgment */
#define RFC1350_OP_ERROR 5 /* Error */
#define RFC1350_ERR_NOTDEF 0 /* Not defined, see err. messsage */
#define RFC1350_ERR_FNOTFOUND 1 /* File not found */
#define RFC1350_ERR_ACCESS 2 /* Access violation */
#define RFC1350_ERR_DISKFULL 3 /* Disk full or allocation exceeded */
#define RFC1350_ERR_ILEGALOP 4 /* Illegal TFTP operation */
#define RFC1350_ERR_UKNOWID 5 /* Unknown transfer ID */
#define RFC1350_ERR_FEXISTS 6 /* File already exists */
#define RFC1350_ERR_NOUSER 7 /* No such user */
#define RFC1350_PORT 69 /* Transport TFTP port */
#define RFC1350_BLOCKSIZE 512 /* Max. data block size */
#define u_int16_t unsigned short
#define OPCODE(addr) (ntohs(* ((u_int16_t *) addr)))
/* ------------------------------------------------------------------------- */
typedef enum {
FALSE,
TRUE
} BOOL;
/* ------------------------------------------------------------------------- */
/*
Read/Write header. See also RFC1350.
.-------+------------+------+------------+------.
RRQ/ | 01/02 | Filename | 0 | Mode | 0 |
WRQ '-------+------------+------+------------+------'
2 bytes string 1 byte string 1 byte
*/
#define MAXPATH_STRLEN 1024 /* Should be enough for all systems */
#define MAXMODE_STRLEN 8 /* octet, mail, netascii */
typedef struct {
u_int16_t opcode;
char filename[MAXPATH_STRLEN + 1];
char mode[MAXMODE_STRLEN + 1];
char tout[8];
char toutv[4];
} tftp_rwq_hdr;
/* ------------------------------------------------------------------------- */
/*
Data header. See also RFC1350.
.-------+------------+----------------.
DATA | 03 | Block # | Data |
'-------+------------+----------------'
2 bytes 2 bytes 1..512 bytes
*/
typedef struct {
u_int16_t opcode;
u_int16_t num_block;
char data[RFC1350_BLOCKSIZE];
} tftp_data_hdr;
/* ------------------------------------------------------------------------- */
/*
Acknowlege header. See also RFC1350.
.-------+------------.
ACK | 04 | Block # |
'-------+------------'
2 bytes 2 bytes
*/
typedef struct {
u_int16_t opcode;
u_int16_t num_block;
} tftp_ack_hdr;
/* ------------------------------------------------------------------------- */
/*
Error header. See also RFC1350.
.-------+------------+------------+------.
ERROR | 05 | ErrorCode | ErrMsg | 0 |
'-------+------------+------------+------'
2 bytes 2 bytes string 1 byte
*/
#define MAX_ERROR_STRLEN 300
typedef struct {
u_int16_t opcode;
u_int16_t code;
char message[MAX_ERROR_STRLEN + 1];
} tftp_error_hdr;
#endif
/* ------------------------------------------------------------------------- */