Fixed modelines.
[iolib.git] / net.sockets / dns / common.lisp
blobfb814a154410ca32fb12ee68d18fbfc173af6bc4
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; common.lisp --- DNS client constants.
4 ;;;
5 ;;; Copyright (C) 2006-2008, Stelian Ionescu <sionescu@common-lisp.net>
6 ;;;
7 ;;; This code is free software; you can redistribute it and/or
8 ;;; modify it under the terms of the version 2.1 of
9 ;;; the GNU Lesser General Public License as published by
10 ;;; the Free Software Foundation, as clarified by the
11 ;;; preamble found here:
12 ;;; http://opensource.franz.com/preamble.html
13 ;;;
14 ;;; This program is distributed in the hope that it will be useful,
15 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU Lesser General
20 ;;; Public License along with this library; if not, write to the
21 ;;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 ;;; Boston, MA 02110-1301, USA
24 (in-package :net.sockets)
26 (defconstant +dns-max-datagram-size+ 4096)
28 (defconstant +opcode-standard+ 0)
30 ;;; Query types
32 (define-constant +query-type-to-value-map+
33 #h:eq{:a => 1 , :ns => 2 , :cname => 5 , :soa => 6 ,
34 :wks => 11 , :ptr => 12 , :hinfo => 13 , :mx => 15 ,
35 :txt => 16 , :aaaa => 28 , :any => 255}
36 :test #'equalp)
38 (define-constant +query-value-to-type-map+
39 #h{1 => :a , 2 => :ns , 5 => :cname , 6 => :soa ,
40 11 => :wks , 12 => :ptr , 13 => :hinfo , 15 => :mx ,
41 16 => :txt , 28 => :aaaa , 255 => :any}
42 :test #'equalp)
44 (defun query-type-number (id)
45 (gethash id +query-type-to-value-map+))
47 (defun query-type-id (number)
48 (gethash number +query-value-to-type-map+))
50 (defun dns-record-type-p (id)
51 (query-type-number id))
53 ;;; Query classes
55 (define-constant +query-class-to-value-map+
56 #h:eq{:in => 1 , :any => 255}
57 :test #'equalp)
59 (define-constant +query-value-to-class-map+
60 #h{1 => :in , 255 => :any}
61 :test #'equalp)
63 (defun query-class-number (id)
64 (gethash id +query-class-to-value-map+))
66 (defun query-class-id (number)
67 (gethash number +query-value-to-class-map+))
69 ;;; Error codes
71 (define-constant +rcode-to-value-map+
72 #h:eq{:no-error => 0 , :format-error => 1 ,
73 :server-failure => 2 , :name-error => 3 ,
74 :not-implemented => 4 , :refused => 5}
75 :test #'equalp)
77 (define-constant +value-to-rcode-map+
78 #h{0 => :no-error , 1 => :format-error ,
79 2 => :server-failure , 3 => :name-error ,
80 4 => :not-implemented , 5 => :refused}
81 :test #'equalp)
83 (defun rcode-number (id)
84 (gethash id +rcode-to-value-map+))
86 (defun rcode-id (number)
87 (gethash number +value-to-rcode-map+))