diff --git a/lib/lwres/context.c b/lib/lwres/context.c index e67bab0379..cee1764e15 100644 --- a/lib/lwres/context.c +++ b/lib/lwres/context.c @@ -186,7 +186,8 @@ context_connect(lwres_context_t *ctx) int lwres_context_sendrecv(lwres_context_t *ctx, void *sendbase, int sendlen, - void *recvbase, int recvlen) + void *recvbase, int recvlen, + int *recvd_len) { int ret; struct sockaddr_in sin; @@ -214,5 +215,8 @@ lwres_context_sendrecv(lwres_context_t *ctx, || sin.sin_port != htons(LWRES_UDP_PORT)) goto again; - return (ret); + if (recvd_len != NULL) + *recvd_len = ret; + + return (LWRES_R_SUCCESS); } diff --git a/lib/lwres/include/lwres/context.h b/lib/lwres/include/lwres/context.h index 92a7c2740d..a0f41b37a6 100644 --- a/lib/lwres/include/lwres/context.h +++ b/lib/lwres/include/lwres/context.h @@ -80,7 +80,8 @@ lwres_context_allocmem(lwres_context_t *ctx, size_t len); int lwres_context_sendrecv(lwres_context_t *ctx, void *sendbase, int sendlen, - void *recvbase, int recvlen); + void *recvbase, int recvlen, + int *recvd_len); ISC_LANG_ENDDECLS diff --git a/lib/lwres/lwresutil.c b/lib/lwres/lwresutil.c index 14ca6964e0..0187ce889b 100644 --- a/lib/lwres/lwresutil.c +++ b/lib/lwres/lwresutil.c @@ -100,6 +100,7 @@ lwres_getaddrsbyname(lwres_context_t *ctx, const char *name, lwres_gabnrequest_t request; lwres_gabnresponse_t *response; int ret; + int recvlen; lwres_buffer_t b_in, b_out; lwres_lwpacket_t pkt; isc_uint32_t serial; @@ -127,6 +128,7 @@ lwres_getaddrsbyname(lwres_context_t *ctx, const char *name, */ request.addrtypes = addrtypes; request.name = (char *)name; + request.namelen = strlen(name); pkt.flags = 0; pkt.serial = serial; pkt.result = 0; @@ -134,15 +136,15 @@ lwres_getaddrsbyname(lwres_context_t *ctx, const char *name, again: ret = lwres_gabnrequest_render(ctx, &request, &pkt, &b_out); - if (ret != 0) + if (ret != LWRES_R_SUCCESS) goto out; ret = lwres_context_sendrecv(ctx, b_out.base, b_out.length, buffer, - LWRES_RECVLENGTH); - if (ret < 0) + LWRES_RECVLENGTH, &recvlen); + if (ret != LWRES_R_SUCCESS) goto out; - lwres_buffer_init(&b_in, buffer, ret); + lwres_buffer_init(&b_in, buffer, recvlen); /* * Parse the packet header. @@ -199,6 +201,7 @@ lwres_getnamebyaddr(lwres_context_t *ctx, isc_uint32_t addrtype, lwres_gnbarequest_t request; lwres_gnbaresponse_t *response; int ret; + int recvlen; lwres_buffer_t b_in, b_out; lwres_lwpacket_t pkt; isc_uint32_t serial; @@ -239,11 +242,11 @@ lwres_getnamebyaddr(lwres_context_t *ctx, isc_uint32_t addrtype, goto out; ret = lwres_context_sendrecv(ctx, b_out.base, b_out.length, buffer, - LWRES_RECVLENGTH); - if (ret < 0) + LWRES_RECVLENGTH, &recvlen); + if (ret != LWRES_R_SUCCESS) goto out; - lwres_buffer_init(&b_in, buffer, ret); + lwres_buffer_init(&b_in, buffer, recvlen); /* * Parse the packet header.