getrrset.c revision 1200b067851fd29777e1154c41e85b9b041447bd
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2000 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence * purpose with or without fee is hereby granted, provided that the above
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40e7c805a8f38ad9b20dd6c688496fc09fc971c2Mark Andrews/* $Id: getrrset.c,v 1.5 2000/12/21 00:27:53 bwelling Exp $ */
73d62a89f1493865c33c689b3ee3de91c74ad58eDavid Lawrence#include <lwres/netdb.h> /* XXX #include <netdb.h> */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencestatic unsigned int
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence case LWRES_R_SUCCESS: return (ERRSET_SUCCESS);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence case LWRES_R_NOMEMORY: return (ERRSET_NOMEMORY);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence default: return (ERRSET_FAIL);
b65f2ab14abb4b6ef906d7d02064fba158f07b1eDavid Lawrence * malloc / calloc functions that guarantee to only
b65f2ab14abb4b6ef906d7d02064fba158f07b1eDavid Lawrence * return NULL if there is an error, like they used
b65f2ab14abb4b6ef906d7d02064fba158f07b1eDavid Lawrence * to before the ANSI C committee broke them.
1630fce031f7a3e33f0579e477a3e17d1993e1f9Bob Halleystatic void *
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrencelwres_getrrsetbyname(const char *hostname, unsigned int rdclass,
b65f2ab14abb4b6ef906d7d02064fba158f07b1eDavid Lawrence unsigned int i;
cec7a04adc665a8c1029be008fd97c018c12c1b3David Lawrence unsigned int result;
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence * Don't allow queries of class or type ANY
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence lwresult = lwres_context_create(&lwrctx, NULL, NULL, NULL, 0);
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence (void) lwres_conf_parse(lwrctx, lwres_resolv_conf);
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence * If any input flags were defined, lwflags would be set here
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence * based on them
0f5962ac3e4ef336faff68f1cb838505e64665e5David Lawrence lwresult = lwres_getrdatabyname(lwrctx, hostname, rdclass, rdtype,
b65f2ab14abb4b6ef906d7d02064fba158f07b1eDavid Lawrence rrset = sane_malloc(sizeof(struct rrsetinfo));
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence rrset->rri_name = sane_malloc(response->realnamelen + 1);
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence strncpy(rrset->rri_name, response->realname, response->realnamelen);
7554feaef6057f5ea2926076900ac7634b911456Mark Andrews if ((response->flags & LWRDATA_VALIDATED) != 0)
7554feaef6057f5ea2926076900ac7634b911456Mark Andrews rrset->rri_rdatas = sane_calloc(rrset->rri_nrdatas,
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence sizeof(struct rdatainfo));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence rrset->rri_rdatas[i].rdi_length = response->rdatalen[i];
bd1190c84b08e61a12789c54f083318c36449e5eDavid Lawrence sane_malloc(rrset->rri_rdatas[i].rdi_length);
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence memcpy(rrset->rri_rdatas[i].rdi_data, response->rdatas[i],
401fc772b1bf058a981e3c474fa6502f6ee0e2bfDavid Lawrence rrset->rri_sigs = sane_calloc(rrset->rri_nsigs,
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence sizeof(struct rdatainfo));
b65f2ab14abb4b6ef906d7d02064fba158f07b1eDavid Lawrence rrset->rri_sigs[i].rdi_length = response->siglen[i];
b65f2ab14abb4b6ef906d7d02064fba158f07b1eDavid Lawrence memcpy(rrset->rri_sigs[i].rdi_data, response->sigs[i],
092b4e5359c5982a438e36ced3dbefc313f7fbfcDavid Lawrence unsigned int i;