Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hyperized/bpf
Go utility library for bpf devices
https://github.com/hyperized/bpf
Last synced: 27 days ago
JSON representation
Go utility library for bpf devices
- Host: GitHub
- URL: https://github.com/hyperized/bpf
- Owner: hyperized
- License: mit
- Created: 2019-10-09T11:28:38.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-18T09:07:14.000Z (over 4 years ago)
- Last Synced: 2024-06-20T08:10:42.448Z (5 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# bpf/files [![GoDoc](https://godoc.org/github.com/hyperized/bpf/file?status.svg)](https://godoc.org/github.com/hyperized/bpf/file)
Utility library for bpf files.
Useful for BSD: Darwin, Dragonfly, FreeBSD, NetBSD & OpenBSD
## Files
Example implementation:
```go
package mainimport (
"github.com/hyperized/bpf/file"
"log"
)func main() {
// Use logging, off by default
bpf, err := file.GetBpfDevice(true)
defer func() {
if err := bpf.Close(); err != nil {
log.Printf(err.Error())
}
}()// Showing off methods available
if bpf != nil {
log.Println(bpf.File())
log.Println(bpf.Path())
log.Println(bpf.FileDescriptor())
} else {
log.Println(err)
}// Open new bpf device, this will be a new one, since the previous one is already open
bpf2, err := file.GetBpfDevice(true)
defer func() {
if err := bpf2.Close(); err != nil {
log.Printf(err.Error())
}
}()log.Println(bpf2.Path())
}```
Results in:
```
2019/10/09 14:35:40 github.com/hyperized/bpf/files: /dev/bpf0 cannot be accessed, skipping
2019/10/09 14:35:40 github.com/hyperized/bpf/files: /dev/bpf1 cannot be accessed, skipping
2019/10/09 14:35:40 github.com/hyperized/bpf/files: using /dev/bpf10
2019/10/09 14:35:40 &{0xc0000221e0}
2019/10/09 14:35:40 /dev/bpf10
2019/10/09 14:35:40 3
2019/10/09 14:35:40 github.com/hyperized/bpf/files: /dev/bpf0 cannot be accessed, skipping
2019/10/09 14:35:40 github.com/hyperized/bpf/files: /dev/bpf1 cannot be accessed, skipping
2019/10/09 14:35:40 github.com/hyperized/bpf/files: /dev/bpf10 cannot be accessed, skipping
2019/10/09 14:35:40 github.com/hyperized/bpf/files: using /dev/bpf100
2019/10/09 14:35:40 /dev/bpf100
2019/10/09 14:35:40 github.com/hyperized/bpf/files: closing /dev/bpf100
2019/10/09 14:35:40 github.com/hyperized/bpf/files: closing /dev/bpf10
```## Author
Gerben Geijteman