How do you determine equality between two IPv6 addresses?

后端 未结 4 1781
误落风尘
误落风尘 2020-12-28 19:05

I have an application that allows administrators to specify valid IP addresses from which web service requests can be made. I simply take the configured IP addresses and co

4条回答
  •  感动是毒
    2020-12-28 19:32

    The only difference is the %10 and %11 - what gives?

    These are IPv6 zone identifiers, link-local addresses, i.e. fe80 prefix, are only guaranteed unique on the local link. This means that the addresses fe80:8179:5576:c6d0:8b16%11 and fe80::8179:5576:c6d0:8b16%10 may refer to different machines, one has to be accessed through interface 10 and the other through interface 11.

    Have a look at the definition of sockaddr_in6,

    struct sockaddr_in6 {
      short sin6_family;
      u_short sin6_port;
      u_long sin6_flowinfo;
      struct in6_addr sin6_addr;
      u_long sin6_scope_id;
    };
    

    You will need to compare the family, address, and scope-id fields for a complete match.

提交回复
热议问题