hashicorp / mdns

Simple mDNS client/server library in Golang
MIT License
1.18k stars 209 forks source link

osx - Failed to bind to udp6 port: listen udp6 ff02::fb: setsockopt: can't assign requested address #35

Open matzhouse opened 9 years ago

matzhouse commented 9 years ago

Getting this error when trying to use Lookup/Query - OSX 10.9.4 Go 1.4.2

Specifically this test - TestServer_Lookup

➜  mdns git:(master) go test -run Lookup
2015/04/23 17:03:29 [ERR] mdns: Failed to bind to udp6 port: listen udp6 ff02::fb: setsockopt: can't assign requested address
2015/04/23 17:03:29 [INFO] mdns: Closing client {0xc20802c068 0xc20802c070 0xc20802c078 <nil> true 0xc208030360 {1 0}}
2015/04/23 17:03:29 [ERR] mdns: Failed to read packet: read udp4: use of closed network connection
2015/04/23 17:03:29 [ERR] mdns: Failed to read packet: read udp6: use of closed network connection
2015/04/23 17:03:29 [ERR] mdns: Failed to read packet: read udp4: use of closed network connection
PASS
ok      github.com/hashicorp/mdns   0.121s

Also this simple program failed to run.

package main

import (
    "fmt"
    "time"

    "github.com/hashicorp/mdns"
)

func main() {

    // Make a channel for results and start listening
    entriesCh := make(chan *mdns.ServiceEntry, 4)
    go func() {
        for entry := range entriesCh {
            fmt.Printf("Got new entry: %v\n", entry)
        }
    }()

    // Start the lookup
    //mdns.Lookup("_googlecast._tcp.local.", entriesCh)

    params := mdns.DefaultParams("_googlecast._tcp.local.")

    params.Entries = make(chan *mdns.ServiceEntry, 4)

    mdns.Query(params)

    time.Sleep(10 * time.Second)

    close(entriesCh)

}
➜  mDNSLocal  go run client.go
2015/04/23 16:37:55 [ERR] mdns: Failed to bind to udp6 port: listen udp6 ff02::fb: setsockopt: can't assign requested address
2015/04/23 16:37:56 [INFO] mdns: Closing client {0xc208038020 0xc208038028 0xc208038030 <nil> true 0xc2080520c0 {1 0}}
2015/04/23 16:37:56 [ERR] mdns: Failed to read packet: read udp4: use of closed network connection
2015/04/23 16:37:56 [ERR] mdns: Failed to read packet: read udp6: use of closed network connection
2015/04/23 16:37:56 [ERR] mdns: Failed to read packet: read udp4: use of closed network connection

Having read some other issues, I've checked that the OSX firewall is not on. Also it looks like I have an IPv6 address.

➜  mdns git:(master) ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet6 ::1 prefixlen 128
    inet 127.0.0.1 netmask 0xff000000
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
    nd6 options=1<PERFORMNUD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
    ether 40:6c:8f:1c:3f:72
    inet6 fe80::426c:8fff:fe1c:3f72%en0 prefixlen 64 scopeid 0x4
    inet 192.168.1.110 netmask 0xffffff00 broadcast 192.168.1.255
    nd6 options=1<PERFORMNUD>
    media: autoselect (100baseTX <full-duplex,flow-control>)
    status: active
fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
    lladdr 40:6c:8f:ff:fe:5d:de:be
    nd6 options=1<PERFORMNUD>
    media: autoselect <full-duplex>
    status: inactive
en1: flags=8823<UP,BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500
    ether 70:73:cb:c2:cd:ab
    nd6 options=1<PERFORMNUD>
    media: autoselect (<unknown type>)
    status: inactive
en4: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    options=60<TSO4,TSO6>
    ether b2:00:15:dd:eb:e1
    media: autoselect <full-duplex>
    status: inactive
p2p0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 2304
    ether 02:73:cb:c2:cd:ab
    media: autoselect
    status: inactive
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=63<RXCSUM,TXCSUM,TSO4,TSO6>
    ether 42:6c:8f:c1:81:00
    Configuration:
        id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
        maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
        root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
        ipfilter disabled flags 0x2
    member: en4 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 7 priority 0 path cost 0
    nd6 options=1<PERFORMNUD>
    media: <unknown type>
    status: inactive

Any pointers about what I should be looking at? Tried to do it using sudo but same result. Slightly confused as the tests run and are ok - are the above messages errors?

Thanks!

akolb1 commented 9 years ago

I am running into the same issue on Yosemite 10.10.4 Public Beta. Firewall is turned off.

euskadi31 commented 5 years ago

ping

noctarius commented 4 years ago

Try setting a scope (interface), e.g. en0 for example. OSX seems to be a bit more complicated with IPv6 :)

turekaj commented 4 years ago

I tried both lo0 and en0, no luck

noctarius commented 4 years ago

Normally you should use en0. How'd you do it?

snipem commented 4 years ago

I'm running into the same issue with i, err := net.InterfaceByName("en0")

snipem commented 4 years ago

Update I enabled native Ipv6 at my router, it's working now: https://service.avm.de/help/de/FRITZ-Box-Fon-WLAN-7490/014/hilfe_internet_ipv6

venjiang commented 2 years ago

I am running into the same issue on macOS Big Sur 11.6

mgoltzsche commented 2 years ago

Alternatively IPv6 usage can be disabled with this library:

params.DisableIPv6 = true

I had to do this to make my application run within a docker container network and discover other services via mdns.