Qsmtp  0.30dev
Functions
dns_helpers.c File Reference

DNS helper functions that do no network actions. More...

#include <qdns.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

Functions

int domainvalid (const char *const host)
 
void freeips (struct ips *p)
 
static int ip6_sort (const void *l, const void *r)
 
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...
 
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

DNS helper functions that do no network actions.

Function Documentation

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.

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.