简体   繁体   中英

Filtering out IPv6 multicast address range

For a given IPv6 address represented in a struct sockaddr_in6 data type, I want to know whether or not the address is in the multicast address range or not.

For instance, I want a function is_ipv6_multicast() that works as follows

struct sockaddr_in6* sa6;
...
if (is_ipv6_multicast(sa6)) {
    // do one thing
} else {
    // do another
}

Can anyone help me with this?

IPv6 multicast addresses have a value of 0xFF in the first byte. So you can test it like this:

int is_ipv6_multicast(struct sockaddr_in6* sa6) {
    return (sa6->sin6_addr.s6_addr[0] == 0xff);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM