libSPF v1.0: dns.h Source File

Main Page | Data Structures | File List | Data Fields | Globals | Search for

# dns.h

Go to the documentation of this file.

    00001 /* libspf - Sender Policy Framework library
    00002 *
    00003 *  ANSI C implementation of spf-draft-200405.txt
    00004 *
    00005 *  Author: James Couzens <jcouzens@codeshare.ca>
    00006 *  Author: Sean Comeau   <scomeau@obscurity.org>
    00007 *
    00008 *  FILE: dns.h
    00009 *  DESC: dns functions header file
    00010 *
    00011 *  License:
    00012 *
    00013 *  The libspf Software License, Version 1.0
    00014 *
    00015 *  Copyright (c) 2004 James Couzens & Sean Comeau  All rights
    00016 *  reserved.
    00017 *
    00018 *  Redistribution and use in source and binary forms, with or without
    00019 *  modification, are permitted provided that the following conditions
    00020 *  are met:
    00021 *
    00022 *  1. Redistributions of source code must retain the above copyright
    00023 *     notice, this list of conditions and the following disclaimer.
    00024 *
    00025 *  2. Redistributions in binary form must reproduce the above copyright
    00026 *     notice, this list of conditions and the following disclaimer in
    00027 *     the documentation and/or other materials provided with the
    00028 *     distribution.
    00029 *
    00030 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    00031 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    00032 *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    00033 *  DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS MAKING USE OF THIS LICESEN
    00034 *  OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00035 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00036 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    00037 *  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00038 *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    00039 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    00040 *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    00041 *  SUCH DAMAGE.
    00042 *
    00043 */
    00044
    00045 #ifndef _DNS_H
    00046 #define _DNS_H 1
    00047
    00048 #include "../../config.h"    /* autoconf */
    00049 #include <stdio.h>           /* printf */
    00050 #include <string.h>          /* snprintf strstr */
    00051 #include <strings.h>         /* strcasecmp */
    00052 #include <sys/socket.h>      /* inet_ functions / structs */
    00053 #include <netinet/in.h>      /* inet_ functions / structs */
    00054 #include <arpa/nameser.h>    /* DNS HEADER struct */
    00055 #include <resolv.h>          /* dn_skipname */
    00056 #include <netdb.h>           /* gethostbyname */
    00057 #include <arpa/inet.h>       /* in_addr struct */
    00058
    00059 #ifdef _WITH_DARWINPPC
    00060 #include <nameser8_compat.h> /* T_CNAME */
    00061 #endif /* _WITH_DARWINPCC */
    00062
    00063 #ifdef _WITH_PTHREADS
    00064 #include <pthread.h>         /* pthread_mutex_t */
    00065 #endif /* _WITH_PTHREADS */
    00066
    00067 #ifdef HAVE__BEGIN_DECLS
    00068 __BEGIN_DECLS
    00069 #else
    00070 # ifdef __cplusplus
    00071 extern "C" {
    00072 # endif /* __cplusplus */
    00073 #endif /* HAVE__BEGIN_DECLS */
    00074
    00075 /*
    00076 *  For reference purposes commented out are the constants based on
    00077 *  RFC 883, RFC 1034, RFC 1035.  Because we're working with IN_TXT
    00078 *  records we will use a larger packet size at 65536 bytes which
    00079 *  is likey to cover most circumstances.
    00080 *
    00081 *  #define PACKETSZ  512   max response packet size
    00082 *  #define MAXDNAME  1025  max uncompressed IN_TXT record
    00083 *  #define MAXCDNAME 255   max compressed IN_TXT record
    00084 *
    00085 */
    00086
    00087 #define SPF_PACKETSZ  8192
    00088 #define SPF_MAXDNAME  1025
    00089 #define SPF_MAXCDNAME 255
    00090
    00091 extern int h_errno;
    00092
    00093 #ifndef HPUX
    00094 struct hostent;
    00095 #endif /* HPUX */
    00096
    00097 void _DNS_gethostbyname_r_free(void);
    00098
    00099 #ifdef _WITH_PTHREADS
    00100   /* if we've got native gethostbyname_r (GNU extension) */
    00101   #ifdef HAVE_GETHOSTBYNAME_R
    00102
    00103     struct hostent *_DNS_GNU_gethostbyname_r(const char *name, struct hostent *result,
    00104       char *buf, int buflen, int *h_errnop);
    00105
    00106     #define xgethostbyname(a, b, c, d, e) _DNS_GNU_gethostbyname_r((a), (b), (c), (d), (e))
    00107     #define xgethostbyname_free()
    00108
    00109   #else
    00110     extern pthread_mutex_t dns_mutex;
    00111
    00112     struct hostent *_DNS_gethostbyname_r(const char *name, struct hostent *result,
    00113       char *buf, int buflen, int *h_errnop);
    00114
    00115     #define xgethostbyname(a, b, c, d, e) _DNS_gethostbyname_r((a), (b), (c), (d), (e))
    00116     #define xgethostbyname_free()         _DNS_gethostbyname_r_free()
    00117
    00118   #endif /* HAVE_GETHOSTBYNAME_R */
    00119 #else /* _WITH_PTHREADS */
    00120
    00121   #define xgethostbyname(a, b, c, d, e) gethostbyname((a))
    00122   #define xgethostbyname_free()
    00123
    00124 #endif /* _WITH_PTHREADS */
    00125
    00126
    00127 /* silence link error on SCO */
    00128 #ifdef SCO
    00129 #undef h_errno
    00130 #define h_errno errno
    00131 #endif /* SCO */
    00132
    00133 char    *DNS_query(peer_info_t *, const char *, const int T_TYPE, const char *);
    00134 char    *DNS_txt_answer(int16_t, const u_char *, const u_char *, u_char *,
    00135                         char *, int *);
    00136 char    *DNS_mx_answer(int16_t, const u_char *, const u_char *, u_char *,
    00137                        char *, int *);
    00138 SPF_BOOL DNS_ptr_answer(peer_info_t *, int16_t, const u_char *, const u_char *,
    00139                         u_char *, char *, const char *, int *);
    00140 char    *DNS_cname_answer(int16_t, const u_char *, const u_char *,
    00141                           u_char *, char *, int *);
    00142 SPF_BOOL DNS_check_client_reverse(peer_info_t *);
    00143
    00144
    00145 #ifdef  HAVE__BEGIN_DECLS
    00146 __END_DECLS /* _DNS_H */
    00147 #else
    00148 # ifdef __cplusplus
    00149 }
    00150 # endif /* __cplusplus */
    00151 #endif /* HAVE__BEGIN_DECLS */
    00152
    00153 #endif /* _DNS_H */
    00154
    00155 /* end dns.h */