File Coverage

blib/lib/Net/P0f/Backend/Socket.pm
Criterion Covered Total %
statement 12 27 44.4
branch 0 4 0.0
condition 0 3 0.0
subroutine 4 8 50.0
pod 4 4 100.0
total 20 46 43.4


line stmt bran cond sub pod time code
1             package Net::P0f::Backend::Socket;
2 1     1   1256 use strict;
  1         2  
  1         44  
3 1     1   5 use Carp;
  1         2  
  1         76  
4 1     1   1506 use Socket;
  1         4821  
  1         760  
5              
6 1     1   13 { no strict;
  1         3  
  1         367  
7             $VERSION = 0.02;
8             @ISA = qw(Net::P0f);
9             }
10              
11             =head1 NAME
12              
13             Net::P0f::Backend::Socket - Back-end for C 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.
29             It provides an interface to pilot the C utility using its
30             local-socket.
31              
32             See L 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 during the object creation.
42              
43             B
44              
45             =over 4
46              
47             =item *
48              
49             C - indicates the path to the socket which can be used
50             to query a P0f process.
51              
52             =back
53              
54             =cut
55              
56             sub init {
57 0     0 1   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 0 0 0       exists $self->{options}{$opt} ?
66             ( $self->{options}{$opt} = $opts{$opt} and delete $opts{$opt} )
67             : carp "warning: Unknown option '$opt'";
68             }
69             }
70              
71             =item run()
72              
73             =cut
74              
75             sub run {
76 0     0 1   my $self = shift;
77 0           die "*** ",(caller(0))[3]," not implemented ***\n";
78 0 0         croak "fatal: Please set the path to the socket with the 'socket_path' option"
79             unless $self->{options}{socket_path};
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             sub encode_p0f_query {
102 0     0 1   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             sub decode_p0f_response {
114 0     0 1   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 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
159              
160             =head1 AUTHOR
161              
162             SEbastien Aperghis-Tramoni Esebastien@aperghis.netE
163              
164             =head1 BUGS
165              
166             Please report any bugs or feature requests to
167             L, or through the web interface at
168             L.
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 SEbastien 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             1; # End of Net::P0f::Backend::Socket