lib/Net/LibResolv.xs

filter: Statementstmt 92.5% 25 / 27 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 90.3% 28 / 31 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Net/LibResolv.pm ↑ Summary
1 /* You may distribute under the terms of either the GNU General Public License
2 * or the Artistic License (the same terms as Perl itself)
3 *
4 * (C) Paul Evans, 2011 -- leonerd@leonerd.org.uk
5 */
6  
7 #include "EXTERN.h"
8 #include "perl.h"
9 #include "XSUB.h"
10  
11 #include <sys/types.h>
12 #include <netinet/in.h>
13 #include <arpa/nameser.h>
14 #include <resolv.h>
15  
16 5 static void setup_constants(void)
17 {
18 HV *stash;
19 AV *export;
20  
21 5 stash = gv_stashpvn("Net::LibResolv", 14, TRUE);
22 5 export = get_av("Net::LibResolv::EXPORT", TRUE);
23  
24 #define DO_CONSTANT(c) \
25 newCONSTSUB(stash, #c, newSViv(c)); \
26 av_push(export, newSVpv(#c, 0));
27  
28 5 DO_CONSTANT(HOST_NOT_FOUND)
29 5 DO_CONSTANT(NO_ADDRESS)
30 5 DO_CONSTANT(NO_DATA)
31 5 DO_CONSTANT(NO_RECOVERY)
32 5 DO_CONSTANT(TRY_AGAIN)
33 5 }
34  
35 1 static void set_h_errno(void)
36 {
37 1 SV *h_errno_sv = get_sv("Net::LibResolv::h_errno", GV_ADD);
38  
39 1 sv_setiv(h_errno_sv, h_errno);
40 1 sv_setpv(h_errno_sv, hstrerror(h_errno));
41  
42 1 SvIOK_on(h_errno_sv);
43 1 SvPOK_on(h_errno_sv);
44 1 }
45  
46 MODULE = Net::LibResolv PACKAGE = Net::LibResolv
47  
48 BOOT:
49 5 setup_constants();
50  
51 SV *
52 res_query(dname, class, type)
53 char *dname
54 int class
55 int type
56 PREINIT:
57 unsigned char answer[512];
58 int len;
59 CODE:
60 2 len = res_query(dname, class, type, answer, sizeof answer);
61 2 ▶ if(len == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if(len == -1) { 1 1 2
62 1 set_h_errno();
63 1 XSRETURN_UNDEF;
64 }
65 1 RETVAL = newSVpvn(answer, len);
66 OUTPUT:
67 RETVAL
68  
69 SV *
70 res_search(dname, class, type)
71 char *dname
72 int class
73 int type
74 PREINIT:
75 unsigned char answer[512];
76 int len;
77 CODE:
78 1 len = res_search(dname, class, type, answer, sizeof answer);
79 1 ▶ if(len == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if(len == -1) { 0 1 1
80 0 set_h_errno();
81 0 XSRETURN_UNDEF;
82 }
83 1 RETVAL = newSVpvn(answer, len);
84 OUTPUT:
85 RETVAL
« blib/lib/Net/LibResolv.pm ↑ Summary