~ubuntu-branches/ubuntu/karmic/pdnsd/karmic

« back to all changes in this revision

Viewing changes to src/dns.h

  • Committer: Bazaar Package Importer
  • Author(s): Takuo KITAME
  • Date: 2002-04-07 02:30:11 UTC
  • Revision ID: james.westby@ubuntu.com-20020407023011-6zzd1y8a8tk5fz97
Tags: upstream-1.1.7
ImportĀ upstreamĀ versionĀ 1.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* dns.h - Declarations for dns handling and generic dns functions
 
2
   Copyright (C) 2000, 2001 Thomas Moestl
 
3
 
 
4
This file is part of the pdnsd package.
 
5
 
 
6
pdnsd is free software; you can redistribute it and/or modify
 
7
it under the terms of the GNU General Public License as published by
 
8
the Free Software Foundation; either version 2, or (at your option)
 
9
any later version.
 
10
 
 
11
pdnsd is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with pdsnd; see the file COPYING.  If not, write to
 
18
the Free Software Foundation, 59 Temple Place - Suite 330,
 
19
Boston, MA 02111-1307, USA.  */
 
20
 
 
21
/* $Id: dns.h,v 1.14 2002/01/01 23:54:49 tmm Exp $ */
 
22
 
 
23
#ifndef DNS_H
 
24
#define DNS_H
 
25
 
 
26
#include <config.h>
 
27
#include <arpa/inet.h>
 
28
#include <net/if.h>
 
29
#include <sys/types.h>
 
30
#include <inttypes.h>
 
31
#include "rr_types.h"
 
32
#include "list.h"
 
33
 
 
34
/* Deal with byte orders */
 
35
#ifndef BYTE_ORDER
 
36
# define LITTLE_ENDIAN __LITTLE_ENDIAN
 
37
# define BIG_ENDIAN __BIG_ENDIAN
 
38
# ifdef __BYTE_ORDER
 
39
#  define BYTE_ORDER __BYTE_ORDER
 
40
# else
 
41
#  ifdef __LITTLE_ENDIAN
 
42
#   define BYTE_ORDER __LITTLE_ENDIAN
 
43
#  endif
 
44
#  ifdef __BIG_ENDIAN
 
45
#   define BYTE_ORDER __LITTLE_ENDIAN
 
46
#  endif
 
47
# endif
 
48
#endif
 
49
 
 
50
/* special rr type codes for queries */
 
51
#define QT_MIN    251
 
52
#define QT_IXFR   251
 
53
#define QT_AXFR   252
 
54
#define QT_MAILB  253
 
55
#define QT_MAILA  254
 
56
#define QT_ALL    255
 
57
#define QT_MAX    255
 
58
#define QT_NUM      5
 
59
 
 
60
/* rr classes */
 
61
#define C_MIN       1
 
62
#define C_IN        1
 
63
#define C_CS        2
 
64
#define C_CH        3
 
65
#define C_HS        4
 
66
#define C_MAX       4
 
67
#define C_NUM       4
 
68
 
 
69
/* special classes for queries */
 
70
#define QC_ALL    255
 
71
 
 
72
/* status codes */
 
73
#define RC_OK       0
 
74
#define RC_FORMAT   1
 
75
#define RC_SERVFAIL 2
 
76
#define RC_NAMEERR  3
 
77
#define RC_NOTSUPP  4
 
78
#define RC_REFUSED  5
 
79
 
 
80
/*
 
81
 * special internal retvals
 
82
 */
 
83
#define RC_TCPREFUSED 254
 
84
#define RC_TRUNC      255
 
85
 
 
86
/* query/response */
 
87
#define QR_QUERY    0
 
88
#define QR_RESP     1
 
89
 
 
90
/*opcodes */
 
91
#define OP_QUERY    0
 
92
#define OP_IQUERY   1
 
93
#define OP_STATUS   2
 
