Commit d80da258 authored by Michael Graff's avatar Michael Graff
Browse files

Add isc_netaddr_ismulticast() and isc_sockaddr_ismulticast()

parent d2e9c94e
......@@ -123,4 +123,10 @@ struct sockaddr_in6 {
((a)->s6_addr32[1] == 0) && \
((a)->s6_addr32[2] == htonl(0x0000ffff)))
/*
* Multicast
*/
#define IN6_IS_ADDR_MULTICAST(a) \
((a)->s6_addr8[0] == 0xffU)
#endif /* ISC_IPV6_H */
......@@ -92,6 +92,12 @@ isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina);
void
isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6);
isc_boolean_t
isc_netaddr_ismulticast(isc_netaddr_t *na);
/*
* Returns ISC_TRUE if the address is a multicast address
*/
ISC_LANG_ENDDECLS
#endif /* ISC_NETADDR_H */
......@@ -119,6 +119,12 @@ isc_sockaddr_format(isc_sockaddr_t *sa, char *array, unsigned int size);
* The resulting string is guaranteed to be null-terminated.
*/
isc_boolean_t
isc_sockaddr_ismulticast(isc_sockaddr_t *sa);
/*
* Returns ISC_TRUE if the address is a multicast address
*/
#define ISC_SOCKADDR_FORMATSIZE \
sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX#YYYYY")
/*
......
......@@ -212,8 +212,7 @@ isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6) {
}
void
isc_netaddr_fromsockaddr(isc_netaddr_t *t, const isc_sockaddr_t *s)
{
isc_netaddr_fromsockaddr(isc_netaddr_t *t, const isc_sockaddr_t *s) {
int family = s->type.sa.sa_family;
t->family = family;
switch (family) {
......@@ -228,3 +227,16 @@ isc_netaddr_fromsockaddr(isc_netaddr_t *t, const isc_sockaddr_t *s)
}
}
isc_boolean_t
isc_netaddr_ismulticast(isc_netaddr_t *na) {
switch (na->family) {
case AF_INET:
return (ISC_TF(ISC_IPADDR_ISMULTICAST(na->type.in.s_addr)));
break;
case AF_INET6:
return (ISC_TF(IN6_IS_ADDR_MULTICAST(&na->type.in6)));
break;
default:
return (ISC_FALSE); /* XXXMLG ? */
}
}
......@@ -378,3 +378,11 @@ isc_sockaddr_getport(isc_sockaddr_t *sockaddr) {
return (port);
}
isc_boolean_t
isc_sockaddr_ismulticast(isc_sockaddr_t *sockaddr) {
isc_netaddr_t netaddr;
isc_netaddr_fromsockaddr(&netaddr, sockaddr);
return (isc_netaddr_ismulticast(&netaddr));
}
......@@ -45,6 +45,9 @@
* It ensures that INADDR_ANY, IN6ADDR_ANY_INIT, in6addr_any, and
* in6addr_loopback are available.
*
* It ensures that IN_MULTICAST() is available to check for multicast
* addresses.
*
* MP:
* No impact.
*
......@@ -125,6 +128,16 @@ typedef isc_uint16_t in_port_t;
#define ISC_PLATFORM_RECVOVERFLOW
#endif
#define ISC__IPADDR(x) ((isc_uint32_t)htonl((isc_uint32_t)(x)))
#ifdef IN_MULTICAST
#define ISC_IPADDR_ISMULTICAST(i) IN_MULTICAST(i)
#else
#define ISC_IPADDR_ISMULTICAST(i) \
(((isc_uint32_t)(i) & ISC__IPADDR(0xf0000000)) \
== ISC__IPADDR(0xe0000000))
#endif
/***
*** Functions.
***/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment