dns.c File Reference

DNS Functions. More...

#include "spf.h"
#include "util.h"
#include "dns.h"
#include "error.h"

Go to the source code of this file.

Functions

char * DNS_query (peer_info_t *peer_info, const char *s, const int T_TYPE, const char *mta)
 Execute a DNS query.

char * DNS_txt_answer (int16_t ancount, const u_char *msg_ptr, const u_char *eom_ptr, u_char *rd_ptr, char *buf, int *ttl)
 Process a DNS message of type T_TXT.

char * DNS_mx_answer (int16_t ancount, const u_char *msg_ptr, const u_char *eom_ptr, u_char *rd_ptr, char *buf, int *ttl)
 Process a DNS message of type T_MX.

SPF_BOOL DNS_ptr_answer (peer_info_t *peer_info, int16_t ancount, const u_char *msg_ptr, const u_char *eom_ptr, u_char *rd_ptr, char *buf, const char *mta, int *ttl)
 Process a DNS message of type T_PTR.

char * DNS_cname_answer (int16_t ancount, const u_char *msg_ptr, const u_char *eom_ptr, u_char *rd_ptr, char *buf, int *ttl)
 Process a DNS message of type T_MX.


Detailed Description

DNS Functions.

dns.c contains functions relating to the execution and processing of DNS queries. Each particular DNS record type has a unique function that is designed to process such a response.

Definition in file dns.c.


Function Documentation

char * DNS_cname_answer int16_t  ancount,
const u_char *  msg_ptr,
const u_char *  eom_ptr,
u_char *  rd_ptr,
char *  buf,
int *  ttl
 

Process a DNS message of type T_MX.

Parameters:
ancount Answer count
msg_ptr DNS message
eom_ptr Pointer to the end of the DNS message
rd_ptr Pointer to a position in the DNS message
buf Utiltiy buffer
ttl Time To Live value of the DNS message
Author: Teddy <teddy@teddy.ch>

Date: 29/04/04
Date: 02/20/04 - Added cache by Travis Anderson <travis@anthrax.ca>

Desc: SPF_PACKETSZ bytes are allocated and then filled with chars. This buffer is then used in a TXT DNS query using data from the passed peer_info_t structure. Upon success this buffer is re-cast as a char * and then a pointer to this memory is returned. Upon failure a NULL pointer is returned.

Definition at line 733 of file dns.c.

References SPF_MAXCDNAME, SPF_MAXDNAME, xeprintf, xmalloc, xrealloc, and xvprintf.

Referenced by DNS_query().

char * DNS_mx_answer int16_t  ancount,
const u_char *  msg_ptr,
const u_char *  eom_ptr,
u_char *  rd_ptr,
char *  buf,
int *  ttl
 

Process a DNS message of type T_MX.

Parameters:
ancount Answer count
msg_ptr DNS message
eom_ptr Pointer to the end of the DNS message
rd_ptr Pointer to a position in the DNS message
buf Utiltiy buffer
ttl Time To Live value of the DNS message
Author: James Couzens <jcouzens@6o4.ca>

Date: 01/02/04
Date: 02/20/04 - Added cache by Travis Anderson <travis@anthrax.ca>

Desc: SPF_PACKETSZ bytes are allocated and then filled with chars. This buffer is then used in an MX DNS query using data from the passed peer_info_t structure. Upon success this buffer is re-cast as a char * and then a pointer to this memory is returned. Upon failure a NULL pointer is returned.

Definition at line 504 of file dns.c.

References SPF_MAXCDNAME, SPF_MAXDNAME, xeprintf, xmalloc, xprintf, xrealloc, and xvprintf.

Referenced by DNS_query().

SPF_BOOL DNS_ptr_answer peer_info_t peer_info,
int16_t  ancount,
const u_char *  msg_ptr,
const u_char *  eom_ptr,
u_char *  rd_ptr,
char *  buf,
const char *  mta,
int *  ttl
 

