1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tuple.go 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
Steffen Siering 提交于 2016-11-14 14:50 . More Packetbeat cleanups (#2972)
package icmp
import (
"fmt"
"net"
)
// In order for the icmpTuple to be used as hashtable key, it needs to have
// a fixed size. This means the net.IP is problematic because it's internally
// represented as a slice. Therefore the hashableIcmpTuple type is introduced
// which internally is a simple byte array.
const maxIcmpTupleRawSize = 1 + 16 + 16 + 2 + 2
type hashableIcmpTuple [maxIcmpTupleRawSize]byte
type icmpTuple struct {
icmpVersion uint8
srcIP net.IP
dstIP net.IP
id uint16
seq uint16
}
func (t *icmpTuple) Reverse() icmpTuple {
return icmpTuple{
icmpVersion: t.icmpVersion,
srcIP: t.dstIP,
dstIP: t.srcIP,
id: t.id,
seq: t.seq,
}
}
func (t *icmpTuple) Hashable() hashableIcmpTuple {
var hash hashableIcmpTuple
copy(hash[0:16], t.srcIP)
copy(hash[16:32], t.dstIP)
copy(hash[32:37], []byte{byte(t.id >> 8), byte(t.id), byte(t.seq >> 8), byte(t.seq), t.icmpVersion})
return hash
}
func (t *icmpTuple) String() string {
return fmt.Sprintf("icmpTuple version[%d] src[%s] dst[%s] id[%d] seq[%d]",
t.icmpVersion, t.srcIP, t.dstIP, t.id, t.seq)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v5.6.13

搜索帮助

0d507c66 1850385 C8b1a773 1850385