P0f/Backend/Socket.pm

filter: Statementstmt 51.6% 16 / 31 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod 100% 4 / 4 totaltotal 46.1% 24 / 52 CC 5 SCAR 21.2
CC
5
Cov
42%
init
20.0
run
6.0
encode_p0f_query
2.0
CRAP 8.3
« P0f/Backend/XS.pm ↑ Summary P0f.pm »
1 package Net::P0f::Backend::Socket;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶{ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $VERSION = 0.02;
8 2 @ISA = qw(Net::P0f);
9 }
10  
11 =head1 NAME
12  
13 Net::P0f::Backend::Socket - Back-end for C<Net::P0f> that links to the P0f library
14  
15 =head1 VERSION
16  
17 Version 0.01
18  
19 =head1 SYNOPSIS
20  
21 use Net::P0f;
22  
23 my $p0f = Net::P0f->new(backend => 'socket', socket_path => '/var/run/p0f.sock');
24 ...
25  
26 =head1 DESCRIPTION
27  
28 This module is a back-end helper for B<Net::P0f>.
29 It provides an interface to pilot the C<p0f(1)> utility using its
30 local-socket.
31  
32 See L<Net::P0f> for more general information and examples.
33  
34 =head1 METHODS
35  
36 =over 4
37  
38 =item init()
39  
40 This method initialize the backend-specific part of the object.
41 It is automatically called by C<Net::P0f> during the object creation.
42  
43 B<Options>
44  
45 =over 4
46  
47 =item *
48  
49 C<socket_path> - indicates the path to the socket which can be used
50 to query a P0f process.
51  
52 =back
53  
54 =cut
55  
56 0 ▶sub init {
Subroutine init: not called CC=4 SCAR=30.0
Pod documented
57 0 my $self = shift;
58 0 my %opts = @_;
59  
60 # declare my specific options
61 #$self->{options}{XXX} = '';
62
63 # initialize my options
64 0 for my $opt (keys %opts) {
65 exists $self->{options}{$opt} ?
66 0 ▶ ( $self->{options}{$opt} = $opts{$opt} and delete $opts{$opt} )
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'options'}{$opt} ? : 0 0 0
Condition0%0/3
$self->{"options"}{$opt} = $opts{$opt} and delete $opts{$opt}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"options"}{$opt} = $opts{$opt} and delete $opts{$opt}
$self->{"options"}{$opt} = $opts{$opt} delete $opts{$opt}
Truth table0%0/3
A and B
A= $self->{"options"}{$opt} = $opts{$opt}B= delete $opts{$opt}
ABresult
0X0
100
111
67 : carp "warning: Unknown option '$opt'";
68 }
69 }
70  
71 =item run()
72  
73 =cut
74  
75 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
76 0 my $self = shift;
77 0 die "*** ",(caller(0))[3]," not implemented ***\n";
78 croak "fatal: Please set the path to the socket with the 'socket_path' option"
79 0 ▶ unless $self->{options}{socket_path};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"options"}{"socket_path"} 0 0 0
80 }
81  
82  
83 #
84 # P0f types <-> pack()
85 # ====================
86 # _u8 C unsigned char
87 # _u16 S unsigned short
88 # _u32 I unsigned int
89 # _u64 Q unsigned quad
90 #
91 # _s8 c signed char
92 # _s16 s signed short
93 # _s32 i signed int
94 # _s64 q signed quad
95 #
96  
97 =item encode_p0f_query()
98  
99 =cut
100  
101 0 ▶sub encode_p0f_query {
Subroutine encode_p0f_query: not called CC=1 SCAR=6.9
Pod documented
102 0 my $magic = 0x0defaced;
103 0 my($id,$src_addr,$dest_addr,$src_port,$dest_port) = @_;
104 0 $src_addr = inet_aton($src_addr);
105 0 $dest_addr = inet_aton($dest_addr);
106 0 return pack('IIIISS', $magic,$id,$src_addr,$dest_addr,$src_port,$dest_port)
107 }
108  
109 =item decode_p0f_response()
110  
111 =cut
112  
113 0 ▶sub decode_p0f_response {
Subroutine decode_p0f_response: not called CC=1 SCAR=6.9
Pod documented
114 0 my $packet = shift;
115 0 my($magic,$id,$type,$genre,$detail,$dist,$link,$tos,$fw,$nat,$real,$score,
116 $mflags,$uptime) = unpack('IICA20A40cA30A30CCCsSi', $packet);
117 0 return ($id,$type,$genre,$detail,$dist,$link,$tos,$fw,$nat,
118 $real,$score,$mflags,$uptime)
119 }
120  
121 =back
122  
123 =head1 DIAGNOSTICS
124  
125 These messages are classified as follows (listed in increasing order of
126 desperatin):
127  
128 =over 4
129  
130 =item *
131  
132 B<(W)> A warning, usually caused by bad user data.
133  
134 =item *
135  
136 B<(E)> An error caused by external code.
137  
138 =item *
139  
140 B<(F)> A fatal error caused by the code of this module.
141  
142 =back
143  
144 =over 4
145  
146 =item Please set the path to the socket with the 'socket_path' option
147  
148 B<(F)> You must set the C<socket_path> option with the path to the socket.
149  
150 =item Unknown option '%s'
151  
152 B<(W)> You called an accesor which does not correspond to a known option.
153  
154 =back
155  
156 =head1 SEE ALSO
157  
158 L<Net::P0f>
159  
160 =head1 AUTHOR
161  
162 SE<eacute>bastien Aperghis-Tramoni E<lt>sebastien@aperghis.netE<gt>
163  
164 =head1 BUGS
165  
166 Please report any bugs or feature requests to
167 L<bug-net-p0f-xs@rt.cpan.org>, or through the web interface at
168 L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-P0f>.
169 I will be notified, and then you'll automatically be notified
170 of progress on your bug as I make changes.
171  
172 =head1 ACKNOWLEDGEMENTS
173  
174 =head1 COPYRIGHT & LICENSE
175  
176 Copyright 2004 SE<eacute>bastien Aperghis-Tramoni, All Rights Reserved.
177  
178 This program is free software; you can redistribute it and/or modify it
179 under the same terms as Perl itself.
180  
181 =cut
182  
183 2 1; # End of Net::P0f::Backend::Socket
« P0f/Backend/XS.pm ↑ Summary P0f.pm »