Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow binding on address with arbitrary zone #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"net/netip"
"runtime"
"strconv"
"time"

"golang.org/x/net/icmp"
Expand Down Expand Up @@ -45,8 +46,10 @@ func Listen(ifi *net.Interface, addr Addr) (*Conn, netip.Addr, error) {
if err != nil {
return nil, netip.Addr{}, err
}

ic, err := icmp.ListenPacket("ip6:ipv6-icmp", ip.String())
// Specify the zone index to bind to the correct interface.
// The zone index is cached in https://github.com/golang/go/blob/go1.23.1/src/net/interface.go#L192
// and may result in binding on the wrong interface if using the interface name as zone.
ic, err := icmp.ListenPacket("ip6:ipv6-icmp", ip.WithZone(strconv.Itoa(ifi.Index)).String())
if err != nil {
return nil, netip.Addr{}, err
}
Expand Down