01: /* VirtualDNS - A modular DNS server.
02: * Copyright (C) 2000 Eric Kidd
03: * Copyright (C) 1999 Brian Wellington
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package CustomDNS.VirtualDNS;
21:
22: import java.io.*;
23: import org.xbill.DNS.*;
24: import org.xbill.DNS.utils.*;
25:
26: /*************************************************************************
27: * Routines for creating different kinds of DNS error responses.
28: *************************************************************************
29: * This code was adapted from Brian Wellington's jnamed code.
30: * @see org.xbill.DNS.Message
31: */
32:
33: public class ErrorMessages {
34:
35: /*********************************************************************
36: * Create a format error message (FORMERR).
37: *********************************************************************
38: * @param in The malformed packet.
39: * @return A DNS error message.
40: */
41: public static Message makeFormatErrorMessage(byte[] in) {
42: Header header;
43: try {
44: header = new Header(new DataByteInputStream(in));
45: } catch (IOException e) {
46: header = new Header(0);
47: }
48: Message response = new Message();
49: response.setHeader(header);
50: for (int i = 0; i < 4; i++)
51: response.removeAllRecords(i);
52: header.setRcode(Rcode.FORMERR);
53: return response;
54: }
55:
56: /*********************************************************************
57: * Create an arbitrary DNS error message.
58: *********************************************************************
59: * @param query The query sent by the user.
60: * @param rcode The response code to use for this error.
61: * @return A DNS error message.
62: * @see org.xbill.DNS.Rcode
63: */
64: public static Message makeErrorMessage(Message query, short rcode) {
65: Header header = query.getHeader();
66: Message response = new Message();
67: response.setHeader(header);
68: for (int i = 0; i < 4; i++)
69: response.removeAllRecords(i);
70: header.setRcode(rcode);
71: return response;
72: }
73: }
|