feat: bind socket to a particular device

This commit is contained in:
hellodword
2022-05-23 18:13:24 +08:00
parent 31d34e5269
commit 32f35894cc
7 changed files with 93 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
package sockopt
import (
"net"
"syscall"
"golang.org/x/sys/unix"
)
func bindRawConn(network string, c syscall.RawConn, bindIface *net.Interface) error {
return c.Control(func(fd uintptr) {
if bindIface != nil {
unix.BindToDevice(int(fd), bindIface.Name)
}
})
}