File: dns.h

package info (click to toggle)
mailfromd 9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,268 kB
  • sloc: ansic: 56,643; sh: 22,791; yacc: 4,130; lex: 1,428; makefile: 914; lisp: 488; awk: 393; perl: 319; sed: 25
file content (127 lines) | stat: -rw-r--r-- 3,803 bytes parent folder | download
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-2024 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

#include <mflib/status.h>

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

/* NOTICE: When updating this enum, be sure to update dns_to_mf_status in
   dns.c accordingly. */
typedef enum {
	dns_success,
	dns_not_found,
	dns_failure,
	dns_temp_failure,
	dns_too_many
} dns_status;

typedef enum {
	dns_reply_ip,
	dns_reply_ip6,
	dns_reply_str
} dns_reply_type;

struct dns_reply {
	dns_reply_type type;
	int count;
	size_t maxcount;
	union {
		char **str;
		struct in_addr *ip;
		struct in6_addr *ip6;
		void *ptr;
	} data;
};

/*
 * Resolve modes for ns and mx lookups.  The DFL mode (use connection
 * type) is handled by MFL built-ins.
 */
enum {
	resolve_none = _MFL_RESOLVE_NONE,  /* Don't resolve hostnames. */
	resolve_ip4 = _MFL_RESOLVE_IP4,    /* Look up A records. */
	resolve_ip6 = _MFL_RESOLVE_IP6     /* Look up AAAA records. */
};

#define IPV4_INADDR_DOMAIN "in-addr.arpa"

/*
 * Max. buffer capacity for reversed dotted-quad IPv4: four three-digit
 * segments, each terminated by a dot, plus 1 byte for terminating \0.
 */
#define IPV4_DOTTED_BUFSIZE (4*4 + 1)

/*
 * Max. buffer capacity for formatting an in-addr.arpa address.
 */
#define	IPV4_INADDR_BUFSIZE \
	(IPV4_DOTTED_BUFSIZE + sizeof(IPV4_INADDR_DOMAIN) - 1)

#define IPV6_INADDR_DOMAIN "ip6.arpa"

/*
 * Max. buffer capacity for IPv6 addresses: 32 hexdigit
 * segments, each terminated by a dot, plus 1 byte for terminating \0.
 */
#define IPV6_DOTTED_BUFSIZE (32*2 + 1)

/*
 * Max. buffer capacity for formatting an ip6.arpa address.
 */
#define IPV6_INADDR_BUFSIZE \
	(IPV6_DOTTED_BUFSIZE + sizeof(IPV6_INADDR_DOMAIN) - 1)

#define IPMAX_DOTTED_BUFSIZE IPV6_DOTTED_BUFSIZE
#define IPMAX_INADDR_BUFSIZE IPV6_INADDR_BUFSIZE

void dnsbase_real_init(char *configtext);
void dnsbase_file_init(char const *file);

void dns_reply_init(struct dns_reply *reply, dns_reply_type type, size_t count);
void dns_reply_free(struct dns_reply *r);
size_t dns_reply_elsize(struct dns_reply *reply);

int dns_str_is_ipv4(const char *addr);
int dns_str_is_ipv6(const char *addr);

int dns_reverse_ipstr(const char *ipstr, char *revipstr, size_t len);
dns_status dns_reverse_name(const char *ipstr, char *buf, size_t bufsize);

dns_status dns_resolve_ipstr(const char *ipstr, struct dns_reply *reply);

dns_status dns_resolve_hostname(const char *host, int resolve_family, char **ipbuf);

dns_status soa_check(const char *name, int ip, struct dns_reply *repl);

dns_status a_lookup(const char *host, struct dns_reply *repl);
dns_status aaaa_lookup(const char *host, struct dns_reply *repl);

dns_status ptr_lookup(const char *host, struct dns_reply *reply);
dns_status txt_lookup(const char *name, struct dns_reply *repl);

dns_status ptr_validate(const char *ipstr, struct dns_reply *repl);

dns_status spf_lookup(const char *domain, char **record);
dns_status dkim_lookup(const char *domain, const char *sel, char ***retval);

dns_status mx_lookup(const char *host, int resolve, struct dns_reply *repl);

dns_status ns_lookup(const char *host, int resolve, struct dns_reply *reply);

#endif