2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Wrap inet_ntop() and use that in the _totext() functions. The wrapper calls

inet_ntop() and copies the output (but not the trailing null) into the buffer.
This commit is contained in:
Brian Wellington
2001-01-25 20:14:42 +00:00
parent b586eb4408
commit 330705066b
6 changed files with 34 additions and 41 deletions

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rdata.c,v 1.141 2001/01/09 21:51:20 bwelling Exp $ */
/* $Id: rdata.c,v 1.142 2001/01/25 20:14:36 bwelling Exp $ */
#include <config.h>
#include <ctype.h>
@@ -107,6 +107,9 @@ name_length(dns_name_t *name);
static isc_result_t
str_totext(const char *source, isc_buffer_t *target);
static isc_result_t
inet_totext(int af, isc_region_t *src, isc_buffer_t *target);
static isc_boolean_t
buffer_empty(isc_buffer_t *source);
@@ -1469,6 +1472,19 @@ str_totext(const char *source, isc_buffer_t *target) {
return (ISC_R_SUCCESS);
}
static isc_result_t
inet_totext(int af, isc_region_t *src, isc_buffer_t *target) {
char tmpbuf[64];
/* Note - inet_ntop doesn't do size checking on its input. */
if (inet_ntop(af, src->base, tmpbuf, sizeof(tmpbuf)) == NULL)
return (ISC_R_NOSPACE);
if (strlen(tmpbuf) > isc_buffer_availablelength(target))
return (ISC_R_NOSPACE);
isc_buffer_putstr(target, tmpbuf);
return (ISC_R_SUCCESS);
}
static isc_boolean_t
buffer_empty(isc_buffer_t *source) {
return((source->current == source->active) ? ISC_TRUE : ISC_FALSE);

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: a_1.c,v 1.21 2001/01/09 21:54:58 bwelling Exp $ */
/* $Id: a_1.c,v 1.22 2001/01/25 20:14:38 bwelling Exp $ */
/* reviewed: Thu Mar 16 15:58:36 PST 2000 by brister */
@@ -62,13 +62,8 @@ totext_hs_a(ARGS_TOTEXT) {
UNUSED(tctx);
isc_buffer_availableregion(target, &region);
if (inet_ntop(AF_INET, rdata->data,
(char *)region.base, region.length) == NULL)
return (ISC_R_NOSPACE);
isc_buffer_add(target, strlen((char *)region.base));
return (ISC_R_SUCCESS);
dns_rdata_toregion(rdata, &region);
return (inet_totext(AF_INET, &region, target));
}
static inline isc_result_t

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: a6_38.c,v 1.40 2001/01/09 21:55:00 bwelling Exp $ */
/* $Id: a6_38.c,v 1.41 2001/01/25 20:14:39 bwelling Exp $ */
/* draft-ietf-ipngwg-dns-lookups-03.txt */
@@ -86,8 +86,7 @@ fromtext_in_a6(ARGS_FROMTEXT) {
static inline isc_result_t
totext_in_a6(ARGS_TOTEXT) {
isc_region_t tr;
isc_region_t sr;
isc_region_t sr, ar;
unsigned char addr[16];
unsigned char prefixlen;
unsigned char octets;
@@ -115,12 +114,9 @@ totext_in_a6(ARGS_TOTEXT) {
memcpy(&addr[octets], sr.base, 16 - octets);
mask = 0xff >> (prefixlen % 8);
addr[octets] &= mask;
isc_buffer_availableregion(target, &tr);
if (inet_ntop(AF_INET6, addr,
(char *)tr.base, tr.length) == NULL)
return (ISC_R_NOSPACE);
isc_buffer_add(target, strlen((char *)tr.base));
ar.base = addr;
ar.length = sizeof(addr);
RETERR(inet_totext(AF_INET6, &ar, target));
isc_region_consume(&sr, 16 - octets);
}

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: a_1.c,v 1.42 2001/01/09 21:55:03 bwelling Exp $ */
/* $Id: a_1.c,v 1.43 2001/01/25 20:14:40 bwelling Exp $ */
/* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
@@ -64,13 +64,8 @@ totext_in_a(ARGS_TOTEXT) {
UNUSED(tctx);
isc_buffer_availableregion(target, &region);
if (inet_ntop(AF_INET, rdata->data,
(char *)region.base, region.length) == NULL)
return (ISC_R_NOSPACE);
isc_buffer_add(target, strlen((char *)region.base));
return (ISC_R_SUCCESS);
dns_rdata_toregion(rdata, &region);
return (inet_totext(AF_INET, &region, target));
}
static inline isc_result_t

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: aaaa_28.c,v 1.32 2001/01/09 21:55:05 bwelling Exp $ */
/* $Id: aaaa_28.c,v 1.33 2001/01/25 20:14:41 bwelling Exp $ */
/* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
@@ -64,13 +64,8 @@ totext_in_aaaa(ARGS_TOTEXT) {
REQUIRE(rdata->rdclass == 1);
REQUIRE(rdata->length == 16);
isc_buffer_availableregion(target, &region);
if (inet_ntop(AF_INET6, rdata->data,
(char *)region.base, region.length) == NULL)
return (ISC_R_NOSPACE);
isc_buffer_add(target, strlen((char *)region.base));
return (ISC_R_SUCCESS);
dns_rdata_toregion(rdata, &region);
return (inet_totext(AF_INET6, &region, target));
}
static inline isc_result_t

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: wks_11.c,v 1.39 2001/01/09 21:55:21 bwelling Exp $ */
/* $Id: wks_11.c,v 1.40 2001/01/25 20:14:42 bwelling Exp $ */
/* Reviewed: Fri Mar 17 15:01:49 PST 2000 by explorer */
@@ -137,7 +137,6 @@ fromtext_in_wks(ARGS_FROMTEXT) {
static inline isc_result_t
totext_in_wks(ARGS_TOTEXT) {
isc_region_t sr;
isc_region_t tr;
unsigned short proto;
char buf[sizeof "65535"];
unsigned int i, j;
@@ -146,13 +145,10 @@ totext_in_wks(ARGS_TOTEXT) {
REQUIRE(rdata->type == 11);
REQUIRE(rdata->rdclass == 1);
REQUIRE(rdata->length != 0);
REQUIRE(rdata->length >= 5);
dns_rdata_toregion(rdata, &sr);
isc_buffer_availableregion(target, &tr);
if (inet_ntop(AF_INET, sr.base, (char *)tr.base, tr.length) == NULL)
return (ISC_R_NOSPACE);
isc_buffer_add(target, strlen((char *)tr.base));
RETERR(inet_totext(AF_INET, &sr, target));
isc_region_consume(&sr, 4);
proto = uint8_fromregion(&sr);