Qsmtp  0.30dev
Data Structures | Macros | Enumerations | Functions
qdns.h File Reference

headers of functions for DNS lookups More...

#include <netinet/in.h>

Go to the source code of this file.

Data Structures

struct  ips
 list of IP addresses for a given host More...
 

Macros

#define FOREACH_STRUCT_IPS(_ptr, _s, _list)   for (_ptr = _list, _s = 0; _ptr != NULL; (_s < _ptr->count - 1) ? (_s++) : (_ptr = _ptr->next, _s = 0))
 iterate through all IP addresses in an list of MX entries More...
 
#define INET_ADDRSTRLEN   16
 

Enumerations

enum  mx_special_priorities { MX_PRIORITY_IMPLICIT = 65536, MX_PRIORITY_USED = 65537, MX_PRIORITY_CURRENT = 65538 }
 values used as priority in struct ips to reflect special conditions More...
 
enum  dns_errors { DNS_ERROR_LOCAL = -1, DNS_ERROR_TEMP = -2, DNS_ERROR_PERM = -3 }
 error codes returned by the DNS lookup functions More...
 

Functions

int ask_dnsmx (const char *, struct ips **)
 get info out of the DNS More...
 
int ask_dnsaaaa (const char *, struct in6_addr **)
 get AAAA record from of the DNS More...
 
int ask_dnsa (const char *, struct in6_addr **)
 get A record from of the DNS More...
 
int ask_dnsname (const struct in6_addr *, char **)
 get host name for IP address More...
 
void freeips (struct ips *)
 
int domainvalid (const char *const)
 
void sortmx (struct ips **p)
 sort MX list by priority More...
 
struct ipsin6_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 More...
 
static struct in6_addr in_addr_to_v4mapped (const struct in_addr *ip4)
 convert an IPv4 address to a v4mapped IPv6 address More...
 
int inet_pton_v4mapped (const char *str, struct in6_addr *addr)
 read an IPv4 address and convert it to a v4mapped IPv6 address More...
 

Detailed Description

headers of functions for DNS lookups

Macro Definition Documentation

#define FOREACH_STRUCT_IPS (   _ptr,
  _s,
  _list 
)    for (_ptr = _list, _s = 0; _ptr != NULL; (_s < _ptr->count - 1) ? (_s++) : (_ptr = _ptr->next, _s = 0))

iterate through all IP addresses in an list of MX entries

Parameters
_ptrstruct ips* variable that holds the current entry
_sunsigned short variable that holds the current index inside _ptr
_liststart point of the list to iterate over

Enumeration Type Documentation

enum dns_errors

error codes returned by the DNS lookup functions

Enumerator
DNS_ERROR_LOCAL 

a local error during DNS lookup, errno is set

DNS_ERROR_TEMP 

a temporary DNS error

DNS_ERROR_PERM 

a permanent DNS error

values used as priority in struct ips to reflect special conditions

Enumerator
MX_PRIORITY_IMPLICIT 

used for implicit MX entries (i.e. A or AAAA)

MX_PRIORITY_USED 

the entry has already been tried

MX_PRIORITY_CURRENT 

used to mark the entry currently in use

Function Documentation

int ask_dnsa ( const char *  name,
struct in6_addr **  result 
)

get A record from of the DNS

Parameters
namethe name to look up
resultfirst element of a list of results will be placed, or NULL if only return code is of interest
Returns
if records have been found
Return values
0no entries found
>0how many entries were returned in result
DNS_ERROR_LOCALon error (errno is set)
DNS_ERROR_TEMPtemporary DNS error
DNS_ERROR_PERMpermanent DNS error
int ask_dnsaaaa ( const char *  name,
struct in6_addr **  result 
)

get AAAA record from of the DNS

Parameters
namethe name to look up
resultfirst element of a list of results will be placed
Return values
0no entries found
>0how many entries were returned in result
DNS_ERROR_TEMPif temporary DNS error
DNS_ERROR_PERMif permanent DNS error
DNS_ERROR_LOCALon error (errno is set)
int ask_dnsmx ( const char *  name,
struct ips **  result 
)

get info out of the DNS

Parameters
namethe name to look up
resultfirst element of a list of results will be placed
Return values
0on success
1if host is not existent
DNS_ERROR_TEMPif temporary DNS error
DNS_ERROR_PERMif permanent DNS error
DNS_ERROR_LOCALon error (errno is set)
int ask_dnsname ( const struct in6_addr *  ip,
char **  result 
)

get host name for IP address

Parameters
ipthe IP to look up
resultname will be stored here
Returns
how many names were found, negative on error
Return values
0host not found
DNS_ERROR_LOCALlocal error (errno is set)
DNS_ERROR_TEMPtemporary DNS error
DNS_ERROR_PERMpermanent DNS error
int domainvalid ( const char *const  host)

check if a string is a valid fqdn

Parameters
hostthe name to check
Returns
if the string is a valid domain name
Return values
0everything is ok
1on syntax error

if there is a standard function doing the same throw this one away

void freeips ( struct ips p)

free memory of IP list

Parameters
pIP list to free
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

Parameters
athe input array
cntthe address count in a (must be >0)
prioritypriority of the new records
Returns
list of struct ips
Return values
NULLan allocation error happened during conversion

a will always be freed.

static struct in6_addr in_addr_to_v4mapped ( const struct in_addr *  ip4)
static

convert an IPv4 address to a v4mapped IPv6 address

Parameters
ip4the address to convert
Returns
the v4mapped address
Warning
This does not handle any special addresses specifically.
int inet_pton_v4mapped ( const char *  str,
struct in6_addr *  addr 
)

read an IPv4 address and convert it to a v4mapped IPv6 address

Parameters
strthe string to read in
addrwhere to store the resulting address
Returns
the same values as inet_pton()
Return values
1address was successfully read in
void sortmx ( struct ips **  p)

sort MX list by priority

Parameters
plist of MX entries

Inside each entry of p the IPv6 entries are moved to the front so that IPv6 addresses are prefered. If 2 entries of p have the same priority those that contain IPv6 addresses will be moved to the front for the same reason.

If IPV4ONLY is defined all IPv6 addresses will be stripped from the list.