forked from Lukasa/gopcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport_sctp.go
56 lines (46 loc) · 1.21 KB
/
transport_sctp.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
package gopcap
import (
"io"
)
//-----------------------------------------------------------------------------
// SCTPSegment
//-----------------------------------------------------------------------------
// SCTPSegment represents the data for a single Stream Control Transmission Protocol segment.
// This method of storing an SCTPSegment is less efficient than storing the binary representation
// on the wire.
type SCTPSegment struct {
SourcePort uint16
DestinationPort uint16
VerificationTag uint32
Checksum uint32
Chunks []SCTPChunk
}
func (s *SCTPSegment) TransportData() []byte {
// Extract the data from data chunks in the packet
data := make([]byte, 0)
for _, chunk := range s.Chunks {
dataChunk, isData := chunk.(*SCTPChunkData)
if isData {
data = append(data, dataChunk.Data...)
}
}
return data
}
func (s *SCTPSegment) ReadFrom(src io.Reader) error {
err := readFields(src, networkByteOrder, []interface{}{
&s.SourcePort,
&s.DestinationPort,
&s.VerificationTag,
&s.Checksum,
})
if err != nil {
return err
}
// Read the chunks from the rest of the request
chunks, err := readSCTPChunks(src)
if err != nil {
return err
}
s.Chunks = chunks
return nil
}