Skip to content

Commit a5fd02d

Browse files
committed
fixed markdown issues
1 parent 167e205 commit a5fd02d

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

readme.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
ZSocket
2-
-------
1+
# ZSocket
2+
33
ZSocket is a library that wraps the linux zero-copy socket syscall to create a ring buffer in a memory mapped file.
44
It also contains some utility functions and types to help with a handful of layer 2, 3, and 4 types.
55
It is a lot like libcap, except it has easy to understand facilities for writing (injecting packets) to an interface.
66

77
ZSocket doesn't contain or wrap any C/C++, and it is lock free and thread safe.
88

99
The following program prints out all know layer types to ZSocket on a given interface:
10+
1011
```go
1112
package main
1213

1314
import (
14-
"fmt"
15+
"fmt"
1516

16-
"github.com/newtools/zsocket"
17-
"github.com/newtools/zsocket/nettypes"
17+
"github.com/newtools/zsocket"
18+
"github.com/newtools/zsocket/nettypes"
1819
)
1920

2021
func main() {
21-
// args: interfaceIndex, options, maxFrameSize, and maxTotalFrames
22-
23-
// inerfaceIndex: the index of the net device you want to open a raw socket to
24-
// options: RX and TX, or just one or the other?
25-
// maxFrameSize: must be a power of 2, bigger than zsocket.MINIMUM_FRAME_SIZE,
26-
// and smaller than maximum frame size
27-
// maxTotalFrames: must be at least 16, and be a multiple of 8.
28-
zs, err := zsocket.NewZSocket(14, zsocket.ENABLE_RX, 2048, 64, nettypes.All)
29-
// the above will result in a ring buffer of 64 frames at
30-
// (2048 - zsocket.PacketOffset()) *writeable* bytes each
31-
// for a total of 2048*64 bytes of *unswappable* system memory consumed.
32-
if err != nil {
33-
panic(err)
34-
}
35-
zs.Listen(func(f *nettypes.Frame, frameLen, capturedLen uint16) {
36-
fmt.Printf(f.String(capturedLen, 0))
37-
})
22+
// args: interfaceIndex, options, maxFrameSize, and maxTotalFrames
23+
24+
// inerfaceIndex: the index of the net device you want to open a raw socket to
25+
// options: RX and TX, or just one or the other?
26+
// maxFrameSize: must be a power of 2, bigger than zsocket.MINIMUM_FRAME_SIZE,
27+
// and smaller than maximum frame size
28+
// maxTotalFrames: must be at least 16, and be a multiple of 8.
29+
zs, err := zsocket.NewZSocket(14, zsocket.ENABLE_RX, 2048, 64, nettypes.All)
30+
// the above will result in a ring buffer of 64 frames at
31+
// (2048 - zsocket.PacketOffset()) *writeable* bytes each
32+
// for a total of 2048*64 bytes of *unswappable* system memory consumed.
33+
if err != nil {
34+
panic(err)
35+
}
36+
zs.Listen(func(f *nettypes.Frame, frameLen, capturedLen uint16) {
37+
fmt.Printf(f.String(capturedLen, 0))
38+
})
3839
}
3940
```
4041

@@ -43,4 +44,4 @@ func main() {
4344
2. Learn how to set up a docker container with a custom veth-pair in the utils folder (useful for setting up
4445
complex virtual networking scenarios)
4546

46-
3. Play around with FakeInterface to (and its examples folder) to play around with networking protocols.
47+
3. Play around with FakeInterface to (and its examples folder) to play around with networking protocols.

0 commit comments

Comments
 (0)