Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / bin / named / lwderror.c
blob6a4c15b5e3fbf08c6db5ad39777969b153653412
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: lwderror.c,v 1.7.2.1 2004/03/09 06:09:18 marka Exp $ */
20 #include <config.h>
22 #include <isc/socket.h>
23 #include <isc/util.h>
25 #include <named/types.h>
26 #include <named/lwdclient.h>
29 * Generate an error packet for the client, schedule a send, and put us in
30 * the SEND state.
32 * The client->pkt structure will be modified to form an error return.
33 * The receiver needs to verify that it is in fact an error, and do the
34 * right thing with it. The opcode will be unchanged. The result needs
35 * to be set before calling this function.
37 * The only change this code makes is to set the receive buffer size to the
38 * size we use, set the reply bit, and recompute any security information.
40 void
41 ns_lwdclient_errorpktsend(ns_lwdclient_t *client, isc_uint32_t _result) {
42 isc_result_t result;
43 int lwres;
44 isc_region_t r;
45 lwres_buffer_t b;
47 REQUIRE(NS_LWDCLIENT_ISRUNNING(client));
50 * Since we are only sending the packet header, we can safely toss
51 * the receive buffer. This means we won't need to allocate space
52 * for sending an error reply. This is a Good Thing.
54 client->pkt.length = LWRES_LWPACKET_LENGTH;
55 client->pkt.pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
56 client->pkt.recvlength = LWRES_RECVLENGTH;
57 client->pkt.authtype = 0; /* XXXMLG */
58 client->pkt.authlength = 0;
59 client->pkt.result = _result;
61 lwres_buffer_init(&b, client->buffer, LWRES_RECVLENGTH);
62 lwres = lwres_lwpacket_renderheader(&b, &client->pkt);
63 if (lwres != LWRES_R_SUCCESS) {
64 ns_lwdclient_stateidle(client);
65 return;
68 r.base = client->buffer;
69 r.length = b.used;
70 client->sendbuf = client->buffer;
71 result = ns_lwdclient_sendreply(client, &r);
72 if (result != ISC_R_SUCCESS) {
73 ns_lwdclient_stateidle(client);
74 return;
77 NS_LWDCLIENT_SETSEND(client);