2014-01-23 22:05
浏览 239


I have a question concerning tcp packet sniffing with golang. We have written a small tool which captures all incoming TCP packets comming from a fibre Tap.

The current implementation uses a libpcap wrapper under Linux. We need to port this tool to Windows. Of course, it is not possible at the moment.

So my question is, is there a cross platform solution for sniffing packets? We only need TCP packets, IP headers , no Ethernet Data and not all features of libpcap.

If there is no cross platform solution, two Code implementation would be ok, too. I know one can use raw sockets under Linux (and with some limitations under Windows). Does Golang support raw sockets and is there an example implementation for sniffing packets with sockets?

Tanks!! :-)

图片转代码服务由CSDN问答提供 功能建议

我有一个关于使用golang嗅探tcp数据包的问题。 我们编写了一个小工具,可以捕获来自光纤分流器的所有传入TCP数据包。

当前实现在Linux下使用libpcap包装器。 我们需要将此工具移植到Windows。 当然,目前尚不可能。

所以我的问题是,是否存在用于嗅探数据包的跨平台解决方案? 我们只需要TCP数据包,IP标头,没有以太网数据,并且不需要libpcap的所有功能。

如果没有跨平台的解决方案,那么两个Code的实现也是可以的。 我知道一个人可以在Linux下使用原始套接字(在Windows下有一些限制)。 Golang是否支持原始套接字,是否有使用套接字嗅探数据包的示例实现?

坦克!! :-)

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyan8267 2014-01-23 23:17

    You should be able to use the ipv4 package from

    Package ipv4 implements IP-level socket options for the Internet Protocol version 4.

    The ipv4.RawConn type and it's associated methods should work cross-platform.

    A RawConn represents a packet network endpoint that uses the IPv4 transport. It is used to control several IP-level socket options including IPv4 header manipulation. It also provides datagram based network I/O methods specific to the IPv4 and higher layer protocols that handle IPv4 datagram directly such as OSPF, GRE.

    There is also an equivalent package for ipv6.

    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题