I’m trying to read multicast packets directed to 126.96.36.199:520, but only when received from interface eth2 (its IP address is 188.8.131.52/24).
My sample code is based on docs for golang.org/x/net/ipv4.
Roughly steps are:
- Find interface eth2 with: net.InterfaceByName(“eth2”)
- Bind socket to 184.108.40.206:520 with: net.ListenPacket(“udp”, “220.127.116.11:520”)
- Join multicast group 18.104.22.168: JoinGroup(ifi, 22.214.171.124)
- Read data with: ReadFrom(buf)
Full code is available here: http://play.golang.org/p/YOwu38OQdw
In order to test, I send UDP packets from the attached host (126.96.36.199/24):
$ echo x | nc -s 188.8.131.52 -u 184.108.40.206 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 220.127.116.11.51920 > 18.104.22.168.520: [|rip]
However my Go code running on host 22.214.171.124 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 ‘126.96.36.199’ on ‘eth2’
I have also posted this question on stackoverflow: http://stackoverflow.com/questions/35300039/in-golang-how-to-receive-multicast-packets-with-socket-bound-to-specific-addres
go version is: go version go1.6rc2 linux/386
Can anyone please spot where the error is?