Feature: bind socket to interface by native API on Windows (#2662)
This commit is contained in:
@ -51,7 +51,15 @@ func ListenPacket(ctx context.Context, network, address string, options ...Optio
|
||||
|
||||
lc := &net.ListenConfig{}
|
||||
if cfg.interfaceName != "" {
|
||||
addr, err := bindIfaceToListenConfig(cfg.interfaceName, lc, network, address)
|
||||
var (
|
||||
addr string
|
||||
err error
|
||||
)
|
||||
if cfg.fallbackBind {
|
||||
addr, err = fallbackBindIfaceToListenConfig(cfg.interfaceName, lc, network, address)
|
||||
} else {
|
||||
addr, err = bindIfaceToListenConfig(cfg.interfaceName, lc, network, address)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -83,8 +91,14 @@ func dialContext(ctx context.Context, network string, destination net.IP, port s
|
||||
|
||||
dialer := &net.Dialer{}
|
||||
if opt.interfaceName != "" {
|
||||
if err := bindIfaceToDialer(opt.interfaceName, dialer, network, destination); err != nil {
|
||||
return nil, err
|
||||
if opt.fallbackBind {
|
||||
if err := fallbackBindIfaceToDialer(opt.interfaceName, dialer, network, destination); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err := bindIfaceToDialer(opt.interfaceName, dialer, network, destination); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if opt.routingMark != 0 {
|
||||
|
Reference in New Issue
Block a user