ToolKit.xs

filter: Statementstmt 82.1% 226 / 275 Branchbran 65.5% 131 / 200 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 75.1% 357 / 475 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs_include/dn_expand.inc ↑ Summary blib/lib/Net/DNS/ToolKit/Debug.pm »
1 /* ToolKit.xs
2 *
3 * Copyright 2003 - 2011, Michael Robinton <michael@bizsystems.com>
4 *
5 * Michael Robinton <michael@bizsystems.com>
6 *
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of either:
11 *
12 * a) the GNU General Public License as published by the Free
13 * Software Foundation; either version 2, or (at your option) any
14 * later version, or
15 *
16 * b) the "Artistic License" which comes with this distribution.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
21 * the GNU General Public License or the Artistic License for more details.
22 *
23 * You should have received a copy of the Artistic License with this
24 * distribution, in the file named "Artistic". If not, I'll be glad to provide
25 * one.
26 *
27 * You should also have received a copy of the GNU General Public License
28 * along with this program in the file named "Copying". If not, write to the
29 *
30 * Free Software Foundation, Inc.
31 * 59 Temple Place, Suite 330
32 * Boston, MA 02111-1307, USA
33 *
34 * or visit their web page on the internet at:
35 *
36 * http://www.gnu.org/copyleft/gpl.html.
37 */
38  
39 #include "EXTERN.h"
40 #include "perl.h"
41 #include "XSUB.h"
42 #include <stdio.h>
43  
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
47 #include "u_intxx.h"
48  
49 /* for size of string buffer below */
50 #include <netdb.h>
51 #include <resolv.h>
52 #include <arpa/nameser.h>
53 #ifdef BIND_4_COMPAT
54 #include <arpa/nameser_compat.h>
55 #endif
56 #include "ToolKit.h"
57  
58 /* for clock */
59 #include <time.h>
60  
61 /* for resolver */
62 struct __res_state res;
63  
64 #ifdef RES_XINIT
65 #define RES_Init RES_INIT | RES_XINIT
66 #else
67 #define RES_Init RES_INIT
68 #endif
69  
70 /* from /usr/include/arpa/nameser_compat.h, modified a little */
71 typedef struct {
72 unsigned id :16; /* query identification number */
73 #ifdef host_is_BIG_ENDIAN
74 /* fields in third byte */
75 unsigned qr :1; /* response flag */
76 unsigned opcode :4; /* purpose of message */
77 unsigned aa :1; /* authoritive answer */
78 unsigned tc :1; /* truncated message */
79 unsigned rd :1; /* recursion desired */
80 /* fields in fourth byte */
81 unsigned ra :1; /* recursion available */
82 unsigned z :1; /* unused bits (MBZ as of 4.9.3a3) */
83 unsigned ad :1; /* authentic data from named */
84 unsigned cd :1; /* checking disabled by resolver */
85 unsigned rcode :4; /* response code */
86 #else
87 # ifdef host_is_LITTLE_ENDIAN
88 /* fields in third byte */
89 unsigned rd :1; /* recursion desired */
90 unsigned tc :1; /* truncated message */
91 unsigned aa :1; /* authoritive answer */
92 unsigned opcode :4; /* purpose of message */
93 unsigned qr :1; /* response flag */
94 /* fields in fourth byte */
95 unsigned rcode :4; /* response code */
96 unsigned cd :1; /* checking disabled by resolver */
97 unsigned ad :1; /* authentic data from named */
98 unsigned z :1; /* unused bits (MBZ as of 4.9.3a3) */
99 unsigned ra :1; /* recursion available */
100 # else
101 # error ENDIANness is not defined
102 # endif
103 #endif
104 /* remaining bytes */
105 unsigned qdcount :16; /* number of question entries */
106 unsigned ancount :16; /* number of answer entries */
107 unsigned nscount :16; /* number of authority entries */
108 unsigned arcount :16; /* number of resource entries */
109 } MY_HEADER;
110  
111 u_char * dnptrs[20];
112  
113 struct in_addr i2p;
114  
115 struct timeval tv;
116  
117 #ifdef lastchanceTEST
118 #ifndef NO_RESOLV_CONF
119 #define NO_RESOLV_CONF
120 #endif
121 #endif
122  
123 struct __res_state my_res_state;
124 struct sockaddr_in mysa;
125  
126 #ifdef _PATH_RESCONF
127 char *path = _PATH_RESCONF;
128 size_t pathz = sizeof(_PATH_RESCONF);
129 #else
130 char *path = NULL;
131 size_t pathz = 0;
132 #endif
133  
134 /* **************************** *
135 * return int's, long's *
136 * from char string *
137 * **************************** *
138 */
139  
140 u_short
141 90 gint16(u_char * cp)
142 {
143 u_short i;
144 90 NS_GET16(i,cp);
145 90 return(i);
146 }
147  
148 u_int32_t
149 21 gint32(u_char * cp)
150 {
151 u_int32_t i;
152 21 NS_GET32(i,cp);
153 21 return(i);
154 }
155  
156 void
157 182 gput16(u_char * cp, unsigned int i)
158 {
159 182 NS_PUT16(i,cp);
160 182 }
161  
162 void
163 18 gput32(u_char * cp, u_int32_t v)
164 {
165 18 NS_PUT32(v,cp);
166 18 }
167  
168 u_char *
169 0 ns_ptr(int i)
170 {
171 0 i2p.s_addr = _res.nsaddr_list[i].sin_addr.s_addr;
172 0 return((u_char *)&i2p.s_addr);
173 }
174  
175 void
176 1 mysin()
177 {
178 #ifdef USELOOPBACK
179 mysa.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
180 #else
181 1 mysa.sin_addr.s_addr = INADDR_ANY;
182 #endif
183 1 }
184  
185 int
186 1 lchance()
187 {
188 #ifndef NO_RESOLV_CONF
189 1 return 0;
190 #else
191 #ifdef lastchanceTEST
192 my_res_state.options = RES_INIT;
193 if (res_ninit(&my_res_state) != 0) /* punt if we can not initialize resolver interface */
194 return 0;
195 return my_res_state.nscount;
196 #else
197 memset(&my_res_state,0,sizeof(my_res_state));
198 return get_nameservers(&my_res_state);
199 #endif
200 #endif
201 }
202  
203 MODULE = Net::DNS::ToolKit PACKAGE = Net::DNS::ToolKit
204  
205 PROTOTYPES: DISABLE
206  
207 # include functions for inet_aton, inet_ntoa, dn_expand
208  
209 INCLUDE: xs_include/dn_expand.inc
210  
211 # int dn_comp(unsigned char *exp_dn, unsigned char *comp_dn,
212 # int length, unsigned char **dnptrs, unsigned char **lastdnptr);
213 #
214 # dn_comp
215 # dn_comp() compresses the domain name exp_dn and stores it in
216 # the buffer comp_dn of length 'length'. The compression uses
217 # an array of pointers dnptrs to previously compressed names
218 # in the current message. The first pointer points to the
219 # beginning of the message and the list ends with NULL. The
220 # limit of the array is specified by lastdnptr. if dnptr
221 # is NULL, domain names are not compressed. If lastdnptr is
222 # NULL, the list of labels is not updated.
223 #
224  
225 void
226 dn_comp(buffer, offset, name,...)
227 SV * buffer
228 int offset
229 SV * name
230 PROTOTYPE: $$$;@
231 PREINIT:
232 AV * dptr;
233 SV **aptrs;
234 STRLEN len, size, bsize;
235 u_char **lastdnptr, **aoff;
236 u_char * exp_dn, * msg, * comp_dn;
237 int i, v, dnsize;
238 PPCODE:
239 56 ▶ if (! SvROK(buffer) || ! SvROK(name))
Branch: 2 branches
BranchTrueFalseTotal
if (! SvROK(buffer) || ! SvROK(name)) 56 0 56
if (! SvROK(buffer) || ! SvROK(name)) 0 56 56
240 0 XSRETURN_EMPTY;
241  
242 # see: perlapi on 'svtype' and /usr/lib/perl5/i386-linux/CORE/sv.h
243 56  
244 name = SvRV(name);
245 56 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
0 56 56
246 0 if (SvTYPE(name) == SVt_PVGV) /* debugging, skip dn_comp */
247 56 ▶ exp_dn = (u_char *)SvPV(GvSV(name), len);
Branch: 1 branch
BranchTrueFalseTotal
exp_dn = (u_char *)SvPV(GvSV(name), len); 56 0 56
248 56 if (SvPOK(name)) /* normal */
249 exp_dn = (u_char *)SvPV(name, len);
250 0 else /* punt, not scalar or glob */
251 XSRETURN_EMPTY;
252 56  
253 56 ▶ buffer = SvRV(buffer);
Branch: 1 branch
BranchTrueFalseTotal
buffer = SvRV(buffer); 0 56 56
254 0 if (! SvPOK(buffer))
255 XSRETURN_EMPTY;
256  
257 # get the size of the buffer
258 56 ▶ (void)SvPV(buffer,size);
Branch: 1 branch
BranchTrueFalseTotal
(void)SvPV(buffer,size); 0 56 56
259 0  
260 if (size != offset) /* punt if it does not match offset */
261 56 ▶ XSRETURN_EMPTY;
Branch: 2 branches
BranchTrueFalseTotal
XSRETURN_EMPTY; 29 27 56
XSRETURN_EMPTY; 25 4 29
262 56  
263 # add some space at the end of the string, get pointer
264 56 msg = (u_char *)SvGROW(buffer, (STRLEN)(size + MAXDNAME));
265 56 comp_dn = msg + offset;
266  
267 56 ▶ # setup dnptrs from outside or init them to zero
Branch: 3 branches
BranchTrueFalseTotal
# setup dnptrs from outside or init them to zero 38 18 56
# setup dnptrs from outside or init them to zero 25 13 38
# setup dnptrs from outside or init them to zero 25 0 25
268 dnsize = sizeof dnptrs/sizeof dnptrs[0];
269 25 lastdnptr = dnptrs + dnsize;
270  
271 25 if (items > 3 && SvTRUE(ST(3)) && SvROK(ST(3))) { /* defined, should be \@dnptrs */
272 25 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
0 25 25
273 0 dptr = (AV *)SvRV(ST(3)); /* array pointer */
274  
275 525 ▶ # external array must be exactly the same size as internal one
Branch: 1 branch
BranchTrueFalseTotal
# external array must be exactly the same size as internal one 500 25 525
276 500 i = av_len(dptr);
277 500 ▶ if ( i != dnsize -1)
Branch: 1 branch
BranchTrueFalseTotal
if ( i != dnsize -1) 0 500 500
278 0 XSRETURN_EMPTY;
279  
280 500 for(i=0;i<dnsize;i++) {
281 500 ▶ aptrs = av_fetch(dptr,i,0);
Branch: 2 branches
BranchTrueFalseTotal
aptrs = av_fetch(dptr,i,0); 475 25 500
aptrs = av_fetch(dptr,i,0); 28 447 475
282 53 if (aptrs == NULL) /* should never happen */
283 XSRETURN_EMPTY;
284 447  
285 v = SvIV(*aptrs);
286 if (i == 0 || v)
287 31 dnptrs[i] = msg + v;
288 31 else
289 dnptrs[i] = NULL;
290 }
291 56 ▶ } else {
Branch: 1 branch
BranchTrueFalseTotal
} else { 0 56 56
292 0 memset(dnptrs,0,sizeof(dnptrs));
293 56 dnptrs[0] = msg;
294 }
295 56  
296 if (SvTYPE(name) == SVt_PVGV)
297 56 ▶ dnptrs[0] = NULL; /* do not compress */
Branch: 2 branches
BranchTrueFalseTotal
dnptrs[0] = NULL; /* do not compress */ 56 0 56
dnptrs[0] = NULL; /* do not compress */ 0 56 56
298 56 len = dn_comp((char *)exp_dn,comp_dn,MAXDNAME,dnptrs,lastdnptr);
299 1176 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
1120 56 1176
300 1120 ▶ # set the string length to the new real length
Branch: 1 branch
BranchTrueFalseTotal
# set the string length to the new real length 980 140 1120
301 980 SvCUR_set(buffer, (I32)(size + len));
302  
303 140 EXTEND(SP, dnsize + 1);
304 PUSHs(sv_2mortal(newSViv(size + len )));
305 56 for(i=0;i<dnsize;i++) {
306 if (dnptrs[i] == NULL)
307 PUSHs(sv_2mortal(newSViv(0)));
308 else
309 PUSHs(sv_2mortal(newSViv(dnptrs[i] - msg)));
310 }
311 XSRETURN(dnsize + 1);
312  
313 # return the header values
314 # ID, QR, Opcode, AA, TC, RD, RA, MBZ, AD, CD, RCODE, QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT
315  
316 void
317 gethead(header)
318 SV * header
319 PROTOTYPE: $
320 PREINIT:
321 STRLEN len;
322 MY_HEADER * hp;
323 PPCODE:
324 19 ▶ if (! SvROK(header))
Branch: 1 branch
BranchTrueFalseTotal
if (! SvROK(header)) 0 19 19
325 0 XSRETURN_EMPTY;
326  
327 19 hp = (MY_HEADER *)SvPV(SvRV(header),len);
328 19 ▶ EXTEND(SP, 16);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 16); 0 19 19
329 19 PUSHs(sv_2mortal(newSViv(NS_HFIXEDSZ)));
330 19 PUSHs(sv_2mortal(newSViv(ntohs(hp->id))));
331 19 PUSHs(sv_2mortal(newSViv(hp->qr)));
332 19 PUSHs(sv_2mortal(newSViv(hp->opcode)));
333 19 PUSHs(sv_2mortal(newSViv(hp->aa)));
334 19 PUSHs(sv_2mortal(newSViv(hp->tc)));
335 19 PUSHs(sv_2mortal(newSViv(hp->rd)));
336 19 PUSHs(sv_2mortal(newSViv(hp->ra)));
337 19 PUSHs(sv_2mortal(newSViv(hp->z)));
338 19 PUSHs(sv_2mortal(newSViv(hp->ad)));
339 19 PUSHs(sv_2mortal(newSViv(hp->cd)));
340 19 PUSHs(sv_2mortal(newSViv(hp->rcode)));
341 19 PUSHs(sv_2mortal(newSViv(ntohs(hp->qdcount))));
342 19 PUSHs(sv_2mortal(newSViv(ntohs(hp->ancount))));
343 19 PUSHs(sv_2mortal(newSViv(ntohs(hp->nscount))));
344 19 PUSHs(sv_2mortal(newSViv(ntohs(hp->arcount))));
345 19 XSRETURN(16);
346  
347 void
348 parse_char(ch)
349 unsigned char ch
350 PROTOTYPE: $
351 PREINIT:
352 256 u_char bmask[] = {128,64,32,16,8,4,2,1};
353 256 unsigned int i, hi, lo, tens[] = {1000,100,10,1, 1000,100,10,1};
354 char out[15];
355 PPCODE:
356 256 hi = lo = 0;
357 1280 ▶ for(i=0;i<4;i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0;i<4;i++) { 1024 256 1280
358 1024 ▶ if (ch & bmask[i])
Branch: 1 branch
BranchTrueFalseTotal
if (ch & bmask[i]) 512 512 1024
359 512 hi += tens[i];
360 }
361 1280 ▶ for(i=4;i<8;i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=4;i<8;i++) { 1024 256 1280
362 1024 ▶ if (ch & bmask[i])
Branch: 1 branch
BranchTrueFalseTotal
if (ch & bmask[i]) 512 512 1024
363 512 lo += tens[i];
364 }
365 256 ▶ EXTEND(SP,4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP,4); 0 256 256
366 256 sprintf(out,"%04d_%04d",hi,lo);
367 256 PUSHs(sv_2mortal(newSVpv(out,0)));
368 256 i = (int)ch;
369 256 sprintf(out,"0x%02X",i);
370 256 PUSHs(sv_2mortal( newSVpv(out,0)));
371 256 sprintf(out,"%3d",i);
372 256 PUSHs(sv_2mortal(newSVpv(out,0)));
373 256 ▶ if (i < 0x20 || i > 0x7E) {
Branch: 2 branches
BranchTrueFalseTotal
if (i < 0x20 || i > 0x7E) { 224 32 256
if (i < 0x20 || i > 0x7E) { 129 95 224
374 161 sprintf(out,"%s","");
375 161 PUSHs(sv_2mortal(newSVpv(out,0)));
376 } else {
377 95 sprintf(out,"%c",ch);
378 95 PUSHs(sv_2mortal(newSVpv(out,0)));
379 }
380 256 XSRETURN(4);
381  
382 unsigned char
383 get1char(buffer,off)
384 SV * buffer
385 unsigned int off
386 PROTOTYPE: $$
387 PREINIT:
388 STRLEN size;
389 unsigned char * cp;
390 CODE:
391 2835 ▶ if (!SvROK(buffer)) /* not a pointer */
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(buffer)) /* not a pointer */ 0 2835 2835
392 1 XSRETURN_UNDEF;
393  
394 2835 cp = (u_char *)(SvPV(SvRV(buffer),size) + off);
395  
396 2835 ▶ if (size <= off) /* offset beyond end */
Branch: 1 branch
BranchTrueFalseTotal
if (size <= off) /* offset beyond end */ 1 2834 2835
397 1 XSRETURN_UNDEF;
398  
399 2834 ▶ RETVAL = *cp;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = *cp; 2796 38 2834
400 OUTPUT:
401 RETVAL
402  
403 void
404 getstring(buffer,off,len)
405 SV * buffer
406 unsigned int off
407 unsigned int len
408 PROTOTYPE: $$$
409 PREINIT:
410 STRLEN size;
411 unsigned char * cp;
412 SV * out;
413 PPCODE:
414 13 ▶ if (!SvROK(buffer)) /* not a pointer */
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(buffer)) /* not a pointer */ 0 13 13
415 0 XSRETURN_EMPTY;
416  
417 13 cp = (u_char *)(SvPV(SvRV(buffer),size) + off);
418  
419 13 ▶ if (off + len > size) /* offset beyond end */
Branch: 1 branch
BranchTrueFalseTotal
if (off + len > size) /* offset beyond end */ 0 13 13
420 0 XSRETURN_EMPTY;
421  
422 13 out = sv_newmortal();
423 13 sv_setpvn(out, (char *)cp, len );
424 13 ▶ XPUSHs(out);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(out); 0 13 13
425 13 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 13 0 13
426 13 ▶ XPUSHs(sv_2mortal(newSViv(off + len)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(off + len))); 0 13 13
427 13 XSRETURN(2);
428 }
429 0 XSRETURN(1);
430  
431 unsigned int
432 putstring(buffer,off,string)
433 SV * buffer
434 unsigned int off
435 SV * string
436 PROTOTYPE: $$$
437 PREINIT:
438 SV * buf;
439 STRLEN size, len;
440 unsigned char * cp, * bp;
441 CODE:
442 16 ▶ if (!SvROK(buffer)) /* not a pointer */
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(buffer)) /* not a pointer */ 0 16 16
443 0 XSRETURN_UNDEF;
444  
445 16 ▶ if (!SvROK(string)) /* not a pointer */
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(string)) /* not a pointer */ 0 16 16
446 0 XSRETURN_UNDEF;
447  
448 16 buf = SvRV(buffer);
449  
450 (void)SvPV(buf,size);
451  
452 16 ▶ if (off > size) /* not a valid offset */
Branch: 1 branch
BranchTrueFalseTotal
if (off > size) /* not a valid offset */ 0 16 16
453 0 XSRETURN_UNDEF;
454  
455 16 cp = (u_char *)SvPV(SvRV(string),len);
456  
457 16 ▶ if (off + len > MAXDNAME) /* too big to add */
Branch: 1 branch
BranchTrueFalseTotal
if (off + len > MAXDNAME) /* too big to add */ 0 16 16
458 0 XSRETURN_UNDEF;
459  
460 16 ▶ if (off < size)
Branch: 1 branch
BranchTrueFalseTotal
if (off < size) 2 14 16
461 2 SvCUR_set(buf,off);
462  
463 16 sv_catpvn(buf, (char *)cp, len);
464  
465 16 SvCUR_set(buf, (I32)(off + len));
466 16 ▶ RETVAL = off + len;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = off + len; 3 13 16
467 OUTPUT:
468 RETVAL
469  
470 # void
471 # get32
472 void
473 get16(buffer,off)
474 SV * buffer
475 unsigned int off
476 ALIAS:
477 Net::DNS::ToolKit::get32 = 1
478 PREINIT:
479 SV * out;
480 STRLEN size;
481 u_char * cp;
482 PPCODE:
483 114 ▶ if (GIMME_V == G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_VOID) 0 114 114
484 0 XSRETURN_UNDEF; /* punt, nothing to return */
485  
486 114 ▶ if (!SvROK(buffer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(buffer)) { 1 113 114
487 1 bail:
488 3 ▶ if (GIMME_V != G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_ARRAY) 3 0 3
489 3 XSRETURN_UNDEF;
490 else
491 0 XSRETURN_EMPTY;
492 }
493 113 cp = (u_char *)(SvPV(SvRV(buffer),size) + off);
494  
495 113 ▶ if (ix) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix) { 22 91 113
496 22 off += NS_INT32SZ;
497 22 ▶ if (off > size) /* punt if pointing beyond end of buff */
Branch: 1 branch
BranchTrueFalseTotal
if (off > size) /* punt if pointing beyond end of buff */ 1 21 22
498 1 goto bail;
499 21 ▶ XPUSHs(sv_2mortal(newSViv(gint32(cp))));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(gint32(cp)))); 0 21 21
500 } else {
501 91 off += NS_INT16SZ;
502 91 ▶ if (off > size) /* punt if pointing beyond end of buff */
Branch: 1 branch
BranchTrueFalseTotal
if (off > size) /* punt if pointing beyond end of buff */ 1 90 91
503 1 goto bail;
504 90 ▶ XPUSHs(sv_2mortal(newSViv(gint16(cp))));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(gint16(cp)))); 0 90 90
505 }
506 111 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 87 24 111
507 87 ▶ XPUSHs(sv_2mortal(newSViv(off)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(off))); 0 87 87
508 87 XSRETURN(2);
509 }
510 24 XSRETURN(1);
511  
512 # void
513 # put1char, put32
514 unsigned int
515 put16(buffer,off,val_long)
516 SV * buffer
517 unsigned int off
518 SV * val_long
519 ALIAS:
520 Net::DNS::ToolKit::put32 = 1
521 Net::DNS::ToolKit::put1char = 2
522 PREINIT:
523 STRLEN size;
524 U32 val;
525 478 ▶ unsigned int i, ns_size = NS_INT16SZ;
Branch: 1 branch
BranchTrueFalseTotal
unsigned int i, ns_size = NS_INT16SZ; 432 46 478
526 u_char c, * cp, blank[NS_INT32SZ];
527 CODE:
528 478 ▶ if (!SvROK(buffer))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(buffer)) 1 477 478
529 4 XSRETURN_UNDEF;
530  
531 477 buffer = SvRV(buffer);
532 (void)SvPV(buffer,size); /* get size of buffer */
533  
534 477 ▶ if (off > size) /* punt if pointing beyond end of buff */
Branch: 1 branch
BranchTrueFalseTotal
if (off > size) /* punt if pointing beyond end of buff */ 2 475 477
535 2 XSRETURN_UNDEF;
536  
537 475 val = SvUV(val_long);
538  
539 475 ▶ if (ix == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) 18 457 475
540 18 ns_size = NS_INT32SZ;
541 457 ▶ else if (ix == 2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 2) { 274 183 457
542 274 ▶ if (val > 255)
Branch: 1 branch
BranchTrueFalseTotal
if (val > 255) 0 274 274
543 0 XSRETURN_UNDEF;
544 274 ns_size = 1;
545 274 c = (u_char)val;
546 }
547 else {
548 183 ▶ if (val > 65535)
Branch: 1 branch
BranchTrueFalseTotal
if (val > 65535) 1 182 183
549 1 XSRETURN_UNDEF;
550 182 i = (unsigned int)val;
551 }
552  
553 474 ▶ if (off + ns_size > size) /* add space at end if needed */
Branch: 1 branch
BranchTrueFalseTotal
if (off + ns_size > size) /* add space at end if needed */ 400 74 474
554 400 sv_catpvn(buffer,(char *)blank,ns_size);
555  
556 474 cp = (u_char *)(SvPV(buffer,size) + off);
557  
558 474 ▶ if (ix == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) 18 456 474
559 18 gput32(cp,val);
560 456 ▶ else if (ix == 2)
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 2) 274 182 456
561 274 *cp = c;
562 else
563 182 gput16(cp,i);
564  
565 474 ▶ RETVAL = off + ns_size;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = off + ns_size; 262 212 474
566 OUTPUT:
567 RETVAL
568  
569 void
570 getIPv4(buffer,off)
571 SV * buffer
572 unsigned int off
573 PREINIT:
574 SV * netaddr;
575 STRLEN size;
576 u_char * cp, out[NS_INADDRSZ];
577 PPCODE:
578 10 ▶ if (GIMME_V == G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_VOID) 0 10 10
579 0 XSRETURN_UNDEF; /* punt, nothing to return */
580  
581 10 ▶ if (!SvROK(buffer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(buffer)) { 0 10 10
582 0 bail:
583 0 ▶ if (GIMME_V != G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_ARRAY) 0 0 0
584 0 XSRETURN_UNDEF;
585 else
586 0 XSRETURN_EMPTY;
587 }
588 10 cp = (u_char *)(SvPV(SvRV(buffer),size) + off);
589  
590 10 off += NS_INADDRSZ;
591 10 ▶ if (off > size) /* punt if pointing beyond end of buff */
Branch: 1 branch
BranchTrueFalseTotal
if (off > size) /* punt if pointing beyond end of buff */ 0 10 10
592 0 goto bail;
593
594 10 netaddr = sv_newmortal();
595 10 sv_setpvn(netaddr, (char *)cp, NS_INADDRSZ );
596 10 ▶ XPUSHs(netaddr);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(netaddr); 0 10 10
597 10 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 9 1 10
598 9 ▶ XPUSHs(sv_2mortal(newSViv( off)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv( off))); 0 9 9
599 9 XSRETURN(2);
600 }
601 1 XSRETURN(1);
602  
603 unsigned int
604 putIPv4(buffer,off,netaddr)
605 SV * buffer
606 unsigned int off
607 unsigned char * netaddr
608 PREINIT:
609 STRLEN size, discard;
610 u_char * cp, blank[NS_INADDRSZ];
611 CODE:
612 9 ▶ if (!SvROK(buffer))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(buffer)) 0 9 9
613 0 XSRETURN_UNDEF;
614  
615 9 buffer = SvRV(buffer);
616 (void)SvPV(buffer,size); /* get size of buffer */
617  
618 9 ▶ if (off > size) /* punt if pointing beyond end of buff */
Branch: 1 branch
BranchTrueFalseTotal
if (off > size) /* punt if pointing beyond end of buff */ 0 9 9
619 0 XSRETURN_UNDEF;
620  
621 9 ▶ if (off + NS_INADDRSZ > size)
Branch: 1 branch
BranchTrueFalseTotal
if (off + NS_INADDRSZ > size) 9 0 9
622 9 sv_catpvn(buffer,(char *)blank,NS_INADDRSZ); /* extend buffer if needed */
623  
624 9 cp = (u_char *)(SvPV(buffer, discard) + size);
625  
626 9 memcpy(cp,netaddr,NS_INADDRSZ);
627  
628 9 ▶ RETVAL = (int)(size + NS_INADDRSZ);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (int)(size + NS_INADDRSZ); 0 9 9
629 OUTPUT:
630 RETVAL
631  
632 void
633 getIPv6(buffer,off)
634 SV * buffer
635 unsigned int off
636 PREINIT:
637 SV * ipv6addr;
638 STRLEN size;
639 u_char * cp, out[NS_IN6ADDRSZ];
640 PPCODE:
641 3 ▶ if (GIMME_V == G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_VOID) 0 3 3
642 0 XSRETURN_UNDEF; /* punt, nothing to return */
643  
644 3 ▶ if (!SvROK(buffer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(buffer)) { 0 3 3
645 0 bail:
646 0 ▶ if (GIMME_V != G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_ARRAY) 0 0 0
647 0 XSRETURN_UNDEF;
648 else
649 0 XSRETURN_EMPTY;
650 }
651 3 cp = (u_char *)(SvPV(SvRV(buffer),size) + off);
652  
653 3 off += NS_IN6ADDRSZ;
654 3 ▶ if (off > size) /* punt if pointing beyond end of buff */
Branch: 1 branch
BranchTrueFalseTotal
if (off > size) /* punt if pointing beyond end of buff */ 0 3 3
655 0 goto bail;
656
657 3 ipv6addr = sv_newmortal();
658 3 sv_setpvn(ipv6addr, (char *)cp, NS_IN6ADDRSZ );
659 3 ▶ XPUSHs(ipv6addr);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ipv6addr); 0 3 3
660 3 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 2 1 3
661 2 ▶ XPUSHs(sv_2mortal(newSViv( off)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv( off))); 0 2 2
662 2 XSRETURN(2);
663 }
664 1 XSRETURN(1);
665  
666 unsigned int
667 putIPv6(buffer,off,ipv6addr)
668 SV * buffer
669 unsigned int off
670 unsigned char * ipv6addr
671 PREINIT:
672 STRLEN size, discard;
673 u_char * cp, blank[NS_IN6ADDRSZ];
674 CODE:
675 2 ▶ if (!SvROK(buffer))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(buffer)) 0 2 2
676 0 XSRETURN_UNDEF;
677  
678 2 buffer = SvRV(buffer);
679 (void)SvPV(buffer,size); /* get size of buffer */
680  
681 2 ▶ if (off > size) /* punt if pointing beyond end of buff */
Branch: 1 branch
BranchTrueFalseTotal
if (off > size) /* punt if pointing beyond end of buff */ 0 2 2
682 0 XSRETURN_UNDEF;
683  
684 2 ▶ if (off + NS_IN6ADDRSZ > size)
Branch: 1 branch
BranchTrueFalseTotal
if (off + NS_IN6ADDRSZ > size) 2 0 2
685 2 sv_catpvn(buffer,(char *)blank,NS_IN6ADDRSZ); /* extend buffer if needed */
686  
687 2 cp = (u_char *)(SvPV(buffer, discard) + size);
688  
689 2 memcpy(cp,ipv6addr,NS_IN6ADDRSZ);
690  
691 2 ▶ RETVAL = (int)(size + NS_IN6ADDRSZ);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (int)(size + NS_IN6ADDRSZ); 0 2 2
692 OUTPUT:
693 RETVAL
694  
695 void
696 gettimeofday()
697 PREINIT:
698 SV * tmp; /* older perl does not know about newSVuv */
699 PPCODE:
700 100005 ▶ if (gettimeofday(&tv,NULL)) { /* any error */
Branch: 1 branch
BranchTrueFalseTotal
if (gettimeofday(&tv,NULL)) { /* any error */ 0 100005 100005
701 0 ▶ if (GIMME_V == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) 0 0 0
702 0 XSRETURN_EMPTY;
703 else
704 0 XSRETURN_UNDEF;
705 }
706 100005 tmp = newSViv(tv.tv_sec);
707 100005 sv_setuv(tmp,tv.tv_sec);
708 100005 ▶ XPUSHs(sv_2mortal(tmp));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(tmp)); 0 100005 100005
709 100005 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 4 100001 100005
710 4 tmp = newSViv(tv.tv_usec);
711 4 sv_setuv(tmp,tv.tv_usec);
712 4 ▶ XPUSHs(sv_2mortal(tmp));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(tmp)); 0 4 4
713 4 XSRETURN(2);
714 }
715 100001 XSRETURN(1);
716  
717 void
718 get_default()
719 PPCODE:
720 1 mysin();
721 1 ▶ XPUSHs(sv_2mortal(newSVpvn((char *)&mysa.sin_addr, NS_INADDRSZ)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn((char *)&mysa.sin_addr, NS_INADDRSZ))); 0 1 1
722 1 XSRETURN(1);
723  
724 void
725 get_path()
726 PREINIT:
727 SV * out;
728 PPCODE:
729 3 ▶ if (path == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (path == NULL) 0 3 3
730 0 XSRETURN_UNDEF;
731 3 out = sv_newmortal();
732 3 sv_setpvn(out, path, (STRLEN)pathz);
733 3 ▶ XPUSHs(out);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(out); 0 3 3
734 3 XSRETURN(1);
735  
736 void
737 lastchance()
738 PREINIT:
739 int i, nscount;
740 u_char * netptr;
741 PPCODE:
742 1 ▶ if ((nscount = lchance()) < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ((nscount = lchance()) < 1) { 1 0 1
743 1 ▶ if (GIMME_V != G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_ARRAY) 0 1 1
744 0 XSRETURN_UNDEF;
745 else
746 1 XSRETURN_EMPTY;
747 }
748 0 ▶ if (GIMME_V != G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_ARRAY) 0 0 0
749 0 nscount = 1;
750  
751 0 ▶ for(i=0;i<nscount;i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0;i<nscount;i++) { 0 0 0
752 0 netptr = ns_ptr(i);
753 0 ▶ XPUSHs(sv_2mortal(newSVpvn((char *)netptr, NS_INADDRSZ)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn((char *)netptr, NS_INADDRSZ))); 0 0 0
754 }
755 0 XSRETURN(nscount);
« xs_include/dn_expand.inc ↑ Summary blib/lib/Net/DNS/ToolKit/Debug.pm »