Skip to content

Commit 099999f

Browse files
committed
- updated for go doc
1 parent cb3ae05 commit 099999f

File tree

3 files changed

+74
-9
lines changed

3 files changed

+74
-9
lines changed

doc.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Package silk is written without cgo to read common silk file formats.
3+
4+
What is silk?
5+
6+
https://tools.netsa.cert.org/silk/faq.html#what-silk
7+
8+
"SiLK is a suite of network traffic collection and analysis tools developed and
9+
maintained by the CERT Network Situational Awareness Team (CERT NetSA) at
10+
Carnegie Mellon University to facilitate security analysis of large networks.
11+
The SiLK tool suite supports the efficient collection, storage, and analysis
12+
of network flow data, enabling network security analysts to rapidly query
13+
large historical traffic data sets."
14+
15+
16+
Example:
17+
18+
import (
19+
"fmt"
20+
"log"
21+
"silk"
22+
)
23+
24+
func main() {
25+
26+
var testFile = "testdata/FT_RWIPV6-v2-c0-L.dat"
27+
var err error
28+
var sf silk.File
29+
30+
if sf, err = silk.OpenFile(testFile); err != nil {
31+
log.Fatalf("OpenFile() error:%s", err)
32+
}
33+
34+
log.Printf("Compression:%d", sf.Header.Compression)
35+
log.Printf("FileFlags:%d", sf.Header.FileFlags)
36+
log.Printf("FileVersion:%d", sf.Header.FileVersion)
37+
log.Printf("HeaderLength:%d", sf.Header.HeaderLength)
38+
log.Printf("MagicNumber:%x", sf.Header.MagicNumber)
39+
log.Printf("RecordFormat:%d", sf.Header.RecordFormat)
40+
log.Printf("RecordSize:%d", sf.Header.RecordSize)
41+
log.Printf("RecordVersion:%d", sf.Header.RecordVersion)
42+
log.Printf("SilkVersion:%d", sf.Header.SilkVersion)
43+
44+
log.Printf("File record count:%d\n", len(sf.Flows))
45+
46+
fmt.Printf("start_time_ms,src_ip,dst_ip,src_port,dst_port\n")
47+
for _, flow := range sf.Flows {
48+
fmt.Printf("%d,%s,%s,%d,%d\n",
49+
flow.StartTimeMS,
50+
flow.SrcIP.String(),
51+
flow.DstIP.String(),
52+
flow.SrcPort,
53+
flow.DstPort,
54+
)
55+
//Etc... for other silk.Flow values
56+
}
57+
}
58+
59+
*/
60+
package silk

file.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var isTCPAnd = uint32(math.Pow(2, 23))
2525

2626
//Flow represents a silk flow row of data
2727
//Depending on type of silk record not all fields are used
28+
//More details on the Flow stuct fields can be found here:
29+
// https://tools.netsa.cert.org/silk/faq.html#file-formats
2830
type Flow struct {
2931
startTimeMS56 uint32
3032
StartTimeMS uint64
@@ -48,11 +50,11 @@ type Flow struct {
4850
NextHopIP net.IP
4951
}
5052

51-
//ErrUnsupportedCompression unknown compression type. Currently supported
52-
//0 = no compression
53-
//1 = zlib
54-
//2 = lzo
55-
//3 = snappy
53+
// ErrUnsupportedCompression unknown compression type. Currently supported
54+
// 0 = no compression
55+
// 1 = zlib
56+
// 2 = lzo
57+
// 3 = snappy
5658
var ErrUnsupportedCompression = fmt.Errorf("Unsupported compression")
5759

5860
type offsets struct {
@@ -197,13 +199,13 @@ func getOffsets(recordSize uint16) (o offsets, err error) {
197199
return
198200
}
199201

200-
//File contains header and silk flow records
202+
//File contains header and silk slice of flow records
201203
type File struct {
202204
Header Header
203205
Flows []Flow
204206
}
205207

206-
//OpenFile opens silk file returning SilkFile and Error
208+
//OpenFile opens and parses silk file returning silk File struct and Error
207209
func OpenFile(filePath string) (sf File, err error) {
208210
var f *os.File
209211
var n int

header.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66
"os"
77
)
88

9-
//Header TODO
9+
//Header is documented here:
10+
// https://tools.netsa.cert.org/silk/faq.html#file-header
1011
type Header struct {
1112
MagicNumber []byte
1213
FileFlags uint8
@@ -23,7 +24,9 @@ type Header struct {
2324
fileSensor uint32
2425
}
2526

26-
//VarLenHeader TODO
27+
//VarLenHeader is part of the silk header. They contain different things
28+
//like the cli command used to create the file. For some file types the
29+
// variable length header also contains the year/month/day/hour of the file.
2730
type VarLenHeader struct {
2831
ID uint32
2932
Length uint32

0 commit comments

Comments
 (0)