2
0
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:
Bob Halley
1999-07-13 01:46:15 +00:00
parent 9c43547b3a
commit 1ece2b413f
2 changed files with 38 additions and 0 deletions

View File

@@ -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 */

View File

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