headers of functions for DNS lookups
More...
#include <arpa/inet.h>
#include <netinet/in.h>
Go to the source code of this file.
|
struct | ips |
| list of IP addresses for a given host More...
|
|
|
#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 |
|
#define | DOMAINNAME_MAX 255 |
|
headers of functions for DNS lookups
◆ DOMAINNAME_MAX
#define DOMAINNAME_MAX 255 |
maximum length of a valid domain name
◆ FOREACH_STRUCT_IPS
#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
-
_ptr | struct ips* variable that holds the current entry |
_s | unsigned short variable that holds the current index inside _ptr |
_list | start point of the list to iterate over |
◆ 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
|
◆ mx_special_priorities
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
|
◆ ask_dnsa()
int ask_dnsa |
( |
const char * |
name, |
|
|
struct in6_addr ** |
result |
|
) |
| |
get A record from of the DNS
- Parameters
-
name | the name to look up |
result | first 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
-
0 | no entries found |
>0 | how many entries were returned in result |
DNS_ERROR_LOCAL | on error (errno is set) |
DNS_ERROR_TEMP | temporary DNS error |
DNS_ERROR_PERM | permanent DNS error |
◆ ask_dnsaaaa()
int ask_dnsaaaa |
( |
const char * |
name, |
|
|
struct in6_addr ** |
result |
|
) |
| |
get AAAA record from of the DNS
- Parameters
-
name | the name to look up |
result | first element of a list of results will be placed |
- Return values
-
0 | no entries found |
>0 | how many entries were returned in result |
DNS_ERROR_TEMP | if temporary DNS error |
DNS_ERROR_PERM | if permanent DNS error |
DNS_ERROR_LOCAL | on error (errno is set) |
◆ ask_dnsmx()
int ask_dnsmx |
( |
const char * |
name, |
|
|
struct ips ** |
result |
|
) |
| |
get info out of the DNS
- Parameters
-
name | the name to look up |
result | first element of a list of results will be placed |
- Return values
-
0 | on success |
1 | if host is not existent |
2 | null MX is set for this domain (RfC 7505) |
DNS_ERROR_TEMP | if temporary DNS error |
DNS_ERROR_PERM | if permanent DNS error |
DNS_ERROR_LOCAL | on error (errno is set) |
◆ ask_dnsname()
int ask_dnsname |
( |
const struct in6_addr * |
ip, |
|
|
char ** |
result |
|
) |
| |
get host name for IP address
- Parameters
-
ip | the IP to look up |
result | name will be stored here |
- Returns
- how many names were found, negative on error
- Return values
-
0 | host not found |
DNS_ERROR_LOCAL | local error (errno is set) |
DNS_ERROR_TEMP | temporary DNS error |
DNS_ERROR_PERM | permanent DNS error |
◆ domainvalid()
int domainvalid |
( |
const char *const |
host | ) |
|
check if a string is a valid fqdn
- Parameters
-
- Returns
- if the string is a valid domain name
- Return values
-
0 | everything is ok |
1 | on syntax error |
if there is a standard function doing the same throw this one away
◆ domainvalid_or_inherit()
int domainvalid_or_inherit |
( |
const char *const |
host | ) |
|
check if a string is a valid fqdn or "!inherit"
- Parameters
-
- Returns
- if the string is a valid domain name
- Return values
-
0 | everything is ok |
1 | on syntax error |
◆ freeips()
void freeips |
( |
struct ips * |
p | ) |
|
free memory of IP list
- Parameters
-
◆ 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
- Parameters
-
a | the input array |
cnt | the address count in a (must be >0) |
priority | priority of the new records |
- Returns
- list of struct ips
- Return values
-
NULL | an allocation error happened during conversion |
a will always be freed.
◆ in_addr_to_v4mapped()
static struct in6_addr in_addr_to_v4mapped |
( |
const struct in_addr * |
ip4 | ) |
|
|
inlinestatic |
convert an IPv4 address to a v4mapped IPv6 address
- Parameters
-
ip4 | the address to convert |
- Returns
- the v4mapped address
- Warning
- This does not handle any special addresses specifically.
◆ 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
- Parameters
-
str | the string to read in |
addr | where to store the resulting address |
- Returns
- the same values as inet_pton()
- Return values
-
1 | address was successfully read in |
◆ sortmx()
void sortmx |
( |
struct ips ** |
p | ) |
|
sort MX list by priority
- Parameters
-
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.