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