"Fossies" - the Fresh Open Source Software Archive

Member "udns-0.4/udns_bl.c" (5 Jul 2011, 5210 Bytes) of package /linux/misc/dns/udns-0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "udns_bl.c" see the Fossies "Dox" file reference documentation.

    1 /* udns_bl.c
    2    DNSBL stuff
    3 
    4    Copyright (C) 2005  Michael Tokarev <mjt@corpit.ru>
    5    This file is part of UDNS library, an async DNS stub resolver.
    6 
    7    This library is free software; you can redistribute it and/or
    8    modify it under the terms of the GNU Lesser General Public
    9    License as published by the Free Software Foundation; either
   10    version 2.1 of the License, or (at your option) any later version.
   11 
   12    This library is distributed in the hope that it will be useful,
   13    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15    Lesser General Public License for more details.
   16 
   17    You should have received a copy of the GNU Lesser General Public
   18    License along with this library, in file named COPYING.LGPL; if not,
   19    write to the Free Software Foundation, Inc., 59 Temple Place,
   20    Suite 330, Boston, MA  02111-1307  USA
   21 
   22  */
   23 
   24 #include "udns.h"
   25 #ifndef NULL
   26 # define NULL 0
   27 #endif
   28 
   29 struct dns_query *
   30 dns_submit_a4dnsbl(struct dns_ctx *ctx,
   31                    const struct in_addr *addr, const char *dnsbl,
   32                    dns_query_a4_fn *cbck, void *data) {
   33   dnsc_t dn[DNS_MAXDN];
   34   if (dns_a4ptodn(addr, dnsbl, dn, sizeof(dn)) <= 0) {
   35     dns_setstatus(ctx, DNS_E_BADQUERY);
   36     return NULL;
   37   }
   38   return
   39     dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_A, DNS_NOSRCH,
   40                   dns_parse_a4, (dns_query_fn*)cbck, data);
   41 }
   42 
   43 struct dns_query *
   44 dns_submit_a4dnsbl_txt(struct dns_ctx *ctx,
   45                        const struct in_addr *addr, const char *dnsbl,
   46                        dns_query_txt_fn *cbck, void *data) {
   47   dnsc_t dn[DNS_MAXDN];
   48   if (dns_a4ptodn(addr, dnsbl, dn, sizeof(dn)) <= 0) {
   49     dns_setstatus(ctx, DNS_E_BADQUERY);
   50     return NULL;
   51   }
   52   return
   53     dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_TXT, DNS_NOSRCH,
   54                   dns_parse_txt, (dns_query_fn*)cbck, data);
   55 }
   56 
   57 struct dns_rr_a4 *
   58 dns_resolve_a4dnsbl(struct dns_ctx *ctx,
   59                     const struct in_addr *addr, const char *dnsbl) {
   60   return (struct dns_rr_a4 *)
   61     dns_resolve(ctx, dns_submit_a4dnsbl(ctx, addr, dnsbl, 0, 0));
   62 }
   63 
   64 struct dns_rr_txt *
   65 dns_resolve_a4dnsbl_txt(struct dns_ctx *ctx,
   66                         const struct in_addr *addr, const char *dnsbl) {
   67   return (struct dns_rr_txt *)
   68     dns_resolve(ctx, dns_submit_a4dnsbl_txt(ctx, addr, dnsbl, 0, 0));
   69 }
   70 
   71 
   72 struct dns_query *
   73 dns_submit_a6dnsbl(struct dns_ctx *ctx,
   74                    const struct in6_addr *addr, const char *dnsbl,
   75                    dns_query_a4_fn *cbck, void *data) {
   76   dnsc_t dn[DNS_MAXDN];
   77   if (dns_a6ptodn(addr, dnsbl, dn, sizeof(dn)) <= 0) {
   78     dns_setstatus(ctx, DNS_E_BADQUERY);
   79     return NULL;
   80   }
   81   return
   82     dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_A, DNS_NOSRCH,
   83                   dns_parse_a4, (dns_query_fn*)cbck, data);
   84 }
   85 
   86 struct dns_query *
   87 dns_submit_a6dnsbl_txt(struct dns_ctx *ctx,
   88                        const struct in6_addr *addr, const char *dnsbl,
   89                        dns_query_txt_fn *cbck, void *data) {
   90   dnsc_t dn[DNS_MAXDN];
   91   if (dns_a6ptodn(addr, dnsbl, dn, sizeof(dn)) <= 0) {
   92     dns_setstatus(ctx, DNS_E_BADQUERY);
   93     return NULL;
   94   }
   95   return
   96     dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_TXT, DNS_NOSRCH,
   97                   dns_parse_txt, (dns_query_fn*)cbck, data);
   98 }
   99 
  100 struct dns_rr_a4 *
  101 dns_resolve_a6dnsbl(struct dns_ctx *ctx,
  102                     const struct in6_addr *addr, const char *dnsbl) {
  103   return (struct dns_rr_a4 *)
  104     dns_resolve(ctx, dns_submit_a6dnsbl(ctx, addr, dnsbl, 0, 0));
  105 }
  106 
  107 struct dns_rr_txt *
  108 dns_resolve_a6dnsbl_txt(struct dns_ctx *ctx,
  109                         const struct in6_addr *addr, const char *dnsbl) {
  110   return (struct dns_rr_txt *)
  111     dns_resolve(ctx, dns_submit_a6dnsbl_txt(ctx, addr, dnsbl, 0, 0));
  112 }
  113 
  114 static int
  115 dns_rhsbltodn(const char *name, const char *rhsbl, dnsc_t dn[DNS_MAXDN])
  116 {
  117   int l = dns_sptodn(name, dn, DNS_MAXDN);
  118   if (l <= 0) return 0;
  119   l = dns_sptodn(rhsbl, dn+l-1, DNS_MAXDN-l+1);
  120   if (l <= 0) return 0;
  121   return 1;
  122 }
  123 
  124 struct dns_query *
  125 dns_submit_rhsbl(struct dns_ctx *ctx, const char *name, const char *rhsbl,
  126                  dns_query_a4_fn *cbck, void *data) {
  127   dnsc_t dn[DNS_MAXDN];
  128   if (!dns_rhsbltodn(name, rhsbl, dn)) {
  129     dns_setstatus(ctx, DNS_E_BADQUERY);
  130     return NULL;
  131   }
  132   return
  133     dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_A, DNS_NOSRCH,
  134                   dns_parse_a4, (dns_query_fn*)cbck, data);
  135 }
  136 struct dns_query *
  137 dns_submit_rhsbl_txt(struct dns_ctx *ctx, const char *name, const char *rhsbl,
  138                      dns_query_txt_fn *cbck, void *data) {
  139   dnsc_t dn[DNS_MAXDN];
  140   if (!dns_rhsbltodn(name, rhsbl, dn)) {
  141     dns_setstatus(ctx, DNS_E_BADQUERY);
  142     return NULL;
  143   }
  144   return
  145     dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_TXT, DNS_NOSRCH,
  146                   dns_parse_txt, (dns_query_fn*)cbck, data);
  147 }
  148 
  149 struct dns_rr_a4 *
  150 dns_resolve_rhsbl(struct dns_ctx *ctx, const char *name, const char *rhsbl) {
  151   return (struct dns_rr_a4*)
  152     dns_resolve(ctx, dns_submit_rhsbl(ctx, name, rhsbl, 0, 0));
  153 }
  154 
  155 struct dns_rr_txt *
  156 dns_resolve_rhsbl_txt(struct dns_ctx *ctx, const char *name, const char *rhsbl)
  157 {
  158   return (struct dns_rr_txt*)
  159     dns_resolve(ctx, dns_submit_rhsbl_txt(ctx, name, rhsbl, 0, 0));
  160 }