Fix: control should return error

This commit is contained in:
xjasonlyu
2021-11-27 13:27:44 +08:00
parent 6bb44f9eb1
commit cf557f0eb1
3 changed files with 34 additions and 16 deletions

View File

@@ -8,14 +8,20 @@ import (
)
func bindToInterface(i *net.Interface) controlFunc {
return func(network, address string, c syscall.RawConn) error {
ipStr, _, _ := net.SplitHostPort(address)
if ip := net.ParseIP(ipStr); ip != nil && !ip.IsGlobalUnicast() {
return func(network, address string, c syscall.RawConn) (err error) {
host, _, _ := net.SplitHostPort(address)
if ip := net.ParseIP(host); ip != nil && !ip.IsGlobalUnicast() {
return nil
}
return c.Control(func(fd uintptr) {
unix.BindToDevice(int(fd), i.Name)
var innerErr error
err = c.Control(func(fd uintptr) {
innerErr = unix.BindToDevice(int(fd), i.Name)
})
if innerErr != nil {
err = innerErr
}
return
}
}