Qsmtp  0.37
qdns.h
Go to the documentation of this file.
1 
4 #ifndef QSMTP_DNS_H
5 #define QSMTP_DNS_H
6 
7 #include <arpa/inet.h>
8 #include <netinet/in.h>
9 
15  MX_PRIORITY_USED = 65537,
17 };
18 
29 struct ips {
30  struct in6_addr *addr;
31  char *name;
32  unsigned int priority;
33  unsigned short count;
34  struct ips *next;
35 };
36 
43 #define FOREACH_STRUCT_IPS(_ptr, _s, _list) \
44  for (_ptr = _list, _s = 0; _ptr != NULL; (_s < _ptr->count - 1) ? (_s++) : (_ptr = _ptr->next, _s = 0))
45 
46 /* lib/qdns.c */
47 
48 extern int ask_dnsmx(const char *, struct ips **) __attribute__ ((nonnull (1,2)));
49 extern int ask_dnsaaaa(const char *, struct in6_addr **) __attribute__ ((nonnull (1,2)));
50 extern int ask_dnsa(const char *, struct in6_addr **) __attribute__ ((nonnull (1)));
51 extern int ask_dnsname(const struct in6_addr *, char **) __attribute__ ((nonnull (1,2)));
52 
53 /* lib/dnshelpers.c */
54 
55 extern void freeips(struct ips *);
56 extern int domainvalid(const char * const) __attribute__ ((pure)) __attribute__ ((nonnull (1)));
57 extern int domainvalid_or_inherit(const char * const) __attribute__ ((pure)) __attribute__ ((nonnull (1)));
58 extern void sortmx(struct ips **p) __attribute__ ((nonnull (1)));
59 extern struct ips *in6_to_ips(struct in6_addr *a, unsigned int cnt, const unsigned int priority) __attribute__ ((nonnull (1)));
60 
61 #ifndef INET_ADDRSTRLEN
62 #define INET_ADDRSTRLEN 16
63 #endif
64 
65 #define DOMAINNAME_MAX 255
70 enum dns_errors {
74 };
75 
83 static inline struct in6_addr
84 in_addr_to_v4mapped(const struct in_addr *ip4)
85 {
86  struct in6_addr ret;
87 
88  ret.s6_addr32[0] = htonl(0);
89  ret.s6_addr32[1] = htonl(0);
90  ret.s6_addr32[2] = htonl(0xffff);
91  ret.s6_addr32[3] = ip4->s_addr;
92 
93  return ret;
94 }
95 
96 extern int inet_pton_v4mapped(const char *str, struct in6_addr *addr) __attribute__ ((nonnull (1,2)));
97 
98 #endif
ips::addr
struct in6_addr * addr
Definition: qdns.h:30
freeips
void freeips(struct ips *)
Definition: dns_helpers.c:92
MX_PRIORITY_CURRENT
Definition: qdns.h:16
ips
list of IP addresses for a given host
Definition: qdns.h:29
inet_pton_v4mapped
int inet_pton_v4mapped(const char *str, struct in6_addr *addr)
read an IPv4 address and convert it to a v4mapped IPv6 address
Definition: dns_helpers.c:249
DNS_ERROR_PERM
Definition: qdns.h:73
ask_dnsa
int ask_dnsa(const char *, struct in6_addr **)
get A record from of the DNS
Definition: qdns.c:217
in_addr_to_v4mapped
static struct in6_addr in_addr_to_v4mapped(const struct in_addr *ip4)
convert an IPv4 address to a v4mapped IPv6 address
Definition: qdns.h:84
DNS_ERROR_LOCAL
Definition: qdns.h:71
in6_to_ips
struct ips * in6_to_ips(struct in6_addr *a, unsigned int cnt, const unsigned int priority)
convert an array of in6_addr structs to a list of struct ips
Definition: dns_helpers.c:222
mx_special_priorities
mx_special_priorities
values used as priority in struct ips to reflect special conditions
Definition: qdns.h:13
sortmx
void sortmx(struct ips **p)
sort MX list by priority
Definition: dns_helpers.c:141
ips::next
struct ips * next
Definition: qdns.h:34
ips::name
char * name
Definition: qdns.h:31
ask_dnsname
int ask_dnsname(const struct in6_addr *, char **)
get host name for IP address
Definition: qdns.c:283
ask_dnsmx
int ask_dnsmx(const char *, struct ips **)
get info out of the DNS
Definition: qdns.c:27
ask_dnsaaaa
int ask_dnsaaaa(const char *, struct in6_addr **)
get AAAA record from of the DNS
Definition: qdns.c:156
ips::count
unsigned short count
Definition: qdns.h:33
MX_PRIORITY_IMPLICIT
Definition: qdns.h:14
DNS_ERROR_TEMP
Definition: qdns.h:72
MX_PRIORITY_USED
Definition: qdns.h:15
domainvalid
int domainvalid(const char *const)
Definition: dns_helpers.c:24
ips::priority
unsigned int priority
Definition: qdns.h:32
domainvalid_or_inherit
int domainvalid_or_inherit(const char *const)
check if a string is a valid fqdn or "!inherit"
Definition: dns_helpers.c:78