summaryrefslogtreecommitdiffabout
path: root/lib/dns.h
blob: b2884b059b47160e6dd1f285716e8d7844bd164f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* This file is part of Mailfromd.
   Copyright (C) 2005-2008, 2010-2011, 2015-2017 Sergey Poznyakoff

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef __mfd_dns_h
#define __mfd_dns_h

typedef enum {
	dns_success,
	dns_not_found,
	dns_failure,
	dns_temp_failure,
} dns_status;

#define NELEMS(c) (sizeof(c)/sizeof((c)[0]))

/* Libresolv-related defines and DNS functions */
#ifndef MAXPACKET
# define MAXPACKET 8192	/* max packet size used internally by BIND */
#endif 

#define MAXMXCOUNT 32

#define MXF_MAX   0x01
#define MXF_REUSE 0x02

struct mxbuf {
	int mx_flags;
	size_t mx_max;
	char **mx_buf;
	size_t mx_cnt;
};
	
#define MAXCNAMEDEPTH 24 /* FIXME */

#ifdef HAVE_PTHREAD
# define MUTEX_DCL(name) \
 static pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER;
# define MUTEX_LOCK(name) \
 pthread_mutex_lock(&name)
# define MUTEX_UNLOCK(name) \
 pthread_mutex_unlock(&name);
#else
# define MUTEX_DCL(name)
# define MUTEX_LOCK(name)
# define MUTEX_UNLOCK(name)
#endif

#if !defined res_ninit && !defined HAVE_RES_NINIT
# define res_ninit(s)
#endif

#if !defined res_nclose && !defined HAVE_RES_NCLOSE
# define res_nclose(s)
#endif

#if !defined res_nquery && !defined HAVE_RES_NQUERY
# define res_nquery(stat,name,class,type,answer,anslen) \
 res_query(name,class,type,answer,anslen)
#endif

#if !defined res_nquerydomain && !defined HAVE_RES_NQUERYDOMAIN
# define res_nquerydomain(stat,name,domain,class,type,answer,anslen) \
 res_querydomain(name,domain,class,type,answer,anslen)
#endif

#define UPDATE_TTL(m, ttl) do { if ((m) > (ttl)) (m) = (ttl); } while(0)

void mxbuf_init(struct mxbuf *mxbuf);
void mxbuf_free(struct mxbuf *mxbuf);

int dns_str_is_ipv4(const char *addr);
dns_status dns_get_mx_records(const char *host, int maxdepth,
			      struct mxbuf *mxbuf, unsigned long *ttl);

int dns_reverse_ipstr(const char *ipstr, char *revipstr);

dns_status dns_resolve_ipstr(const char *ipstr, const char *domain,
			     unsigned char *answer, size_t answer_size,
			     char *hbuf, size_t hbsize, unsigned long *ttl);

dns_status dns_resolve_hostname(const char *host,
				unsigned char *answer, size_t answer_size,
				char *ipbuf, size_t ipbsize,
				unsigned long *ttl);
dns_status a_lookup(const char *host, 
		    GACOPYZ_UINT32_T *ipbuf, size_t ipbsize, size_t *ipcount,
		    unsigned long *ttl,
		    unsigned char *answer, size_t answer_size);

dns_status ptr_lookup(struct in_addr ip,
		      char **names, size_t maxnames, unsigned long *ttl,
		      unsigned char *answer, size_t answer_size);
dns_status txt_lookup(const char *name,
		      char **names, size_t maxnames, unsigned long *ttl,
		      unsigned char *answer, size_t answer_size);

dns_status ptr_validate(const char *ipstr, char ***vnptr, size_t *vcount,
			unsigned long *pttl);
	
#endif

Return to:

Send suggestions and report system problems to the System administrator.