misc: updated deps

This commit is contained in:
evilsocket 2019-02-22 12:59:11 +01:00
commit c3a4dc8cf5
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
22 changed files with 218 additions and 48 deletions

View file

@ -120,7 +120,7 @@ func Error(format string, args ...interface{}) {
do(ERROR, format, args...)
}
// Fata emits a fatal error message and calls the log.OnFatal callback.
// Fatal emits a fatal error message and calls the log.OnFatal callback.
func Fatal(format string, args ...interface{}) {
do(FATAL, format, args...)
OnFatal()

View file

@ -58,6 +58,43 @@ func padded(s string, maxLen int, align alignment) string {
return fmt.Sprintf("%s%s%s", strings.Repeat(" ", lPad), s, strings.Repeat(" ", rPad))
}
func lineSeparator(num int, columns []string, rows [][]string) string {
lineSep := ""
first := ""
div := ""
end := ""
if num == 0 {
first = "┌"
div = "┬"
end = "┐"
} else if num == 1 {
first = "├"
div = "┼"
end = "┤"
} else if num == 2 {
first = "└"
div = "┴"
end = "┘"
}
for colIndex, colHeader := range columns {
column := []string{colHeader}
for _, row := range rows {
column = append(column, row[colIndex])
}
mLen := maxLen(column)
if colIndex == 0 {
lineSep += fmt.Sprintf(first+"%s", strings.Repeat("─", mLen+1))
} else {
lineSep += fmt.Sprintf(div+"%s", strings.Repeat("─", mLen+1))
}
}
lineSep += end
return lineSep
}
// Table accepts a slice of column labels and a 2d slice of rows
// and prints on the writer an ASCII based datagrid of such
// data.
@ -73,7 +110,6 @@ func Table(w io.Writer, columns []string, rows [][]string) {
}
colPaddings := make([]int, 0)
lineSep := ""
for colIndex, colHeader := range columns {
column := []string{colHeader}
for _, row := range rows {
@ -81,30 +117,29 @@ func Table(w io.Writer, columns []string, rows [][]string) {
}
mLen := maxLen(column)
colPaddings = append(colPaddings, mLen)
lineSep += fmt.Sprintf("+%s", strings.Repeat("-", mLen+1))
}
lineSep += "+"
table := ""
table := "\n"
// header
table += fmt.Sprintf("%s\n", lineSep)
table += fmt.Sprintf("%s\n", lineSeparator(0, columns, rows))
for colIndex, colHeader := range columns {
table += fmt.Sprintf("|%s", padded(colHeader, colPaddings[colIndex], alignCenter))
table += fmt.Sprintf("%s", padded(colHeader, colPaddings[colIndex], alignCenter))
}
table += fmt.Sprintf("|\n")
table += fmt.Sprintf("%s\n", lineSep)
table += fmt.Sprintf("│\n")
table += fmt.Sprintf("%s\n", lineSeparator(1, columns, rows))
// rows
for _, row := range rows {
for colIndex, cell := range row {
table += fmt.Sprintf("|%s", padded(cell, colPaddings[colIndex], alignLeft))
table += fmt.Sprintf("%s", padded(cell, colPaddings[colIndex], alignLeft))
}
table += fmt.Sprintf("|\n")
table += fmt.Sprintf("\n")
}
// footer
table += lineSep
table += fmt.Sprintf("%s\n", lineSeparator(2, columns, rows))
fmt.Fprintf(w, "\n%s\n", table)
fmt.Fprintf(w, "%s", table)
}

View file

@ -168,13 +168,6 @@ type Config struct {
NoCumulativeStats bool
}
// htons converts a short (uint16) from host-to-network byte order.
// Thanks to mikioh for this neat trick:
// https://github.com/mikioh/-stdyng/blob/master/afpacket.go
func htons(i uint16) uint16 {
return (i<<8)&0xff00 | i>>8
}
// Copyright (c) 2012 The Go Authors. All rights reserved.
// Source code in this file is based on src/net/interface_linux.go,
// from the Go standard library. The Go license can be found here:

View file

@ -128,7 +128,7 @@ func (p *packetConn) ReadFrom(b []byte) (int, net.Addr, error) {
if deadline.IsZero() {
timeout = readTimeout
} else {
timeout = deadline.Sub(time.Now())
timeout = time.Until(deadline)
if timeout > readTimeout {
timeout = readTimeout
}
@ -280,25 +280,6 @@ func configureBPF(fd int, ifi *net.Interface, proto uint16) (int, error) {
return buflen, nil
}
// setBPFDirection enables filtering traffic traveling in a specific direction
// using BPF, so that traffic sent by this package is not captured when reading
// using this package.
func setBPFDirection(fd int, direction int) error {
_, _, err := syscall.Syscall(
syscall.SYS_IOCTL,
uintptr(fd),
// Even though BIOCSDIRECTION is preferred on FreeBSD, BIOCSSEESENT continues
// to work, and is required for other BSD platforms
syscall.BIOCSSEESENT,
uintptr(unsafe.Pointer(&direction)),
)
if err != 0 {
return syscall.Errno(err)
}
return nil
}
// assembleBpfInsn assembles a slice of bpf.RawInstructions to the format required by
// package syscall.
func assembleBpfInsn(filter []bpf.RawInstruction) []syscall.BpfInsn {

27
vendor/github.com/mdlayher/raw/raw_direction_bsd.go generated vendored Normal file
View file

@ -0,0 +1,27 @@
// +build darwin dragonfly freebsd netbsd
package raw
import (
"syscall"
"unsafe"
)
// setBPFDirection enables filtering traffic traveling in a specific direction
// using BPF, so that traffic sent by this package is not captured when reading
// using this package.
func setBPFDirection(fd int, direction int) error {
_, _, err := syscall.Syscall(
syscall.SYS_IOCTL,
uintptr(fd),
// Even though BIOCSDIRECTION is preferred on FreeBSD, BIOCSSEESENT continues
// to work, and is required for other BSD platforms
syscall.BIOCSSEESENT,
uintptr(unsafe.Pointer(&direction)),
)
if err != 0 {
return syscall.Errno(err)
}
return nil
}

View file

@ -0,0 +1,35 @@
// +build openbsd
package raw
import (
"syscall"
"unsafe"
)
// setBPFDirection enables filtering traffic traveling in a specific direction
// using BPF, so that traffic sent by this package is not captured when reading
// using this package.
func setBPFDirection(fd int, direction int) error {
var dirfilt uint
switch direction {
case bpfDIn:
// filter outbound
dirfilt = syscall.BPF_DIRECTION_OUT
default:
// no filter
}
_, _, err := syscall.Syscall(
syscall.SYS_IOCTL,
uintptr(fd),
syscall.BIOCSDIRFILT,
uintptr(unsafe.Pointer(&dirfilt)),
)
if err != 0 {
return syscall.Errno(err)
}
return nil
}

View file

@ -53,6 +53,13 @@ type socket interface {
SetTimeout(time.Duration) error
}
// htons converts a short (uint16) from host-to-network byte order.
// Thanks to mikioh for this neat trick:
// https://github.com/mikioh/-stdyng/blob/master/afpacket.go
func htons(i uint16) uint16 {
return (i<<8)&0xff00 | i>>8
}
// listenPacket creates a net.PacketConn which can be used to send and receive
// data at the device driver level.
func listenPacket(ifi *net.Interface, proto uint16, cfg Config) (*packetConn, error) {
@ -124,7 +131,7 @@ func (p *packetConn) ReadFrom(b []byte) (int, net.Addr, error) {
for {
if !deadline.IsZero() {
timeout = deadline.Sub(time.Now())
timeout = time.Until(deadline)
if timeout > readTimeout {
timeout = readTimeout
}