Commit 4ed0c326 authored by Andreas Gustafsson's avatar Andreas Gustafsson
Browse files

isc_sockaddr_totext() now writes to an isc_buf_t, not

a dynamically allocated string
parent 63bb6b85
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: zone.c,v 1.32 1999/10/29 08:37:50 marka Exp $ */
/* $Id: zone.c,v 1.33 1999/10/29 23:46:27 gson Exp $ */
#include <config.h>
......@@ -855,7 +855,6 @@ checkservers_callback(isc_task_t *task, isc_event_t *event) {
isc_sockaddr_t *address;
dns_resolver_t *res;
dns_message_t *msg;
char *master;
REQUIRE(DNS_CHECKSERVERS_VALID(checkservers));
state = checkservers->state;
......@@ -867,9 +866,6 @@ checkservers_callback(isc_task_t *task, isc_event_t *event) {
task = task; /* unused */
master = isc_sockaddr_totext(&zone->masters[zone->curmaster],
zone->mctx);
if (devent->result != DNS_R_SUCCESS) {
/* timeout */
switch (state) {
......@@ -1931,7 +1927,8 @@ refresh_callback(isc_task_t *task, isc_event_t *event) {
isc_uint32_t soacnt, cnamecnt, soacount, nscount;
isc_stdtime_t now;
char *master;
char *unknown = "<UNKNOWN>";
isc_buffer_t masterbuf;
char mastermem[256];
dns_rdataset_t *rdataset;
dns_rdata_t rdata;
dns_rdata_soa_t soa;
......@@ -1945,11 +1942,15 @@ refresh_callback(isc_task_t *task, isc_event_t *event) {
* if timeout log and next master;
*/
master = isc_sockaddr_totext(&zone->masters[zone->curmaster],
zone->mctx);
if (master == NULL)
master = unknown;
isc_buffer_init(&masterbuf, mastermem, sizeof(mastermem),
ISC_BUFFERTYPE_TEXT);
result = isc_sockaddr_totext(&zone->masters[zone->curmaster],
&masterbuf);
if (result == ISC_R_SUCCESS)
master = (char *) buf->base;
else
master = "<UNKNOWN>";
if (devent->result != DNS_R_SUCCESS) {
dns_zone_logerror(zone, "refresh: failure for %s: %s",
master, dns_result_totext(devent->result));
......@@ -2059,8 +2060,6 @@ refresh_callback(isc_task_t *task, isc_event_t *event) {
} else {
goto next_master;
}
if (master != unknown)
isc_mem_put(zone->mctx, master, strlen(master) + 1);
return;
next_master:
......
......@@ -18,6 +18,7 @@
#ifndef ISC_SOCKADDR_H
#define ISC_SOCKADDR_H 1
#include <isc/buffer.h>
#include <isc/net.h>
#include <isc/list.h>
#include <isc/lang.h>
......@@ -70,8 +71,17 @@ isc_sockaddr_pf(const isc_sockaddr_t *sockaddr);
* The protocol family of 'sockaddr', e.g. PF_INET or PF_INET6.
*/
char *
isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_mem_t *mctx);
isc_result_t
isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target);
/*
* Append a text representation of 'sockaddr' to the buffer 'target'.
* The text will include both the IP address (v4 or v6) and the port.
* The text is not null terminated.
*
* Returns:
* ISC_R_SUCCESS
* ISC_R_NOSPACE The text did not fit.
*/
ISC_LANG_ENDDECLS
......
......@@ -102,14 +102,16 @@ isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b)
return (ISC_TRUE);
}
char *
isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_mem_t *mctx) {
isc_result_t
isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) {
char abuf[sizeof "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255"];
unsigned int alen;
char pbuf[sizeof "65000"];
unsigned int plen;
isc_region_t avail;
const struct sockaddr *sa;
const struct sockaddr_in *sin;
const struct sockaddr_in6 *sin6;
char *res;
REQUIRE(sockaddr != NULL);
......@@ -128,13 +130,19 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_mem_t *mctx) {
default:
return (NULL);
}
res = isc_mem_get(mctx, strlen(abuf) + strlen(pbuf) + 2);
if (res == NULL)
return (NULL);
strcpy(res, abuf);
strcat(res, "#");
strcat(res, pbuf);
return (res);
alen = strlen(abuf);
plen = strlen(pbuf);
isc_buffer_available(target, &avail);
if (alen + 1 + plen < avail.length)
return (ISC_R_NOSPACE);
isc_buffer_putmem(target, abuf, alen);
isc_buffer_putmem(target, "#", 1);
isc_buffer_putmem(target, pbuf, plen);
return (ISC_R_SUCCESS);
}
unsigned int
......
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