-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket_oack.go
37 lines (32 loc) · 927 Bytes
/
packet_oack.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
package tftp
import (
"encoding/binary"
"io"
)
// OptionAcknowledgement is a TFTP Request Packet
type OptionAcknowledgement struct {
Options Options
}
// Opcode gets the opcode
func (o *OptionAcknowledgement) Opcode() uint16 {
return OpcodeOptionAcknowledgment
}
// ReadFrom implements the io.ReaderFrom interface
func (o *OptionAcknowledgement) ReadFrom(reader io.Reader) (n int64, err error) {
ecr := NewErrorCountReader(reader)
scanner := NewCStringScanner(ecr)
// RFC 2347 TFTP Option Extension
// Options
err = o.Options.ScanFrom(scanner)
if err == nil && ecr.Err() != io.EOF {
err = ecr.Err()
}
return ecr.Count(), err
}
// WriteTo implements the io.WriterTo interface
func (o *OptionAcknowledgement) WriteTo(writer io.Writer) (n int64, err error) {
ecw := NewErrorCountWriter(writer)
binary.Write(ecw, binary.BigEndian, OpcodeOptionAcknowledgment)
o.Options.WriteTo(ecw)
return ecw.Count(), err
}