"Fossies" - the Fresh Open Source Software Archive 
Member "udns-0.4/udns_misc.c" (5 Jul 2011, 2114 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_misc.c" see the
Fossies "Dox" file reference documentation.
1 /* udns_misc.c
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 }