2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 16:15:27 +00:00

1246. [func] New functions isc_sockaddr_issitelocal(),

isc_sockaddr_islinklocal(), isc_netaddr_issitelocal()
                        and isc_netaddr_islinklocal().
This commit is contained in:
Mark Andrews
2002-04-03 06:38:38 +00:00
parent 5d26560e2b
commit 79a6a33184
7 changed files with 101 additions and 8 deletions

View File

@@ -1,3 +1,7 @@
1246. [func] New functions isc_sockaddr_issitelocal(),
isc_sockaddr_islinklocal(), isc_netaddr_issitelocal()
and isc_netaddr_islinklocal().
1245. [bug] Treat ENOBUFS, ENOMEM and ENFILE as soft errors for
accept().

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: ipv6.h,v 1.18 2001/11/19 03:08:24 mayer Exp $ */
/* $Id: ipv6.h,v 1.19 2002/04/03 06:38:33 marka Exp $ */
#ifndef ISC_IPV6_H
#define ISC_IPV6_H 1
@@ -137,4 +137,12 @@ struct sockaddr_in6 {
#define IN6_IS_ADDR_MULTICAST(a) \
((a)->s6_addr8[0] == 0xffU)
/*
* Unicast link / site local.
*/
#define IN6_IS_ADDR_LINKLOCAL(a) \
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
#define IN6_IS_ADDR_SITELOCAL(a) \
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
#endif /* ISC_IPV6_H */

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: netaddr.h,v 1.20 2002/02/20 03:35:36 marka Exp $ */
/* $Id: netaddr.h,v 1.21 2002/04/03 06:38:35 marka Exp $ */
#ifndef ISC_NETADDR_H
#define ISC_NETADDR_H 1
@@ -109,7 +109,19 @@ isc_netaddr_any6(isc_netaddr_t *netaddr);
isc_boolean_t
isc_netaddr_ismulticast(isc_netaddr_t *na);
/*
* Returns ISC_TRUE if the address is a multicast address
* Returns ISC_TRUE if the address is a multicast address.
*/
isc_boolean_t
isc_netaddr_islinklocal(isc_netaddr_t *na);
/*
* Returns ISC_TRUE if the address is a link local address.
*/
isc_boolean_t
isc_netaddr_issitelocal(isc_netaddr_t *na);
/*
* Returns ISC_TRUE if the address is a site local address.
*/
void

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: sockaddr.h,v 1.38 2002/02/20 03:35:38 marka Exp $ */
/* $Id: sockaddr.h,v 1.39 2002/04/03 06:38:36 marka Exp $ */
#ifndef ISC_SOCKADDR_H
#define ISC_SOCKADDR_H 1
@@ -170,7 +170,19 @@ isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size);
isc_boolean_t
isc_sockaddr_ismulticast(isc_sockaddr_t *sa);
/*
* Returns ISC_TRUE if the address is a multicast address
* Returns ISC_TRUE if the address is a multicast address.
*/
isc_boolean_t
isc_sockaddr_islinklocal(isc_sockaddr_t *sa);
/*
* Returns ISC_TRUE if the address is a link local addresss.
*/
isc_boolean_t
isc_sockaddr_issitelocal(isc_sockaddr_t *sa);
/*
* Returns ISC_TRUE if the address is a sitelocal address.
*/
#define ISC_SOCKADDR_FORMATSIZE \

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: netaddr.c,v 1.21 2002/02/20 03:35:27 marka Exp $ */
/* $Id: netaddr.c,v 1.22 2002/04/03 06:38:31 marka Exp $ */
#include <config.h>
@@ -258,6 +258,30 @@ isc_netaddr_ismulticast(isc_netaddr_t *na) {
}
}
isc_boolean_t
isc_netaddr_islinklocal(isc_netaddr_t *na) {
switch (na->family) {
case AF_INET:
return (ISC_FALSE);
case AF_INET6:
return (ISC_TF(IN6_IS_ADDR_LINKLOCAL(&na->type.in6)));
default:
return (ISC_FALSE);
}
}
isc_boolean_t
isc_netaddr_issitelocal(isc_netaddr_t *na) {
switch (na->family) {
case AF_INET:
return (ISC_FALSE);
case AF_INET6:
return (ISC_TF(IN6_IS_ADDR_SITELOCAL(&na->type.in6)));
default:
return (ISC_FALSE);
}
}
void
isc_netaddr_fromv4mapped(isc_netaddr_t *t, const isc_netaddr_t *s) {
isc_netaddr_t *src;

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: sockaddr.c,v 1.53 2002/02/20 03:35:29 marka Exp $ */
/* $Id: sockaddr.c,v 1.54 2002/04/03 06:38:32 marka Exp $ */
#include <config.h>
@@ -426,3 +426,25 @@ isc_sockaddr_ismulticast(isc_sockaddr_t *sockaddr) {
isc_netaddr_fromsockaddr(&netaddr, sockaddr);
return (isc_netaddr_ismulticast(&netaddr));
}
isc_boolean_t
isc_sockaddr_issitelocal(isc_sockaddr_t *sockaddr) {
isc_netaddr_t netaddr;
if (sockaddr->type.sa.sa_family == AF_INET6) {
isc_netaddr_fromsockaddr(&netaddr, sockaddr);
return (isc_netaddr_issitelocal(&netaddr));
}
return (ISC_FALSE);
}
isc_boolean_t
isc_sockaddr_islinklocal(isc_sockaddr_t *sockaddr) {
isc_netaddr_t netaddr;
if (sockaddr->type.sa.sa_family == AF_INET6) {
isc_netaddr_fromsockaddr(&netaddr, sockaddr);
return (isc_netaddr_islinklocal(&netaddr));
}
return (ISC_FALSE);
}

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: net.h,v 1.33 2001/11/21 13:06:20 marka Exp $ */
/* $Id: net.h,v 1.34 2002/04/03 06:38:38 marka Exp $ */
#ifndef ISC_NET_H
#define ISC_NET_H 1
@@ -137,6 +137,17 @@
#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
#endif
#ifndef IN6_IS_ADDR_LINKLOCAL
#define IN6_IS_ADDR_LINKLOCAL(a) \
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
#endif
#ifndef IN6_IS_ADDR_SITELOCAL
#define IN6_IS_ADDR_SITELOCAL(a) \
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
#endif
#ifndef IN6_IS_ADDR_LOOPBACK
#define IN6_IS_ADDR_LOOPBACK(x) \
(memcmp((x)->s6_addr, in6addr_loopback.s6_addr, 16) == 0)