小编dlu*_*ist的帖子

为什么自定义对象不是HashMap的等效键?

我在使用自己的类作为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)

java hash key hashmap map

7
推荐指数
1
解决办法
7407
查看次数

如何验证ICMPv6校验和?(为什么我一直得到0x3fff的校验和?)

我正在开发一个接收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)

c sockets linux ipv6 icmp

5
推荐指数
1
解决办法
2611
查看次数

标签 统计

c ×1

hash ×1

hashmap ×1

icmp ×1

ipv6 ×1

java ×1

key ×1

linux ×1

map ×1

sockets ×1