Annotation of embedaddon/strongswan/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Transport.pm, revision 1.1.1.1

1.1       misho       1: package Vici::Transport;
                      2: 
                      3: our $VERSION = '0.9';
                      4: 
                      5: use strict;
                      6: 
                      7: sub new {
                      8:     my $class = shift;
                      9:     my $self = {
                     10:         Socket => shift,
                     11:     };
                     12:     bless($self, $class);
                     13:     return $self;
                     14: }
                     15: 
                     16: sub send {
                     17:     my ($self, $data) = @_;
                     18:     my $packet = pack('N/a*', $data);
                     19:     $self->{'Socket'}->send($packet);
                     20: }
                     21: 
                     22: sub receive {
                     23:     my $self = shift;
                     24:     my $packet_header;
                     25: 
                     26:     $packet_header = $self->_recv_all(4);
                     27:     my $packet_len = unpack('N', $packet_header);
                     28:     return $self->_recv_all($packet_len);
                     29: }
                     30: 
                     31: sub _recv_all {
                     32:     my ($self, $len) = @_;
                     33:     my $data;
                     34: 
                     35:     while ($len)
                     36:     {
                     37:         my $buf;
                     38:         unless (defined $self->{'Socket'}->recv($buf, $len))
                     39:         {
                     40:             die "error reading from socket\n";
                     41:         }
                     42:         $len -= length($buf);
                     43:         $data .= $buf;
                     44:     }
                     45:     return $data;
                     46: }
                     47: 
                     48: 1;
                     49: __END__
                     50: =head1 NAME
                     51: 
                     52: Vici::Transport - Perl extension for communicating via a strongSwan VICI socket
                     53: 
                     54: =head1 SYNOPSIS
                     55: 
                     56: use Vici::Transport;
                     57: 
                     58: =head1 DESCRIPTION
                     59: 
                     60: The Vici::Transport module is needed by the Vici::Packet module to send
                     61: and receive packets over the UNIX socket used in the communication with the
                     62: open source strongSwan IPsec daemon (https://www.strongswan.com) via the
                     63: documented Versatile IKE Configuration Interface (VICI). VICI allows the
                     64: onfiguration, management and monitoring of multiple IPsec connections.
                     65: 
                     66: =head2 EXPORT
                     67: 
                     68: None by default.
                     69: 
                     70: =head1 SEE ALSO
                     71: 
                     72: strongSwan Wiki:  https://wiki.strongswan.org/projects/strongswan/wiki/Vici
                     73: 
                     74: strongSwan Mailing list:  users@lists.strongswan.org
                     75: 
                     76: =head1 AUTHOR
                     77: 
                     78: Andreas Steffen, E<lt>andreas.steffen@strongswan.orgE<gt>
                     79: 
                     80: =head1 COPYRIGHT AND LICENSE
                     81: 
                     82: Copyright (C) 2015 by Andreas Steffen
                     83: 
                     84: Permission is hereby granted, free of charge, to any person obtaining a copy
                     85: of this software and associated documentation files (the "Software"), to deal
                     86: in the Software without restriction, including without limitation the rights
                     87: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
                     88: copies of the Software, and to permit persons to whom the Software is
                     89: furnished to do so, subject to the following conditions:
                     90: 
                     91: The above copyright notice and this permission notice shall be included in
                     92: all copies or substantial portions of the Software.
                     93: 
                     94: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
                     95: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
                     96: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
                     97: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
                     98: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
                     99: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
                    100: THE SOFTWARE.
                    101: 
                    102: =cut
                    103: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>