NetIpXs.xs

filter: Statementstmt 89.6% 276 / 308 Branchbran 76.5% 176 / 230 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 84.0% 452 / 538 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« object.c ↑ Summary functions.c »
1 /*
2 NetIpXs.xs - XS wrapper around the core Net::IP::XS functions.
3  
4 Copyright (C) 2010-2023 Tom Harrison <tomhrr@cpan.org>
5 Original inet_pton4, inet_pton6 are Copyright (C) 2006 Free Software
6 Foundation.
7 Original interface, and the auth and ip_auth functions, are Copyright
8 (C) 1999-2002 RIPE NCC.
9  
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14  
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19  
20 You should have received a copy of the GNU General Public License along
21 with this program; if not, write to the Free Software Foundation, Inc.,
22 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24  
25 #include "EXTERN.h"
26 #include "perl.h"
27 #include "XSUB.h"
28  
29 #include <stdio.h>
30 #include <ctype.h>
31 #include <stdarg.h>
32 #include <stdlib.h>
33  
34 #include "inet_pton.h"
35 #include "functions.h"
36 #include "object.h"
37  
38 MODULE = Net::IP::XS::N128 PACKAGE = Net::IP::XS::N128 PREFIX = net_ip_xs_n128
39  
40 SV *
41 new(package)
42 char *package
43 PREINIT:
44 HV *stash;
45 SV *ref;
46 SV *num_ref;
47 n128_t num;
48 CODE:
49 43 stash = gv_stashpv("Net::IP::XS::N128", 1);
50 43 n128_set_ui(&num, 0);
51 43 num_ref = newSVpv((const char*) &num, 16);
52 43 ref = newRV_noinc(num_ref);
53 43 sv_bless(ref, stash);
54 43 RETVAL = ref;
55 OUTPUT:
56 RETVAL
57  
58 int
59 set_ui(self, ui)
60 SV *self
61 unsigned int ui
62 PREINIT:
63 STRLEN len;
64 n128_t num;
65 CODE:
66 88 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 88 88
67 0 RETVAL = 0;
68 } else {
69 88 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
70 88 n128_set_ui(&num, ui);
71 88 sv_setpvn(SvRV(self), (const char*) &num, 16);
72 88 RETVAL = 1;
73 }
74 OUTPUT:
75 RETVAL
76  
77 int
78 set_binstr(self, binstr)
79 SV *self
80 const char *binstr
81 PREINIT:
82 STRLEN len;
83 n128_t num;
84 CODE:
85 7 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 7 7
86 0 RETVAL = 0;
87 } else {
88 7 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
89 7 n128_set_str_binary(&num, binstr, strlen(binstr));
90 7 sv_setpvn(SvRV(self), (const char*) &num, 16);
91 7 RETVAL = 1;
92 }
93 OUTPUT:
94 RETVAL
95  
96 int
97 set_decstr(self, decstr)
98 SV *self
99 const char *decstr
100 PREINIT:
101 STRLEN len;
102 n128_t num;
103 CODE:
104 39 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 39 39
105 0 RETVAL = 0;
106 } else {
107 39 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
108 39 n128_set_str_decimal(&num, decstr, strlen(decstr));
109 39 sv_setpvn(SvRV(self), (const char*) &num, 16);
110 39 RETVAL = 1;
111 }
112 OUTPUT:
113 RETVAL
114  
115 int
116 cmp_ui(self, ui)
117 SV *self
118 unsigned int ui
119 PREINIT:
120 STRLEN len;
121 n128_t num;
122 CODE:
123 49 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 49 49
124 0 RETVAL = 0;
125 } else {
126 49 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
127 49 RETVAL = n128_cmp_ui(&num, ui);
128 }
129 OUTPUT:
130 RETVAL
131  
132 int
133 cmp(self, other)
134 SV *self
135 SV *other
136 PREINIT:
137 STRLEN len;
138 n128_t num1;
139 n128_t num2;
140 CODE:
141 28 ▶ if (!sv_isa(self, "Net::IP::XS::N128")
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128") 28 0 28
142 28 ▶ || !sv_isa(other, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_isa(other, "Net::IP::XS::N128")) { 0 28 28
143 0 RETVAL = 0;
144 } else {
145 28 Copy(SvPV(SvRV(self), len), &num1, 1, n128_t);
146 28 ▶ Copy(SvPV(SvRV(other), len), &num2, 1, n128_t);
Branch: 1 branch
BranchTrueFalseTotal
Copy(SvPV(SvRV(other), len), &num2, 1, n128_t); 28 0 28
147 28 RETVAL = n128_cmp(&num1, &num2);
148 }
149 OUTPUT:
150 RETVAL
151  
152 int
153 blsft(self, shift)
154 SV *self
155 int shift
156 PREINIT:
157 STRLEN len;
158 n128_t num;
159 CODE:
160 16 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 16 16
161 0 RETVAL = 0;
162 } else {
163 16 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
164 16 n128_blsft(&num, shift);
165 16 sv_setpvn(SvRV(self), (const char*) &num, 16);
166 16 RETVAL = 1;
167 }
168 OUTPUT:
169 RETVAL
170  
171 int
172 brsft(self, shift)
173 SV *self
174 int shift
175 PREINIT:
176 STRLEN len;
177 n128_t num;
178 CODE:
179 8 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 8 8
180 0 RETVAL = 0;
181 } else {
182 8 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
183 8 n128_brsft(&num, shift);
184 8 sv_setpvn(SvRV(self), (const char*) &num, 16);
185 8 RETVAL = 1;
186 }
187 OUTPUT:
188 RETVAL
189  
190 int
191 band(self, other)
192 SV *self
193 SV *other
194 PREINIT:
195 STRLEN len;
196 n128_t num1;
197 n128_t num2;
198 CODE:
199 2 ▶ if (!sv_isa(self, "Net::IP::XS::N128")
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128") 2 0 2
200 2 ▶ || !sv_isa(other, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_isa(other, "Net::IP::XS::N128")) { 0 2 2
201 0 RETVAL = 0;
202 } else {
203 2 Copy(SvPV(SvRV(self), len), &num1, 1, n128_t);
204 2 ▶ Copy(SvPV(SvRV(other), len), &num2, 1, n128_t);
Branch: 1 branch
BranchTrueFalseTotal
Copy(SvPV(SvRV(other), len), &num2, 1, n128_t); 2 0 2
205 2 n128_and(&num1, &num2);
206 2 sv_setpvn(SvRV(self), (const char*) &num1, 16);
207 2 RETVAL = 1;
208 }
209 OUTPUT:
210 RETVAL
211  
212 int
213 bior(self, other)
214 SV *self
215 SV *other
216 PREINIT:
217 STRLEN len;
218 n128_t num1;
219 n128_t num2;
220 CODE:
221 3 ▶ if (!sv_isa(self, "Net::IP::XS::N128")
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128") 3 0 3
222 3 ▶ || !sv_isa(other, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_isa(other, "Net::IP::XS::N128")) { 0 3 3
223 0 RETVAL = 0;
224 } else {
225 3 Copy(SvPV(SvRV(self), len), &num1, 1, n128_t);
226 3 ▶ Copy(SvPV(SvRV(other), len), &num2, 1, n128_t);
Branch: 1 branch
BranchTrueFalseTotal
Copy(SvPV(SvRV(other), len), &num2, 1, n128_t); 3 0 3
227 3 n128_ior(&num1, &num2);
228 3 sv_setpvn(SvRV(self), (const char*) &num1, 16);
229 3 RETVAL = 1;
230 }
231 OUTPUT:
232 RETVAL
233  
234 int
235 bxor(self, other)
236 SV *self
237 SV *other
238 PREINIT:
239 STRLEN len;
240 n128_t num1;
241 n128_t num2;
242 CODE:
243 3 ▶ if (!sv_isa(self, "Net::IP::XS::N128")
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128") 3 0 3
244 3 ▶ || !sv_isa(other, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_isa(other, "Net::IP::XS::N128")) { 0 3 3
245 0 RETVAL = 0;
246 } else {
247 3 Copy(SvPV(SvRV(self), len), &num1, 1, n128_t);
248 3 ▶ Copy(SvPV(SvRV(other), len), &num2, 1, n128_t);
Branch: 1 branch
BranchTrueFalseTotal
Copy(SvPV(SvRV(other), len), &num2, 1, n128_t); 3 0 3
249 3 n128_xor(&num1, &num2);
250 3 sv_setpvn(SvRV(self), (const char*) &num1, 16);
251 3 RETVAL = 1;
252 }
253 OUTPUT:
254 RETVAL
255  
256 int
257 badd(self, other)
258 SV *self
259 SV *other
260 PREINIT:
261 STRLEN len;
262 n128_t num1;
263 n128_t num2;
264 CODE:
265 13 ▶ if (!sv_isa(self, "Net::IP::XS::N128")
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128") 13 0 13
266 13 ▶ || !sv_isa(other, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_isa(other, "Net::IP::XS::N128")) { 0 13 13
267 0 RETVAL = 0;
268 } else {
269 13 Copy(SvPV(SvRV(self), len), &num1, 1, n128_t);
270 13 ▶ Copy(SvPV(SvRV(other), len), &num2, 1, n128_t);
Branch: 1 branch
BranchTrueFalseTotal
Copy(SvPV(SvRV(other), len), &num2, 1, n128_t); 13 0 13
271 13 n128_add(&num1, &num2);
272 13 sv_setpvn(SvRV(self), (const char*) &num1, 16);
273 13 RETVAL = 1;
274 }
275 OUTPUT:
276 RETVAL
277  
278 int
279 bsub(self, other)
280 SV *self
281 SV *other
282 PREINIT:
283 STRLEN len;
284 n128_t num1;
285 n128_t num2;
286 CODE:
287 9 ▶ if (!sv_isa(self, "Net::IP::XS::N128")
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128") 9 0 9
288 9 ▶ || !sv_isa(other, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_isa(other, "Net::IP::XS::N128")) { 0 9 9
289 0 RETVAL = 0;
290 } else {
291 9 Copy(SvPV(SvRV(self), len), &num1, 1, n128_t);
292 9 ▶ Copy(SvPV(SvRV(other), len), &num2, 1, n128_t);
Branch: 1 branch
BranchTrueFalseTotal
Copy(SvPV(SvRV(other), len), &num2, 1, n128_t); 9 0 9
293 9 n128_sub(&num1, &num2);
294 9 sv_setpvn(SvRV(self), (const char*) &num1, 16);
295 9 RETVAL = 1;
296 }
297 OUTPUT:
298 RETVAL
299  
300 int
301 badd_ui(self, ui)
302 SV *self
303 unsigned int ui
304 PREINIT:
305 STRLEN len;
306 n128_t num;
307 CODE:
308 6 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 6 6
309 0 RETVAL = 0;
310 } else {
311 6 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
312 6 n128_add_ui(&num, ui);
313 6 sv_setpvn(SvRV(self), (const char*) &num, 16);
314 6 RETVAL = 1;
315 }
316 OUTPUT:
317 RETVAL
318  
319 int
320 bnot(self)
321 SV *self
322 PREINIT:
323 STRLEN len;
324 n128_t num;
325 CODE:
326 4 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 4 4
327 0 RETVAL = 0;
328 } else {
329 4 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
330 4 n128_com(&num);
331 4 sv_setpvn(SvRV(self), (const char*) &num, 16);
332 4 RETVAL = 1;
333 }
334 OUTPUT:
335 RETVAL
336  
337 int
338 tstbit(self, bit)
339 SV *self
340 int bit
341 PREINIT:
342 STRLEN len;
343 n128_t num;
344 CODE:
345 513 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 513 513
346 0 RETVAL = 0;
347 } else {
348 513 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
349 513 RETVAL = n128_tstbit(&num, bit);
350 }
351 OUTPUT:
352 RETVAL
353  
354 int
355 setbit(self, bit)
356 SV *self
357 int bit
358 PREINIT:
359 STRLEN len;
360 n128_t num;
361 CODE:
362 146 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 146 146
363 0 RETVAL = 0;
364 } else {
365 146 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
366 146 n128_setbit(&num, bit);
367 146 sv_setpvn(SvRV(self), (const char*) &num, 16);
368 146 RETVAL = 1;
369 }
370 OUTPUT:
371 RETVAL
372  
373 int
374 clrbit(self, bit)
375 SV *self
376 int bit
377 PREINIT:
378 STRLEN len;
379 n128_t num;
380 CODE:
381 129 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 129 129
382 0 RETVAL = 0;
383 } else {
384 129 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
385 129 n128_clrbit(&num, bit);
386 129 sv_setpvn(SvRV(self), (const char*) &num, 16);
387 129 RETVAL = 1;
388 }
389 OUTPUT:
390 RETVAL
391  
392 SV *
393 bstr(self)
394 SV *self
395 PREINIT:
396 STRLEN len;
397 n128_t num;
398 char buf[40];
399 CODE:
400 12 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 12 12
401 0 RETVAL = &PL_sv_undef;
402 } else {
403 12 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
404 12 n128_print_dec(&num, buf);
405 12 RETVAL = newSVpv(buf, 0);
406 }
407 OUTPUT:
408 RETVAL
409  
410 SV *
411 as_hex(self)
412 SV *self
413 PREINIT:
414 STRLEN len;
415 n128_t num;
416 char buf[40];
417 CODE:
418 0 ▶ if (!sv_isa(self, "Net::IP::XS::N128")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS::N128")) { 0 0 0
419 0 RETVAL = &PL_sv_undef;
420 } else {
421 0 Copy(SvPV(SvRV(self), len), &num, 1, n128_t);
422 0 n128_print_hex(&num, buf);
423 0 RETVAL = newSVpv(buf, 0);
424 }
425 OUTPUT:
426 RETVAL
427  
428 MODULE = Net::IP::XS PACKAGE = Net::IP::XS
429  
430 PROTOTYPES: ENABLE
431  
432 SV *
433 ip_get_Error(data)
434 void *data
435 CODE:
436 55 RETVAL = newSVpv(NI_get_Error(), 0);
437 OUTPUT:
438 RETVAL
439  
440 void
441 ip_set_Error(data, str)
442 void *data
443 char *str
444 CODE:
445 3 NI_set_Error(str);
446  
447 SV *
448 ip_get_Errno(data)
449 void *data
450 CODE:
451 58 RETVAL = newSViv(NI_get_Errno());
452 OUTPUT:
453 RETVAL
454  
455 void
456 ip_set_Errno(data, num)
457 void *data
458 int num
459 CODE:
460 3 NI_set_Errno(num);
461  
462 SV *
463 ip_is_ipv4(ip)
464 char *ip
465 CODE:
466 21 RETVAL = newSViv(NI_ip_is_ipv4(ip));
467 OUTPUT:
468 RETVAL
469  
470 SV *
471 ip_is_ipv6(ip)
472 char *ip
473 CODE:
474 13 RETVAL = newSViv(NI_ip_is_ipv6(ip));
475 OUTPUT:
476 RETVAL
477  
478 SV *
479 ip_binadd(begin, end)
480 char *begin
481 char *end
482 PREINIT:
483 char buf[IPV6_BITSTR_LEN];
484 int res;
485 CODE:
486 13 buf[0] = '\0';
487 13 res = NI_ip_binadd(begin, end, buf, IPV6_BITSTR_LEN);
488 13 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 9 4 13
489 OUTPUT:
490 RETVAL
491  
492 SV *
493 ip_get_prefix_length(bin1, bin2)
494 char *bin1
495 char *bin2
496 PREINIT:
497 int res;
498 int result;
499 CODE:
500 15 res = NI_ip_get_prefix_length(bin1, bin2, &result);
501 15 ▶ RETVAL = (res) ? newSViv(result) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSViv(result) : &PL_sv_undef; 14 1 15
502 OUTPUT:
503 RETVAL
504  
505 void
506 ip_splitprefix(prefix)
507 char *prefix
508 PREINIT:
509 char buf[MAX_IPV6_STR_LEN];
510 int len;
511 int res;
512 PPCODE:
513 13 res = NI_ip_splitprefix(prefix, buf, &len);
514 13 ▶ if (res) {
Branch: 1 branch
BranchTrueFalseTotal
if (res) { 4 9 13
515 4 ▶ XPUSHs(sv_2mortal(newSVpv(buf, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(buf, 0))); 0 4 4
516 4 ▶ XPUSHs(sv_2mortal(newSViv(len)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(len))); 0 4 4
517 }
518  
519 SV *
520 ip_is_valid_mask(mask, ipversion)
521 char *mask
522 int ipversion
523 PREINIT:
524 int res;
525 CODE:
526 9 res = NI_ip_is_valid_mask(mask, ipversion);
527 9 ▶ RETVAL = (res) ? newSViv(1) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSViv(1) : &PL_sv_undef; 4 5 9
528 OUTPUT:
529 RETVAL
530  
531 SV *
532 ip_expand_address(ip, ipversion)
533 char *ip
534 int ipversion
535 PREINIT:
536 int res;
537 char buf[MAX_IPV6_STR_LEN];
538 CODE:
539 54 buf[0] = '\0';
540 54 res = NI_ip_expand_address(ip, ipversion, buf);
541 54 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 41 13 54
542 OUTPUT:
543 RETVAL
544  
545 SV *
546 ip_bincomp(begin, op_arg, end)
547 char *begin
548 char *op_arg
549 char *end
550 PREINIT:
551 int res;
552 int result;
553 CODE:
554 25 res = NI_ip_bincomp(begin, op_arg, end, &result);
555 25 ▶ RETVAL = (res) ? newSViv(result) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSViv(result) : &PL_sv_undef; 22 3 25
556 OUTPUT:
557 RETVAL
558  
559 SV *
560 ip_get_mask(len, ipversion)
561 int len
562 int ipversion
563 PREINIT:
564 int res;
565 char buf[128];
566 CODE:
567 10 res = NI_ip_get_mask(len, ipversion, buf);
568 10 ▶ RETVAL = (res) ? newSVpv(buf, NI_iplengths(ipversion)) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, NI_iplengths(ipversion)) : &PL_sv_undef; 9 1 10
569 OUTPUT:
570 RETVAL
571  
572 SV *
573 ip_last_address_bin(binip, len, ipversion)
574 char *binip
575 int len
576 int ipversion
577 PREINIT:
578 char buf[128];
579 int res;
580 CODE:
581 8 res = NI_ip_last_address_bin(binip, len, ipversion, buf);
582 8 ▶ RETVAL = (res) ? newSVpv(buf, NI_iplengths(ipversion)) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, NI_iplengths(ipversion)) : &PL_sv_undef; 7 1 8
583 OUTPUT:
584 RETVAL
585  
586 SV *
587 ip_get_version(ip)
588 char *ip
589 PREINIT:
590 int res;
591 CODE:
592 4 res = NI_ip_get_version(ip);
593 4 ▶ RETVAL = (res) ? newSViv(res) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSViv(res) : &PL_sv_undef; 3 1 4
594 OUTPUT:
595 RETVAL
596  
597 SV *
598 ip_inttobin_str(str, ipversion)
599 char *str
600 int ipversion
601 PREINIT:
602 char buf[129];
603 int res;
604 CODE:
605 13 res = NI_ip_inttobin_str(str, ipversion, buf);
606 13 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 11 2 13
607 OUTPUT:
608 RETVAL
609  
610 SV *
611 ip_bintoint_str(binip)
612 char *binip
613 PREINIT:
614 char buf[MAX_IPV6_NUM_STR_LEN];
615 CODE:
616 10 NI_ip_bintoint_str(binip, buf);
617 10 RETVAL = newSVpv(buf, 0);
618 OUTPUT:
619 RETVAL
620  
621 SV *
622 ip_iplengths(ipversion)
623 int ipversion
624 PREINIT:
625 int res;
626 CODE:
627 4 res = NI_iplengths(ipversion);
628 4 ▶ RETVAL = (res) ? newSViv(res) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSViv(res) : &PL_sv_undef; 2 2 4
629 OUTPUT:
630 RETVAL
631  
632  
633 SV *
634 ip_bintoip(ip, ipversion)
635 char *ip
636 int ipversion
637 PREINIT:
638 char buf[MAX_IPV6_STR_LEN];
639 int res;
640 CODE:
641 12 buf[0] = '\0';
642 12 res = NI_ip_bintoip(ip, ipversion, buf);
643 12 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 10 2 12
644 OUTPUT:
645 RETVAL
646  
647 SV *
648 ip_iptobin(ip, ipversion)
649 char *ip
650 int ipversion
651 PREINIT:
652 char buf[128];
653 int res;
654 CODE:
655 184 res = NI_ip_iptobin(ip, ipversion, buf);
656 184 RETVAL = (res) ? newSVpv(buf, NI_iplengths(ipversion))
657 184 ▶ : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef; 174 10 184
658 OUTPUT:
659 RETVAL
660  
661 SV *
662 ip_is_overlap(b1, e1, b2, e2)
663 char *b1
664 char *e1
665 char *b2
666 char *e2
667 PREINIT:
668 int res;
669 int result;
670 CODE:
671 23 res = NI_ip_is_overlap(b1, e1, b2, e2, &result);
672 23 ▶ RETVAL = (res) ? newSViv(result) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSViv(result) : &PL_sv_undef; 18 5 23
673 OUTPUT:
674 RETVAL
675  
676 SV *
677 ip_check_prefix(ip, len, ipversion)
678 char *ip
679 int len
680 int ipversion
681 PREINIT:
682 int res;
683 CODE:
684 6 res = NI_ip_check_prefix(ip, len, ipversion);
685 6 ▶ RETVAL = (res) ? newSViv(res) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSViv(res) : &PL_sv_undef; 2 4 6
686 OUTPUT:
687 RETVAL
688  
689 void
690 ip_range_to_prefix(begin, end, ipversion)
691 char *begin
692 char *end
693 int ipversion
694 PREINIT:
695 char *prefixes[MAX_PREFIXES];
696 int pcount;
697 int res;
698 int i;
699 PPCODE:
700 16 pcount = 0;
701 16 res = NI_ip_range_to_prefix(begin, end, ipversion, prefixes, &pcount);
702 16 ▶ if (!res) {
Branch: 1 branch
BranchTrueFalseTotal
if (!res) { 3 13 16
703 3 ▶ for (i = 0; i < pcount; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < pcount; i++) { 0 3 3
704 0 free(prefixes[i]);
705 }
706 3 ST(0) = &PL_sv_undef;
707 } else {
708 224 ▶ for (i = 0; i < pcount; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < pcount; i++) { 211 13 224
709 211 ▶ XPUSHs(sv_2mortal(newSVpv(prefixes[i], 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(prefixes[i], 0))); 0 211 211
710 211 free(prefixes[i]);
711 }
712 }
713  
714 SV *
715 ip_get_embedded_ipv4(ipv6)
716 char *ipv6
717 PREINIT:
718 char buf[16];
719 int res;
720 CODE:
721 8 res = NI_ip_get_embedded_ipv4(ipv6, buf);
722 8 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 4 4 8
723 OUTPUT:
724 RETVAL
725  
726 SV *
727 ip_aggregate(b1, e1, b2, e2, ipversion)
728 char *b1
729 char *e1
730 char *b2
731 char *e2
732 int ipversion
733 PREINIT:
734 char buf[MAX_IPV6_RANGE_STR_LEN];
735 int res;
736 CODE:
737 14 res = NI_ip_aggregate(b1, e1, b2, e2, ipversion, buf);
738 14 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 7 7 14
739 OUTPUT:
740 RETVAL
741  
742 void
743 ip_prefix_to_range(ip, len, version)
744 char *ip
745 int len
746 int version
747 PREINIT:
748 char buf[MAX_IPV6_RANGE_STR_LEN];
749 int res;
750 PPCODE:
751 22 res = NI_ip_prefix_to_range(ip, len, version, buf);
752 22 ▶ if (res) {
Branch: 1 branch
BranchTrueFalseTotal
if (res) { 19 3 22
753 19 ▶ XPUSHs(sv_2mortal(newSVpv(ip, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(ip, 0))); 0 19 19
754 19 ▶ XPUSHs(sv_2mortal(newSVpv(buf, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(buf, 0))); 0 19 19
755 } else {
756 3 ST(0) = &PL_sv_undef;
757 }
758  
759 SV *
760 ip_reverse(ip, len, ipversion)
761 char *ip
762 int len
763 int ipversion
764 PREINIT:
765 char buf[MAX_IPV6_REVERSE_LEN];
766 int res;
767 CODE:
768 30 buf[0] = '\0';
769 30 res = NI_ip_reverse(ip, len, ipversion, buf);
770 30 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 23 7 30
771 OUTPUT:
772 RETVAL
773  
774 void
775 ip_normalize(ip)
776 char *ip
777 PREINIT:
778 char buf1[MAX_IPV6_STR_LEN];
779 char buf2[MAX_IPV6_STR_LEN];
780 int res;
781 PPCODE:
782 55 buf1[0] = '\0';
783 55 buf2[0] = '\0';
784 55 res = NI_ip_normalize(ip, buf1, buf2);
785 55 ▶ if (res >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (res >= 1) { 31 24 55
786 31 ▶ XPUSHs(sv_2mortal(newSVpv(buf1, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(buf1, 0))); 0 31 31
787 }
788 55 ▶ if (res >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (res >= 2) { 29 26 55
789 29 ▶ XPUSHs(sv_2mortal(newSVpv(buf2, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(buf2, 0))); 0 29 29
790 }
791  
792 SV *
793 ip_normal_range(ip)
794 char *ip
795 PREINIT:
796 char buf[MAX_IPV6_NORMAL_RANGE];
797 int res;
798 CODE:
799 9 res = NI_ip_normal_range(ip, buf);
800 9 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 6 3 9
801 OUTPUT:
802 RETVAL
803  
804 SV *
805 ip_compress_address(ip, version)
806 char *ip
807 int version
808 PREINIT:
809 char buf[MAX_IPV6_STR_LEN];
810 int res;
811 CODE:
812 18 buf[0] = '\0';
813 18 res = NI_ip_compress_address(ip, version, buf);
814 18 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 16 2 18
815 OUTPUT:
816 RETVAL
817  
818 SV *
819 ip_compress_v4_prefix(ip, len)
820 char *ip
821 int len
822 PREINIT:
823 char buf[MAX_IPV4_RANGE_STR_LEN];
824 int res;
825 CODE:
826 16 buf[0] = '\0';
827 16 res = NI_ip_compress_v4_prefix(ip, len, buf,
828 MAX_IPV4_RANGE_STR_LEN);
829 16 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 12 4 16
830 OUTPUT:
831 RETVAL
832  
833 SV *
834 ip_iptype(ip, ipversion)
835 char *ip
836 int ipversion
837 PREINIT:
838 char buf[MAX_TYPE_STR_LEN];
839 int res;
840 CODE:
841 10 res = NI_ip_iptype(ip, ipversion, buf);
842 10 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 9 1 10
843 OUTPUT:
844 RETVAL
845  
846 SV *
847 new(package, data, ...)
848 char *package
849 char *data
850 PREINIT:
851 HV *stash;
852 HV *hash;
853 SV *ref;
854 int res;
855 int ipversion;
856 CODE:
857 135 ▶ ipversion = (items > 2) ? SvIV(ST(2)) : 0;
Branch: 1 branch
BranchTrueFalseTotal
ipversion = (items > 2) ? SvIV(ST(2)) : 0; 48 87 135
858 135 hash = newHV();
859 135 ref = newRV_noinc((SV*) hash);
860 135 stash = gv_stashpv(package, 1);
861 135 sv_bless(ref, stash);
862 135 res = NI_set(ref, data, ipversion);
863 135 ▶ if (!res) {
Branch: 1 branch
BranchTrueFalseTotal
if (!res) { 8 127 135
864 8 SvREFCNT_dec(ref);
865 8 RETVAL = &PL_sv_undef;
866 } else {
867 127 RETVAL = ref;
868 }
869 OUTPUT:
870 RETVAL
871  
872 SV *
873 print(self)
874 SV *self
875 PREINIT:
876 char buf[MAX_IPV6_NORMAL_RANGE];
877 int res;
878 CODE:
879 8 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 7 8
880 1 RETVAL = &PL_sv_undef;
881 } else {
882 7 res = NI_print(self, buf, MAX_IPV6_NORMAL_RANGE);
883 7 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 5 2 7
884 }
885 OUTPUT:
886 RETVAL
887  
888 SV *
889 size_str(self)
890 SV *self
891 PREINIT:
892 char buf[MAX_IPV6_NUM_STR_LEN];
893 int res;
894 CODE:
895 20 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 19 20
896 1 RETVAL = &PL_sv_undef;
897 } else {
898 19 res = NI_size_str(self, buf);
899 19 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 17 2 19
900 }
901 OUTPUT:
902 RETVAL
903  
904 SV *
905 intip_str(self)
906 SV *self
907 PREINIT:
908 char buf[MAX_IPV6_NUM_STR_LEN];
909 int res;
910 CODE:
911 20 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 19 20
912 1 RETVAL = &PL_sv_undef;
913 } else {
914 19 res = NI_intip_str(self, buf, MAX_IPV6_NUM_STR_LEN);
915 19 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 17 2 19
916 }
917 OUTPUT:
918 RETVAL
919  
920 SV *
921 hexip(self)
922 SV *self
923 PREINIT:
924 char buf[MAX_IPV6_HEXIP_STR_LEN];
925 int res;
926 CODE:
927 8 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 7 8
928 1 RETVAL = &PL_sv_undef;
929 } else {
930 7 res = NI_hexip(self, buf, MAX_IPV6_HEXIP_STR_LEN);
931 7 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 5 2 7
932 }
933 OUTPUT:
934 RETVAL
935  
936 SV *
937 hexmask(self)
938 SV *self
939 PREINIT:
940 char buf[MAX_IPV6_HEXIP_STR_LEN];
941 int res;
942 CODE:
943 8 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 7 8
944 1 RETVAL = &PL_sv_undef;
945 } else {
946 7 res = NI_hexmask(self, buf, MAX_IPV6_HEXIP_STR_LEN);
947 7 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 6 1 7
948 }
949 OUTPUT:
950 RETVAL
951  
952 SV *
953 prefix(self)
954 SV *self
955 PREINIT:
956 char buf[MAX_IPV6_RANGE_STR_LEN];
957 int res;
958 CODE:
959 9 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 8 9
960 1 RETVAL = &PL_sv_undef;
961 } else {
962 8 res = NI_prefix(self, buf, MAX_IPV6_RANGE_STR_LEN);
963 8 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 6 2 8
964 }
965 OUTPUT:
966 RETVAL
967  
968 SV *
969 mask(self)
970 SV *self
971 PREINIT:
972 char buf[128];
973 int res;
974 CODE:
975 10 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 9 10
976 1 RETVAL = &PL_sv_undef;
977 } else {
978 9 res = NI_mask(self, buf, 128);
979 9 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 6 3 9
980 }
981 OUTPUT:
982 RETVAL
983  
984 SV *
985 iptype(self)
986 SV *self
987 PREINIT:
988 char buf[MAX_TYPE_STR_LEN];
989 int res;
990 CODE:
991 8 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 7 8
992 1 RETVAL = &PL_sv_undef;
993 } else {
994 7 res = NI_iptype(self, buf, MAX_TYPE_STR_LEN);
995 7 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 5 2 7
996 }
997 OUTPUT:
998 RETVAL
999  
1000 SV *
1001 reverse_ip(self)
1002 SV *self
1003 PREINIT:
1004 char buf[MAX_IPV6_REVERSE_LEN];
1005 int res;
1006 CODE:
1007 7 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 6 7
1008 1 RETVAL = &PL_sv_undef;
1009 } else {
1010 6 buf[0] = '\0';
1011 6 res = NI_reverse_ip(self, buf);
1012 6 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 4 2 6
1013 }
1014 OUTPUT:
1015 RETVAL
1016  
1017 SV *
1018 last_bin(self)
1019 SV *self
1020 PREINIT:
1021 char buf[IPV6_BITSTR_LEN];
1022 int res;
1023 CODE:
1024 14 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 13 14
1025 1 RETVAL = &PL_sv_undef;
1026 } else {
1027 13 buf[0] = '\0';
1028 13 res = NI_last_bin(self, buf, IPV6_BITSTR_LEN);
1029 13 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 10 3 13
1030 }
1031 OUTPUT:
1032 RETVAL
1033  
1034 SV *
1035 last_int_str(self)
1036 SV *self
1037 PREINIT:
1038 char buf[MAX_IPV6_NUM_STR_LEN];
1039 int res;
1040 CODE:
1041 19 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 18 19
1042 1 RETVAL = &PL_sv_undef;
1043 } else {
1044 18 buf[0] = '\0';
1045 18 res = NI_last_int_str(self, buf, MAX_IPV6_NUM_STR_LEN);
1046 18 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 16 2 18
1047 }
1048 OUTPUT:
1049 RETVAL
1050  
1051 SV *
1052 last_ip(self)
1053 SV *self
1054 PREINIT:
1055 char buf[MAX_IPV6_STR_LEN];
1056 int res;
1057 CODE:
1058 10 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 9 10
1059 1 RETVAL = &PL_sv_undef;
1060 } else {
1061 9 buf[0] = '\0';
1062 9 res = NI_last_ip(self, buf, MAX_IPV6_STR_LEN);
1063 9 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 8 1 9
1064 }
1065 OUTPUT:
1066 RETVAL
1067  
1068 SV *
1069 short(self)
1070 SV *self
1071 PREINIT:
1072 char buf[MAX_IPV6_STR_LEN];
1073 int res;
1074 CODE:
1075 35 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 34 35
1076 1 RETVAL = &PL_sv_undef;
1077 } else {
1078 34 buf[0] = '\0';
1079 34 res = NI_short(self, buf);
1080 34 ▶ RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSVpv(buf, 0) : &PL_sv_undef; 34 0 34
1081 }
1082 OUTPUT:
1083 RETVAL
1084  
1085 SV *
1086 bincomp(self, op, other)
1087 SV *self
1088 char *op
1089 SV *other
1090 PREINIT:
1091 int res;
1092 int result;
1093 CODE:
1094 5 ▶ if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) { 4 1 5
if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) { 0 4 4
1095 1 RETVAL = &PL_sv_undef;
1096 } else {
1097 4 res = NI_bincomp(self, op, other, &result);
1098 4 ▶ RETVAL = (res) ? newSViv(result) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSViv(result) : &PL_sv_undef; 3 1 4
1099 }
1100 OUTPUT:
1101 RETVAL
1102  
1103 SV *
1104 binadd(self, other)
1105 SV *self
1106 SV *other
1107 PREINIT:
1108 SV *new_ip;
1109 CODE:
1110 5 ▶ if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) { 4 1 5
if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) { 0 4 4
1111 1 RETVAL = &PL_sv_undef;
1112 } else {
1113 4 new_ip = NI_binadd(self, other);
1114 4 ▶ RETVAL = (new_ip) ? new_ip : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (new_ip) ? new_ip : &PL_sv_undef; 3 1 4
1115 }
1116 OUTPUT:
1117 RETVAL
1118  
1119 SV *
1120 aggregate(self, other)
1121 SV *self
1122 SV *other
1123 PREINIT:
1124 SV *new_ip;
1125 CODE:
1126 6 ▶ if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) { 5 1 6
if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) { 1 4 5
1127 2 RETVAL = &PL_sv_undef;
1128 } else {
1129 4 new_ip = NI_aggregate(self, other);
1130 4 ▶ RETVAL = (new_ip) ? new_ip : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (new_ip) ? new_ip : &PL_sv_undef; 2 2 4
1131 }
1132 OUTPUT:
1133 RETVAL
1134  
1135 SV *
1136 overlaps(self, other)
1137 SV *self
1138 SV *other
1139 PREINIT:
1140 int res;
1141 int result;
1142 CODE:
1143 12 ▶ if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) { 11 1 12
if (!sv_isa(self, "Net::IP::XS") || !sv_isa(other, "Net::IP::XS")) { 0 11 11
1144 1 RETVAL = &PL_sv_undef;
1145 } else {
1146 11 res = NI_overlaps(self, other, &result);
1147 11 ▶ RETVAL = (res) ? newSViv(result) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSViv(result) : &PL_sv_undef; 10 1 11
1148 }
1149 OUTPUT:
1150 RETVAL
1151  
1152 void
1153 find_prefixes(self)
1154 SV *self
1155 PREINIT:
1156 char *prefixes[MAX_PREFIXES];
1157 int pcount;
1158 int res;
1159 int i;
1160 PPCODE:
1161 2 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 1 2
1162 1 ST(0) = &PL_sv_undef;
1163 } else {
1164 1 pcount = 0;
1165 1 res = NI_find_prefixes(self, prefixes, &pcount);
1166 1 ▶ if (!res) {
Branch: 1 branch
BranchTrueFalseTotal
if (!res) { 1 0 1
1167 1 ▶ for (i = 0; i < pcount; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < pcount; i++) { 0 1 1
1168 0 free(prefixes[i]);
1169 }
1170 1 ST(0) = &PL_sv_undef;
1171 } else {
1172 0 ▶ for (i = 0; i < pcount; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < pcount; i++) { 0 0 0
1173 0 ▶ XPUSHs(sv_2mortal(newSVpv(prefixes[i], 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(prefixes[i], 0))); 0 0 0
1174 0 free(prefixes[i]);
1175 }
1176 }
1177 }
1178  
1179 SV *
1180 ip_add_num(self, num, unused)
1181 SV *self
1182 char *num
1183 SV *unused
1184 PREINIT:
1185 SV *new_ip;
1186 CODE:
1187 786 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 1 785 786
1188 1 RETVAL = &PL_sv_undef;
1189 } else {
1190 785 new_ip = NI_ip_add_num(self, num);
1191 785 ▶ RETVAL = (new_ip) ? new_ip : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (new_ip) ? new_ip : &PL_sv_undef; 774 11 785
1192 }
1193 OUTPUT:
1194 RETVAL
1195  
1196 SV *
1197 set_ipv6_n128s(self)
1198 SV *self
1199 PREINIT:
1200 int res;
1201 CODE:
1202 0 ▶ if (!sv_isa(self, "Net::IP::XS")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isa(self, "Net::IP::XS")) { 0 0 0
1203 0 RETVAL = &PL_sv_undef;
1204 } else {
1205 0 res = NI_set_ipv6_n128s(self);
1206 0 ▶ RETVAL = (res) ? newSViv(1) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (res) ? newSViv(1) : &PL_sv_undef; 0 0 0
1207 }
1208 OUTPUT:
1209 RETVAL
« object.c ↑ Summary functions.c »