douquan1953 2015-09-26 12:27
浏览 157

Golang不会将UDP数据包发送到多播组

currently I try to reimplement a C application in go. Part of the C application is to send a string to a multicast group. This produces the following packet captured via tcpdump:

00000000  d4 c3 b2 a1 02 00 04 00  00 00 00 00 00 00 00 00  |................|
00000010  ff ff 00 00 01 00 00 00  14 81 06 56 47 2c 01 00  |...........VG,..|
00000020  46 00 00 00 46 00 00 00  33 33 00 02 10 01 04 ce  |F...F...33......|
00000030  ef ca fe 1a 86 dd 60 00  00 00 00 10 11 01 fe 80  |......`.........|
00000040  00 00 00 00 00 00 06 ce  ef ff fe ca fe 1a ff 02  |................|
00000050  00 00 00 00 00 00 00 00  00 00 00 02 10 01 be 8f  |................|
00000060  03 e9 00 10 99 68 6e 6f  64 65 69 6e 66 6f        |.....hnodeinfo|

I tried to replicate the behavior with the following code:

const MultiCastGroup string = "ff02:0:0:0:0:0:2:1001"
const Port int = 1001
const Proto string = "udp6"
const MaxDataGramSize int = 8192

var announcedAddr = &net.UDPAddr{IP: net.ParseIP(MultiCastGroup), Port: Port}

buf := []byte("nodeinfo")
unicastConn, _ := net.ListenUDP(Proto, &net.UDPAddr{IP: net.IPv6zero, Port: 0})
unicastConn.WriteToUDP(buf, announcedAddr)

But the I don't think that it is working, because all I can capture from this via tcpdump is:

00000000  d4 c3 b2 a1 02 00 04 00  00 00 00 00 00 00 00 00  |................|
00000010  ff ff 00 00 01 00 00 00                           |........|
00000018

It doesn't seem that the packet is even send. I tried this on a Debian Wheezy machine. Did anyone if you encounter a similar problem with golang and UDP?

Thanks in advance

  • 写回答

1条回答 默认 最新

  • duanqiu9104 2015-09-26 14:43
    关注

    Did you try to listen for it on another host?

    Go (at least in 1.4) had a hard coded disable of loopback on multicast. Which means that, you can't see your own packets.

    You can override this by calling setsockopt on the socket FD itself, or:

    The golang.org/x/net/ipv6 library can do this for you.

    Or you can take the code from Here (have to poke around to find it)

    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题