kjee
kjee

Reputation: 427

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?

Upvotes: 0

Views: 276

Answers (1)

dbush
dbush

Reputation: 223739

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);
}

Upvotes: 3

Related Questions