我在使用自己的类作为HashMap的键时遇到了麻烦
public class ActorId {
private final int playerId;
private final int id;
ActorId(int playerId, int id) {
this.playerId = playerId;
this.id = id;
}
public boolean equals(ActorId other) {
return this.id == other.id && this.playerId == other.playerId;
}
public int hashCode() {
int hash = 1;
hash = hash * 31 + playerId;
hash = hash * 31 + id;
return hash;
}
public String toString() {
return "#" + playerId + "." + id;
}
public int getPlayerId() …Run Code Online (Sandbox Code Playgroud) 我正在开发一个接收IPv6路由器通告数据包的Linux用户空间程序.作为RFC4861的一部分,我需要验证ICMPv6校验和.基于我的研究,其中大部分指的是一般来说,如果你计算IPv6伪报头的补码校验和以及数据包内容,结果应该是0xffff,那么就是指IP校验和.但我一直得到0x3fff的校验和.
我的校验和实现有问题吗?Linux内核在将数据包传递给用户空间之前是否验证了ICMPv6校验和?是否有一个很好的参考源来测试已知良好的ICMPv6数据包?
uint16_t
checksum(const struct in6_addr *src, const struct in6_addr *dst, const void *data, size_t len) {
uint32_t checksum = 0;
union {
uint32_t dword;
uint16_t word[2];
uint8_t byte[4];
} temp;
// IPv6 Pseudo header source address, destination address, length, zeros, next header
checksum += src->s6_addr16[0];
checksum += src->s6_addr16[1];
checksum += src->s6_addr16[2];
checksum += src->s6_addr16[3];
checksum += src->s6_addr16[4];
checksum += src->s6_addr16[5];
checksum += src->s6_addr16[6];
checksum += src->s6_addr16[7];
checksum += dst->s6_addr16[0];
checksum += dst->s6_addr16[1];
checksum += dst->s6_addr16[2];
checksum += dst->s6_addr16[3];
checksum …Run Code Online (Sandbox Code Playgroud)