NAME

Net::Ident - lookup the username on the remote end of a TCP/IP connection

SYNOPSIS

use Net::Ident;

$username = Net::Ident::lookup(SOCKET, $timeout);

$username = Net::Ident::lookupFromInAddr($localsockaddr,
                                          $remotesockaddr, $timeout);

$obj = Net::Ident->new(SOCKET, $timeout);
$obj = Net::Ident->newFromInAddr($localsockaddr, $remotesockaddr,
                                       $timeout);
$status = $obj->query;
$status = $obj->ready;
$username = $obj->username;
($username, $opsys, $error) = $obj->username;
$fh = $obj->getfh;
$txt = $obj->geterror;

use Net::Ident 'ident_lookup';

$username = ident_lookup(SOCKET, $timeout);

use Net::Ident 'lookupFromInAddr';

$username = lookupFromInAddr($localsockaddr, $remotesockaddr, $timeout);

use Net::Ident ':fh';

$username = SOCKET->ident_lookup($timeout);

use Net::Ident ':apache';

# my Apache $r;
$c = $r->connection;
$username = $c->ident_lookup($timeout);

OVERVIEW

Net::Ident is a module that looks up the username on the remote side of a TCP/IP connection through the ident (auth/tap) protocol described in RFC1413 (which supersedes RFC931). Note that this requires the remote site to run a daemon (often called identd) to provide the requested information, so it is not always available for all TCP/IP connections.

DESCRIPTION

You can either use the simple interface, which does one ident lookup at a time, or use the asynchronous interface to perform (possibly) many simultaneous lookups, or simply continue serving other things while the lookup is proceeding.

Simple Interface

The simple interface comes in four varieties. An object oriented method call of a FileHandle object, an object oriented method of an Apache::Connection object, and as one of two different simple subroutine calls. Other than the calling method, these routines behave exactly the same.

What these functions return depends on the context:

EXAMPLE

The following code is a complete example, implementing a server that waits for a connection on a port, tells you who you are and what time it is, and closes the connection again. The majority of the code will look very familiar if you just read perlipc.

Excersize this server by telnetting to it, preferably from a machine that has a suitable ident daemon installed.

#!/usr/bin/perl -w

use Net::Ident;
# uncomment the below line if you want lots of debugging info
# $Net::Ident::DEBUG = 2;
use Socket;
use strict;

sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }

my $port = shift || 2345;
my $proto = getprotobyname('tcp');
socket(Server, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) or
  die "setsockopt: $!";
bind(Server, sockaddr_in($port, INADDR_ANY)) or die "bind: $!";
listen(Server,SOMAXCONN) or die "listen: $!";

logmsg "server started on port $port";

my $paddr;

for ( ; $paddr = accept(Client,Server); close Client) {
    my($port,$iaddr) = sockaddr_in($paddr);
    my $name = gethostbyaddr($iaddr,AF_INET) || inet_ntoa($iaddr);
    logmsg "connection from $name [" . inet_ntoa($iaddr) .
      "] at port $port";
   
    my $username = Client->ident_lookup(30) || "~unknown";
    logmsg "User at $name:$port is $username";
    
    print Client "Hello there, $username\@$name, it's now ",
       scalar localtime, "\n";
}

Asynchronous Interface

The asynchronous interface is meant for those who know the ins and outs of the select() call (the 4-argument version of select(), but I didn't need saying that, did I?). This interface is completely object oriented. The following methods are available:

An asynchronous example implementing the above server in a multi-threaded way via select, is left as an excersize for the interested reader.

DISCLAIMER

I make NO WARRANTY or representation, either express or implied, with respect to this software, its quality, accuracy, merchantability, or fitness for a particular purpose. This software is provided "AS IS", and you, its user, assume the entire risk as to its quality and accuracy.

AUTHOR

Jan-Pieter Cornet, johnpc@xs4all.nl

COPYRIGHT

Copyright (c) 1995, 1997, 1999 Jan-Pieter Cornet. All rights reserved. You can distribute and use this program under the same terms as Perl itself.

REVISION HISTORY

SEE ALSO

Socket RFC1413, RFC931