-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
82 lines (72 loc) · 1.29 KB
/
types.go
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
package tftp
import (
"bytes"
)
// OpcodeType stores the opcode field in a TFTP message.
type OpcodeType uint16
const (
RRQ = 1
WRQ = 2
DATA = 3
ACK = 4
ERROR = 5
)
const (
MaxDataSize = 512
MaxMsgSize = 2 + 2 + MaxDataSize
)
const (
ErrorNotDefined = 0
ErrorFileNotFound = 1
ErrorAccessViolation = 2
ErrorDiskFull = 3
ErrorIllegalOp = 4
ErrorUnknownTid = 5
ErrorFileAlreadyExists = 6
ErrorNoSuchUser = 7
)
const (
ModeNetascii = "netascii"
ModeOctet = "octet"
ModeMail = "mail"
)
// Frame contains all the fields in a TFTP message in an unpacked
// representation.
type Frame interface {
write(f *Framer) error
read(h FrameHdr, f *Framer) error
}
type FrameHdr struct {
Opcode OpcodeType
}
type RRQFrame struct {
Hdr FrameHdr
Filename string
Mode string
}
type WRQFrame struct {
Hdr FrameHdr
Filename string
Mode string
}
type DATAFrame struct {
Hdr FrameHdr
BlockNum uint16
Data []byte
}
type ACKFrame struct {
Hdr FrameHdr
BlockNum uint16
}
type ERRORFrame struct {
Hdr FrameHdr
ErrorCode uint16
ErrMsg string
}
// Framer handles serializing/deserializing TFTP messages.
type Framer struct {
*bytes.Buffer
}
func NewFramer(b *bytes.Buffer) *Framer {
return &Framer{b}
}