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)

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料