<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># IO::Socket::UNIX.pm
#
# Copyright (c) 1997-8 Graham Barr &lt;gbarr@pobox.com&gt;. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.

package IO::Socket::UNIX;

use strict;
use IO::Socket;
use Carp;

our @ISA = qw(IO::Socket);
our $VERSION = "1.40";

IO::Socket::UNIX-&gt;register_domain( AF_UNIX );

sub new {
    my $class = shift;
    unshift(@_, "Peer") if @_ == 1;
    return $class-&gt;SUPER::new(@_);
}

sub configure {
    my($sock,$arg) = @_;
    my($bport,$cport);

    my $type = $arg-&gt;{Type} || SOCK_STREAM;

    $sock-&gt;socket(AF_UNIX, $type, 0) or
	return undef;

    if(exists $arg-&gt;{Local}) {
	my $addr = sockaddr_un($arg-&gt;{Local});
	$sock-&gt;bind($addr) or
	    return undef;
    }
    if(exists $arg-&gt;{Listen} &amp;&amp; $type != SOCK_DGRAM) {
	$sock-&gt;listen($arg-&gt;{Listen} || 5) or
	    return undef;
    }
    elsif(exists $arg-&gt;{Peer}) {
	my $addr = sockaddr_un($arg-&gt;{Peer});
	$sock-&gt;connect($addr) or
	    return undef;
    }

    $sock;
}

sub hostpath {
    @_ == 1 or croak 'usage: $sock-&gt;hostpath()';
    my $n = $_[0]-&gt;sockname || return undef;
    (sockaddr_un($n))[0];
}

sub peerpath {
    @_ == 1 or croak 'usage: $sock-&gt;peerpath()';
    my $n = $_[0]-&gt;peername || return undef;
    (sockaddr_un($n))[0];
}

1; # Keep require happy

__END__

</pre></body></html>