94
 
 
95
 
 
96
/* rfc2181 details that the ttl is a 32-bit integer, where the most significant bit is always 0.
 
97
 * for convenience and Unix compatablility we use a uint32_t, which satisfies these conditions if 
 
98
 * positive (which is ensured in the code) */
 
99
typedef struct {
 
100
        /* the name is the first field. It has variable length, so it can't be put in the struct */
 
101
        uint16_t type      __attribute__((packed));
 
102
        uint16_t class     __attribute__((packed)); 
 
103
        uint32_t ttl       __attribute__((packed));
 
104
        uint16_t rdlength  __attribute__((packed));
 
105
        /* rdata follows */
 
106
} rr_hdr_t;
 
107
 
 
108
typedef struct {
 
109
        /* The server name and maintainer mailbox are the first two fields. It has variable length, */
 
110
        /* so they can't be put in the struct */
 
111
        uint32_t serial    __attribute__((packed));
 
112
        uint32_t refresh   __attribute__((packed));
 
113
        uint32_t retry     __attribute__((packed));
 
114
        uint32_t expire    __attribute__((packed));
 
115
        uint32_t minimum   __attribute__((packed));
 
116
} soa_r_t;
 
117
 
 
118
 
 
119
typedef struct {
 
120
/*      char           qname[];*/
 
121
        uint16_t qtype     __attribute__((packed));
 
122
        uint16_t qclass    __attribute__((packed));
 
123
} std_query_t;
 
124
 
 
125
typedef struct {
 
126
        uint16_t id        __attribute__((packed));
 
127
#if __BYTE_ORDER == __LITTLE_ENDIAN
 
128
        unsigned int   rd:1;
 
129
        unsigned int   tc:1;
 
130
        unsigned int   aa:1;
 
131
        unsigned int   opcode:4;
 
132
        unsigned int   qr:1;
 
133
        unsigned int   rcode:4;
 
134
        unsigned int   z1:1;
 
135
        unsigned int   au:1;
 
136
        unsigned int   z2:1;
 
137
        unsigned int   ra:1;
 
138
#elif __BYTE_ORDER == __BIG_ENDIAN
 
139
        unsigned int   qr:1;
 
140
        unsigned int   opcode:4;
 
141
        unsigned int   aa:1;
 
142
        unsigned int   tc:1;
 
143
        unsigned int   rd:1;
 
144
        unsigned int   ra:1;
 
145
        unsigned int   z2:1;
 
146
        unsigned int   au:1;
 
147
        unsigned int   z1:1;
 
148
        unsigned int   rcode:4;
 
149
#else
 
150
# error "Please define __BYTE_ORDER to be __LITTLE_ENDIAN or __BIG_ENDIAN"
 
151
#endif
 
152
        uint16_t qdcount   __attribute__((packed));
 
153
        uint16_t ancount   __attribute__((packed));
 
154
        uint16_t nscount   __attribute__((packed));
 
155
        uint16_t arcount   __attribute__((packed));
 
156
} dns_hdr_t;
 
157
 
 
158
/* Recursion depth. */
 
159
#define MAX_HOPS 20
 
160
 
 
161
/*
 
162
 * Types for compression buffers.
 
163
 */
 
164
typedef struct {
 
165
        int           index;
 
166
        unsigned char s[256];
 
167
} compel_t;
 
168
 
 
169
int decompress_name(unsigned char *msg, unsigned char *tgt, unsigned char **src, long *sz, long msgsz, int *len, int *uscore);
 
170
int domain_match(int *o, unsigned char *ms, unsigned char *md, unsigned char *rest);
 
171
int compress_name(unsigned char *in, unsigned char *out, int offs, darray *cb);
 
172
 
 
173
int read_hosts(char *fn, unsigned char *rns, time_t ttl, int flags, int aliases, char *errbuf, int errsize);
 
174
 
 
175
#if DEBUG>0 
 
176
char *get_cname(int id);
 
177
char *get_tname(int id);
 
178
char *get_ename(int id);
 
179
#endif
 
180
 
 
181
#endif