mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
add isc_sockaddr_from{in,in6}
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#define ISC_SOCKADDR_H 1
|
||||
|
||||
#include <isc/net.h>
|
||||
#include <isc/list.h>
|
||||
#include <isc/lang.h>
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
@@ -30,6 +31,7 @@ typedef struct isc_sockaddr {
|
||||
struct sockaddr_in6 sin6;
|
||||
} type;
|
||||
unsigned int length; /* XXXRTH beginning? */
|
||||
ISC_LINK(struct isc_sockaddr) link;
|
||||
} isc_sockaddr_t;
|
||||
|
||||
isc_boolean_t
|
||||
@@ -38,6 +40,14 @@ isc_sockaddr_equal(isc_sockaddr_t *a, isc_sockaddr_t *b);
|
||||
unsigned int
|
||||
isc_sockaddr_hash(isc_sockaddr_t *sockaddr, isc_boolean_t address_only);
|
||||
|
||||
void
|
||||
isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, struct in_addr *ina,
|
||||
unsigned int port);
|
||||
|
||||
void
|
||||
isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, struct in6_addr *ina6,
|
||||
unsigned int port);
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
#endif /* ISC_SOCKADDR_H */
|
||||
|
@@ -110,3 +110,31 @@ isc_sockaddr_hash(isc_sockaddr_t *sockaddr, isc_boolean_t address_only) {
|
||||
|
||||
return (h);
|
||||
}
|
||||
|
||||
void
|
||||
isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, struct in_addr *ina,
|
||||
unsigned int port)
|
||||
{
|
||||
sockaddr->type.sin.sin_family = AF_INET;
|
||||
#ifdef ISC_NET_HAVESALEN
|
||||
sockaddr->type.sin.sin_len = sizeof sockaddr->type.sin;
|
||||
#endif
|
||||
sockaddr->type.sin.sin_addr = *ina;
|
||||
sockaddr->type.sin.sin_port = htons(port);
|
||||
sockaddr->length = sizeof sockaddr->type.sin;
|
||||
ISC_LINK_INIT(sockaddr, link);
|
||||
}
|
||||
|
||||
void
|
||||
isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, struct in6_addr *ina6,
|
||||
unsigned int port)
|
||||
{
|
||||
sockaddr->type.sin6.sin6_family = AF_INET6;
|
||||
#ifdef ISC_NET_HAVESALEN
|
||||
sockaddr->type.sin6.sin6_len = sizeof sockaddr->type.sin6;
|
||||
#endif
|
||||
sockaddr->type.sin6.sin6_addr = *ina6;
|
||||
sockaddr->type.sin6.sin6_port = htons(port);
|
||||
sockaddr->length = sizeof sockaddr->type.sin6;
|
||||
ISC_LINK_INIT(sockaddr, link);
|
||||
}
|
||||
|
Reference in New Issue
Block a user