获取GO中数据报的目标地址

huangapple go评论75阅读模式
英文:

Getting the destination address of a datagram in GO

问题

在C语言中,可以使用setsockopt函数设置IP_PKTINFO选项。在GO语言中,有没有办法获取底层IP数据包的目标地址?

_, addr, err := d.conn.ReadFromUDP(buf)

英文:

In C it's possible to setsockopt IP_PKTINFO.
Is there any way to get the destination address of the underlying IP packet in GO?

_, addr, err := d.conn.ReadFromUDP(buf)

答案1

得分: 0

我几年前在Go的一个DNS库中实现了这个功能。
你可以在这个拉取请求的讨论中看到具体内容:这里

一年前还有另一个拉取请求将此功能公开,所以我猜你可以直接从你的代码中导入那个模块。

英文:

I implemented this in a DNS library in Go a couple of years ago.
You can see the discussion in the pull request here.

There was another PR making this public a year ago, so I guess you can just import that module from your code.

huangapple
  • 本文由 发表于 2016年2月28日 19:04:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/35681677.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定