Process a DNS message of type T_PTR.

Parameters:
peer_info Global information structure containing client information
ancount Answer count
msg_ptr DNS message
eom_ptr Pointer to the end of the DNS message
rd_ptr Pointer to a position in the DNS message
buf Utiltiy buffer
mta IP address of the authoritative MX
ttl Time To Live value of the DNS message
Author: James Couzens <jcouzens@6o4.ca>

Date: 01/02/04
Date: 02/20/04 - Added cache by Travis Anderson <travis@anthrax.ca>

Desc: A reverse lookup on an IP address leads to a lookup per returned PTR answer to see if the returned answer matches. The forward lookups are handled by a separate function which calls gethostbyname. Upon a single successful match of a forward lookup with a reverse lookup, returns TRUE. Returns FALSE upon failure.

Definition at line 599 of file dns.c.

References FALSE, peer_info_s::r_vhname, SPF_BOOL, SPF_MAXCDNAME, SPF_MAXDNAME, TRUE, UTIL_get_dname(), UTIL_validate_hostname(), xeprintf, xfree, xprintf, xstrndup, and xvprintf.

Referenced by DNS_query().

char * DNS_query peer_info_t peer_info,
const char *  s,
const int  T_TYPE,
const char *  mta
 

Execute a DNS query.

Parameters:
peer_info Global information structure containing client information
s Domain name with which to perform the query against
T_TYPE Type of DNS record to lookup (eg: T_TXT, T_PTR, T_A, etc..)
mta Used by DNS_ptr_answer in validation of an SPF ptr mechanism
Author: James Couzens <jcouzens@6o4.ca>
Author: Travis Anderson <travis@anthrax.ca>

Date: 12/10/03
Date: 02/20/04 - Added cache by Travis Anderson <travis@anthrax.ca>

Desc: Executes a DNS query of type T_TYPE and then calls the appropriate answer parsing function based on that type. Returns a pointer to allocated memory (a string of space delimited records). Upon failure returns NULL.

Definition at line 189 of file dns.c.

References DNS_cname_answer(), DNS_mx_answer(), DNS_ptr_answer(), DNS_txt_answer(), peer_info_s::error, FALSE, h_errno, MAX_ERROR, peer_info_t, SPF_ERROR, SPF_MAXDNAME, SPF_NONE, SPF_PACKETSZ, TRUE, UTIL_assoc_prefix(), xeprintf, and xvprintf.

Referenced by SPF_parse_policy(), SPF_policy_main_rec(), UTIL_mx_cmp(), UTIL_ptr_cmp(), and UTIL_validate_ptr().

char * DNS_txt_answer int16_t  ancount,
const u_char *  msg_ptr,
const u_char *  eom_ptr,
u_char *  rd_ptr,
char *  buf,
int *  ttl
 

Process a DNS message of type T_TXT.

Parameters:
ancount Answer count
msg_ptr DNS message
eom_ptr Pointer to the end of the DNS message
rd_ptr Pointer to a position in the DNS message
buf Utiltiy buffer
ttl Time To Live value of the DNS message
Author: James Couzens <jcouzens@6o4.ca>

Date: 01/02/04
Date: 02/23/04 - Bugfix from Albert Weichselbraun <albert@atnet.at>
Date: 02/20/04 - Added cache by Travis Anderson <travis@anthrax.ca>

Desc: SPF_PACKETSZ bytes are allocated and then filled with chars. This buffer is then used in a TXT DNS query using data from the passed peer_info_t structure. Upon success this buffer is re-cast as a char * and then a pointer to this memory is returned. Upon failure a NULL pointer is returned.

Definition at line 364 of file dns.c.

References SPF_MAXCDNAME, SPF_MAXDNAME, xeprintf, xfree, xmalloc, xrealloc, xstrndup, and xvprintf.

Referenced by DNS_query().


Generated on Thu Jul 1 14:05:44 2004 for libspf v1.0 by doxygen 1.3.7