lib/dns/masterdump.c
/*
 * Dump given RRsets in the "raw" format.
 */
Dump given RRsets in the "raw" format.
Dump given RRsets in the " raw " format .
static isc_result_t
dump_rdataset_raw(isc_mem_t *mctx, dns_name_t *name, dns_rdataset_t *rdataset,
		  isc_buffer_t *buffer, FILE *f)
{
	isc_result_t result;
	isc_uint32_t totallen;
	isc_uint16_t dlen;
	isc_region_t r, r_hdr;
	REQUIRE(buffer->length > 0);
	REQUIRE(DNS_RDATASET_VALID(rdataset));
 restart:
	totallen = 0;
	result = dns_rdataset_first(rdataset);
	REQUIRE(result == ISC_R_SUCCESS);
	isc_buffer_clear(buffer);
	isc_buffer_availableregion(buffer, &r_hdr);
	INSIST(r_hdr.length >= sizeof(dns_masterrawrdataset_t));
	isc_buffer_putuint32(buffer, totallen);	
	isc_buffer_putuint16(buffer, rdataset->rdclass); 
	isc_buffer_putuint16(buffer, rdataset->type); 
	isc_buffer_putuint16(buffer, rdataset->covers);	
	isc_buffer_putuint32(buffer, rdataset->ttl); 
	isc_buffer_putuint32(buffer, dns_rdataset_count(rdataset));
	totallen = isc_buffer_usedlength(buffer);
	INSIST(totallen <= sizeof(dns_masterrawrdataset_t));
	dns_name_toregion(name, &r);
	INSIST(isc_buffer_availablelength(buffer) >=
	       (sizeof(dlen) + r.length));
	dlen = (isc_uint16_t)r.length;
	isc_buffer_putuint16(buffer, dlen);
	isc_buffer_copyregion(buffer, &r);
	totallen += sizeof(dlen) + r.length;
	do {
		dns_rdata_t rdata = DNS_RDATA_INIT;
		isc_region_t r;
		dns_rdataset_current(rdataset, &rdata);
		dns_rdata_toregion(&rdata, &r);
		INSIST(r.length <= 0xffffU);
		dlen = (isc_uint16_t)r.length;
		if (isc_buffer_availablelength(buffer) <
						 sizeof(dlen) + r.length) {
			int newlength;
			void *newmem;
			newlength = buffer->length * 2;
			newmem = isc_mem_get(mctx, newlength);
			if (newmem == NULL)
				return (ISC_R_NOMEMORY);
			isc_mem_put(mctx, buffer->base, buffer->length);
			isc_buffer_init(buffer, newmem, newlength);
			goto restart;
		}
		isc_buffer_putuint16(buffer, dlen);
		isc_buffer_copyregion(buffer, &r);
		totallen += sizeof(dlen) + r.length;
		result = dns_rdataset_next(rdataset);
	} while (result == ISC_R_SUCCESS);
	if (result != ISC_R_NOMORE)
		return (result);
	isc_buffer_usedregion(buffer, &r);
	isc_buffer_clear(buffer);
	isc_buffer_putuint32(buffer, totallen);
	INSIST(isc_buffer_usedlength(buffer) < totallen);
	result = isc_stdio_write(r.base, 1, (size_t)r.length, f, NULL);
	if (result != ISC_R_SUCCESS) {
		UNEXPECTED_ERROR(__FILE__, __LINE__,
				 "raw master file write failed: %s",
				 isc_result_totext(result));
		return (result);
	}
	return (result);
}
static isc_result_t dump_rdataset_raw ( isc_mem_t * mctx , dns_name_t * name , dns_rdataset_t * rdataset , isc_buffer_t * buffer , FILE * f ) { isc_result_t result ; isc_uint32_t totallen ; isc_uint16_t dlen ; isc_region_t r , r_hdr ; REQUIRE ( buffer -> length > 0 ) ; REQUIRE ( DNS_RDATASET_VALID ( rdataset ) ) ; restart : totallen = 0 ; result = dns_rdataset_first ( rdataset ) ; REQUIRE ( result == ISC_R_SUCCESS ) ; isc_buffer_clear ( buffer ) ; isc_buffer_availableregion ( buffer , & r_hdr ) ; INSIST ( r_hdr . length >= sizeof ( dns_masterrawrdataset_t ) ) ; isc_buffer_putuint32 ( buffer , totallen ) ; isc_buffer_putuint16 ( buffer , rdataset -> rdclass ) ; isc_buffer_putuint16 ( buffer , rdataset -> type ) ; isc_buffer_putuint16 ( buffer , rdataset -> covers ) ; isc_buffer_putuint32 ( buffer , rdataset -> ttl ) ; isc_buffer_putuint32 ( buffer , dns_rdataset_count ( rdataset ) ) ; totallen = isc_buffer_usedlength ( buffer ) ; INSIST ( totallen <= sizeof ( dns_masterrawrdataset_t ) ) ; dns_name_toregion ( name , & r ) ; INSIST ( isc_buffer_availablelength ( buffer ) >= ( sizeof ( dlen ) + r . length ) ) ; dlen = ( isc_uint16_t ) r . length ; isc_buffer_putuint16 ( buffer , dlen ) ; isc_buffer_copyregion ( buffer , & r ) ; totallen += sizeof ( dlen ) + r . length ; do { dns_rdata_t rdata = DNS_RDATA_INIT ; isc_region_t r ; dns_rdataset_current ( rdataset , & rdata ) ; dns_rdata_toregion ( & rdata , & r ) ; INSIST ( r . length <= 0xffffU ) ; dlen = ( isc_uint16_t ) r . length ; if ( isc_buffer_availablelength ( buffer ) < sizeof ( dlen ) + r . length ) { int newlength ; void * newmem ; newlength = buffer -> length * 2 ; newmem = isc_mem_get ( mctx , newlength ) ; if ( newmem == NULL ) return ( ISC_R_NOMEMORY ) ; isc_mem_put ( mctx , buffer -> base , buffer -> length ) ; isc_buffer_init ( buffer , newmem , newlength ) ; goto restart ; } isc_buffer_putuint16 ( buffer , dlen ) ; isc_buffer_copyregion ( buffer , & r ) ; totallen += sizeof ( dlen ) + r . length ; result = dns_rdataset_next ( rdataset ) ; } while ( result == ISC_R_SUCCESS ) ; if ( result != ISC_R_NOMORE ) return ( result ) ; isc_buffer_usedregion ( buffer , & r ) ; isc_buffer_clear ( buffer ) ; isc_buffer_putuint32 ( buffer , totallen ) ; INSIST ( isc_buffer_usedlength ( buffer ) < totallen ) ; result = isc_stdio_write ( r . base , 1 , ( size_t ) r . length , f , NULL ) ; if ( result != ISC_R_SUCCESS ) { UNEXPECTED_ERROR ( __FILE__ , __LINE__ , " " , isc_result_totext ( result ) ) ; return ( result ) ; } return ( result ) ; }
Dump given RRsets in the "raw" format.
Dump given RRsets in the " raw " format .
/*
	 * Common header and owner name (length followed by name)
	 * These fields should be in a moderate length, so we assume we
	 * can store all of them in the initial buffer.
	 */ /* XXX: leave space */ /* 16-bit class */ /* 16-bit type */ /* same as type */ /* 32-bit TTL */ /*
		 * Copy the rdata into the buffer.  If the buffer is too small,
		 * grow it.  This should be rare, so we'll simply restart the
		 * entire procedure (or should we copy the old data and
		 * continue?).
		 */ /*
	 * Fill in the total length field.
	 * XXX: this is a bit tricky.  Since we have already "used" the space
	 * for the total length in the buffer, we first remember the entire
	 * buffer length in the region, "rewind", and then write the value.
	 */ /*
	 * Write the buffer contents to the raw master file.
	 */