aboutsummaryrefslogtreecommitdiff
path: root/lib/dns.h
blob: 000c6da85dcb7eaeedffd8e8e306819ae3d1a69f (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* 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 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, size_t n);
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, unsigned long *ttl);

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

struct dns_reply {
	size_t count;
	size_t max;
	
	void **base;
	size_t last_len;
	size_t last_max;
};

void dns_reply_free(struct dns_reply *r);

static inline GACOPYZ_UINT32_T
dns_reply_ip(struct dns_reply const *repl, size_t n)
{
	return *(GACOPYZ_UINT32_T*)repl->base[n];
}
	
dns_status a_lookup(const char *host,
		    struct dns_reply *repl, unsigned long *ttl);

dns_status ptr_lookup(struct in_addr ip,
		      struct dns_reply *repl, unsigned long *ttl);
dns_status txt_lookup(const char *name,
		      struct dns_reply *repl, unsigned long *ttl);

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

dns_status spf_lookup(const char *domain, 
		      char ***txtv, size_t *txtc, unsigned long *ttl);


#endif

Return to:

Send suggestions and report system problems to the System administrator.