headers of functions for DNS lookups
More...
#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 |
|
|
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 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 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...
|
|
headers of functions for DNS lookups
#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 |
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
|
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 |
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) |
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 |
DNS_ERROR_TEMP | if temporary DNS error |
DNS_ERROR_PERM | if permanent DNS error |
DNS_ERROR_LOCAL | on error (errno is set) |
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 |
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
void freeips |
( |
struct ips * |
p | ) |
|
free memory of IP list
- Parameters
-
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.
static struct in6_addr in_addr_to_v4mapped |
( |
const struct in_addr * |
ip4 | ) |
|
|
static |
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.
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 |
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.