How to read multicast datagrams but only from specific interface?

I’m trying to read multicast packets directed to, but only when received from interface eth2 (its IP address is

My sample code is based on docs for

Roughly steps are:

  1. Find interface eth2 with: net.InterfaceByName(“eth2”)
  2. Bind socket to with: net.ListenPacket(“udp”, “”)
  3. Join multicast group JoinGroup(ifi,
  4. Read data with: ReadFrom(buf)

Full code is available here:

In order to test, I send UDP packets from the attached host (
$ echo x | nc -s -u 520

Then I verify those packets are actually reaching the destination host interface:
$ sudo tcpdump -n -i eth2
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth2, link-type EN10MB (Ethernet), capture size 262144 bytes
12:08:34.745171 IP > [|rip]

However my Go code running on host is unable to read those packets:
$ sudo go run rip_mcast_listener.go
[sudo] password for lab:
2016/02/10 12:12:29 interfaceAdd: join error for ‘fe80::a00:27ff:fe52:9575’ on ‘eth2’: join: udp/[fe80::a00:27ff:fe52:9575]:520 listen error: listen udp [fe80::a00:27ff:fe52:9575]:520: bind: invalid argument
2016/02/10 12:12:29 main: waiting forever
2016/02/10 12:12:29 udpReader: reading from ‘’ on ‘eth2’

I have also posted this question on stackoverflow:

go version is: go version go1.6rc2 linux/386

Can anyone please spot where the error is?

I see that you try to listen on a ipv6 address.

Yes, by scanning over all interface addresses, the code did hit an IPv6 address. That’s not harmful. Problem is, it seemingly succeeded in binding the IPv4 address plus UDP port ( yet failed to read multicast datagrams. :frowning:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.