simple code (DDNS)

Roman Mashak romez777 at gmail.com
Sat Mar 4 02:40:36 UTC 2006


Hello.

I tried to implement simple function for DNS updates (to understand
better internals of Bind and Co.). I used code from 'nsupdate.c' and
simplified a bit. I thought I left the most important core, seems like
I missed something cause it doesn't work as it's supposed to do:

<skip headers>

int dns_update(unsigned char *r_dname,int r_opcode,short int r_type,
		unsigned int r_ttl,int r_size,unsigned char *r_data) {


	int r_section;
	short int r_class;
	ns_updrec *rrecp;

	r_section=S_UPDATE;
	r_class=C_IN;
	
	if ( !(rrecp = res_mkupdrec(r_section, r_dname, r_class,
             r_type, r_ttl)) || (r_size > 0 &&
             !(rrecp->r_data = (u_char *)malloc(r_size))))

		return(0);
	
	rrecp->r_opcode=r_opcode;
	rrecp->r_size=r_size;
	if(r_size>0) strcpy(rrecp->r_data,r_data);

#if !defined(BIND821) && !defined(__FreeBSD__)
	rrecp->r_link.prev=NULL;
	rrecp->r_link.next=NULL;
#else
	rrecp->r_prev=NULL;
	rrecp->r_next=NULL;
#endif
	
	res_update(rrecp);
	if(rrecp->r_size) free(rrecp->r_data);
	free(rrecp);
	return(1);
}

int main(int argc, char *argv[])
{
	unsigned char str[128];

	if (argc < 2)
		return -1;

	sprintf(str, "%s", argv[1]);
	dns_update(str,DELETE,T_A,0,0,"");
	dns_update(str,ADD,T_A,DYN_TTL,strlen(str),str);

	return 0;
}

#gcc -Wall -I/ext/mrv/my_local/usr/local/bind/include
-L/ext/mrv/my_local/usr/local/bind/lib -g -o ddns ddns.c -lbind

I tried to compile it with Bind8 and Bind9 libraries, succedded but I
updates are not processed, and no records in llog file at all. Where
has the problem hidden?

Thanks in advance.

--
Roman



More information about the bind-users mailing list