Qsmtp  0.30dev
qdns.h
Go to the documentation of this file.
1 
4 #ifndef QSMTP_DNS_H
5 #define QSMTP_DNS_H
6 
7 #include <netinet/in.h>
8 
14  MX_PRIORITY_USED = 65537,
16 };
17 
28 struct ips {
29  struct in6_addr *addr;
30  char *name;
31  unsigned int priority;
32  unsigned short count;
33  struct ips *next;
34 };
35 
42 #define FOREACH_STRUCT_IPS(_ptr, _s, _list) \
43  for (_ptr = _list, _s = 0; _ptr != NULL; (_s < _ptr->count - 1) ? (_s++) : (_ptr = _ptr->next, _s = 0))
44 
45 /* lib/qdns.c */
46 
47 extern int ask_dnsmx(const char *, struct ips **) __attribute__ ((nonnull (1,2)));
48 extern int ask_dnsaaaa(const char *, struct in6_addr **) __attribute__ ((nonnull (1,2)));
49 extern int ask_dnsa(const char *, struct in6_addr **) __attribute__ ((nonnull (1)));
50 extern int ask_dnsname(const struct in6_addr *, char **) __attribute__ ((nonnull (1,2)));
51 
52 /* lib/dnshelpers.c */
53 
54 extern void freeips(struct ips *);
55 extern int domainvalid(const char * const) __attribute__ ((pure)) __attribute__ ((nonnull (1)));
56 extern void sortmx(struct ips **p) __attribute__ ((nonnull (1)));
57 extern struct ips *in6_to_ips(struct in6_addr *a, unsigned int cnt, const unsigned int priority) __attribute__ ((nonnull (1)));
58 
59 #ifndef INET_ADDRSTRLEN
60 #define INET_ADDRSTRLEN 16
61 #endif
62 
66 enum dns_errors {
70 };
71 
79 static inline struct in6_addr
80 in_addr_to_v4mapped(const struct in_addr *ip4)
81 {
82  struct in6_addr ret;
83 
84  ret.s6_addr32[0] = htonl(0);
85  ret.s6_addr32[1] = htonl(0);
86  ret.s6_addr32[2] = htonl(0xffff);
87  ret.s6_addr32[3] = ip4->s_addr;
88 
89  return ret;
90 }
91 
92 extern int inet_pton_v4mapped(const char *str, struct in6_addr *addr) __attribute__ ((nonnull (1,2)));
93 
94 #endif
Definition: qdns.h:15
list of IP addresses for a given host
Definition: qdns.h:28
Definition: qdns.h:14
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:205
struct in6_addr * addr
Definition: qdns.h:29
unsigned short count
Definition: qdns.h:32
dns_errors
error codes returned by the DNS lookup functions
Definition: qdns.h:66
int ask_dnsaaaa(const char *, struct in6_addr **)
get AAAA record from of the DNS
Definition: qdns.c:152
struct ips * next
Definition: qdns.h:33
char * name
Definition: qdns.h:30
int ask_dnsmx(const char *, struct ips **)
get info out of the DNS
Definition: qdns.c:26
Definition: qdns.h:68
Definition: qdns.h:69
int domainvalid(const char *const)
Definition: dns_helpers.c:23
Definition: qdns.h:67
int ask_dnsa(const char *, struct in6_addr **)
get A record from of the DNS
Definition: qdns.c:213
unsigned int priority
Definition: qdns.h:31
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:234
void freeips(struct ips *)
Definition: dns_helpers.c:75
int ask_dnsname(const struct in6_addr *, char **)
get host name for IP address
Definition: qdns.c:277
mx_special_priorities
values used as priority in struct ips to reflect special conditions
Definition: qdns.h:12
void sortmx(struct ips **p)
sort MX list by priority
Definition: dns_helpers.c:124
Definition: qdns.h:13
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:80