ianr0bkny / go-sonos

A Go-language library for accessing UPnP AV devices
Other
87 stars 23 forks source link

ssdp discovery fails with IPV6 addrs #2

Open skhavari opened 10 years ago

skhavari commented 10 years ago

ssdpUnicastDiscoverImpl & ssdpMulticastDiscoverImpl depend on IPV4 address but don't ensure IPV4 addresses are used.

The code currently grabs the first entry returned by net.Interface.Addrs() and on my machine the following is returned:

Addr[0] = fe80::72cd:60ff:fef3:75ad/64
Addr[1] = 192.168.1.68/24

Since the first entry is an IPV6 entry the code issues a panic and fails to complete discovery.

ianr0bkny commented 10 years ago

Hi Sam,

Thanks for the report. I'll take a look at this. I remember writing that code and thinking that I would have to revisit it later!

--Ian

On 06/24/2014 03:03 PM, Sam Khavari wrote:

|ssdpUnicastDiscoverImpl| & |ssdpMulticastDiscoverImpl| depend on IPV4 address but don't ensure IPV4 addresses are used.

The code currently grabs the first entry returned by |net.Interface.Addrs()| and on my machine the following is returned:

Addr[0] = fe80::72cd:60ff:fef3:75ad/64 Addr[1] = 192.168.1.68/24

Since the first entry is an IPV6 entry the code issues a panic and fails to complete discovery.

— Reply to this email directly or view it on GitHub https://github.com/ianr0bkny/go-sonos/issues/2.

skhavari commented 10 years ago

I managed to get by this by disabling IPV6 on mac using the instructions here http://help.unc.edu/help/how-do-i-disable-ipv6-on-mac-os-x/.

Disabling IPV6 and re-enabling it pushes the IPV6 entry to the bottom of the Addrs() array.

ianr0bkny commented 10 years ago

I've checked in a patch that should accept IPv4 or IPv6 [my code was accepting IPv4 only]. If you get a chance, please let me know if it works for you. Thanks.

skhavari commented 10 years ago

i'll give it a shot later this afternoon and let you know how it goes.

skhavari commented 10 years ago

that didn't seem to do it

panic: listen udp [fe80::72cd:60ff:fef3:75ad]:13104: bind: can't assign requested address

goroutine 1 [running]:
runtime.panic(0x3176a0, 0xc210046680)
    /usr/local/go/src/pkg/runtime/panic.c:266 +0xb6
github.com/ianr0bkny/go-sonos/ssdp.(*ssdpDefaultManager).ssdpDiscoverImpl(0xc210039a20, 0x363bf0, 0x3, 0x35aa90, 0x5, ...)
    $GOPATH/src/github.com/ianr0bkny/go-sonos/ssdp/ssdp.go:903 +0xd5
github.com/ianr0bkny/go-sonos/ssdp.(*ssdpDefaultManager).Discover(0xc210039a20, 0x363bf0, 0x3, 0x35aa90, 0x5, ...)
    $GOPATH/src/github.com/ianr0bkny/go-sonos/ssdp/ssdp.go:329 +0x70
github.com/ianr0bkny/go-sonos.Discover(0x363bf0, 0x3, 0x35aa90, 0x5, 0x868708, ...)
    $GOPATH/src/github.com/ianr0bkny/go-sonos/sonos.go:247 +0x9e
main.discoverSonos()
    $PROJ_PATH/sonos.go:22 +0xb7
main.main()
    $PROJ_PATH/sonos.go:103 +0x30
exit status 2
skhavari commented 10 years ago

The IPV6 address on this mac test machine is a link-local address and needs to be qualified with a source address or zone. on mac/linux this needs to be qualified with the interface name it belongs to...

eg: net.JoinHostPort(ipaddr.IP.String()+"%en0", TEST_DISCOVER_PORT)

with that change, the call to ListenUDP succeeds. Fun.

skhavari commented 10 years ago

on mac this does the trick

qualified_ipaddr := ipaddr.IP.String()
if ipaddr.IP.IsLinkLocalMulticast() == true || ipaddr.IP.IsLinkLocalUnicast() {
    qualified_ipaddr = ipaddr.IP.String() + ifi.Name
}
addr_port := net.JoinHostPort(qualified_ipaddr, TEST_DISCOVER_PORT)
skhavari commented 10 years ago

finding more IPV6 related issues. Modified my local build to pick up the first IPV4 address and things are working great.

ianr0bkny commented 10 years ago

Thanks for digging into this. I'm going to have to set-up an IPv6 address on a VMware machine and see if I can't shake out some of these bugs!

On 06/26/2014 09:21 PM, Sam Khavari wrote:

finding more IPV6 related issues. Modified my local build to pick up the first IPV4 address and things are working great.

— Reply to this email directly or view it on GitHub https://github.com/ianr0bkny/go-sonos/issues/2#issuecomment-47299035.

skhavari commented 10 years ago

As a VMware employee and share holder, many thanks.

borje commented 8 years ago

Any progress in this issue? I have the same problem on my macbook.

raggi commented 8 years ago

Is there any reason not to support a global listener? I'd be fine with this for my use case.

dsully commented 7 years ago

+1 - I could use a fix here.