root/src/udns/udns_misc.c

Revision 5a9b91bc0a14543e0995eba973fbeacc05aaee8b, 2.1 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

svn merge -r 327:330 https://labs.omniti.com/reconnoiter/branches/dev/udns .

closes #38

  • Property mode set to 100644
Line 
1 /* $Id: udns_misc.c,v 1.8 2005/04/05 22:51:32 mjt Exp $
2    miscellaneous routines
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
26 int dns_findname(const struct dns_nameval *nv, const char *name) {
27   register const char *a, *b;
28   for(; nv->name; ++nv)
29     for(a = name, b = nv->name; ; ++a, ++b)
30       if (DNS_DNUC(*a) != *b) break;
31       else if (!*a) return nv->val;
32   return -1;
33 }
34
35 const char *_dns_format_code(char *buf, const char *prefix, int code) {
36   char *bp = buf;
37   unsigned c, n;
38   do *bp++ = DNS_DNUC(*prefix);
39   while(*++prefix);
40   *bp++ = '#';
41   if (code < 0) code = -code, *bp++ = '-';
42   n = 0; c = code;
43   do ++n;
44   while((c /= 10));
45   c = code;
46   bp[n--] = '\0';
47   do bp[n--] = c % 10 + '0';
48   while((c /= 10));
49   return buf;
50 }
51
52 const char *dns_strerror(int err) {
53   if (err >= 0) return "successeful completion";
54   switch(err) {
55   case DNS_E_TEMPFAIL:  return "temporary failure in name resolution";
56   case DNS_E_PROTOCOL:  return "protocol error";
57   case DNS_E_NXDOMAIN:  return "domain name does not exist";
58   case DNS_E_NODATA:    return "valid domain but no data of requested type";
59   case DNS_E_NOMEM:     return "out of memory";
60   case DNS_E_BADQUERY:  return "malformed query";
61   default:              return "unknown error";
62   }
63 }
64
65 const char *dns_version(void) {
66   return UDNS_VERSION;
67 }
Note: See TracBrowser for help on using the browser.