choocroot has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I would like to override the new() and accept() method of the IO::Socket::INET object in order to implement some basic "Access Control List" deny/allow rules.

I sucessfully made a preliminary IO::ACLSocket::INET package that inherit the IO::Socket::INET object and provide this ACL mechanism (add the rules when constructing the object with new(), or with addAllow()/addDeny() method, and automatically deny or allow the connection when calling accept()).

So, I would like to find a way to override directly the IO::Socket::INET methods in order to tranparently use these "ACL" socket with the HTTP::Daemon package for example, and anything that use IO::Socket::INET.

I can't rename my IO::ACLSocket::INET package to IO::Socket::INET, as it break everything, and I don't want to modify directly the whole .../IO/Socket/INET.pm file.

Is this possible ? What Perl mechanism should I use ?

Thanks.

  • Comment on Overriding/extending IO::Socket::INET methods

Replies are listed 'Best First'.
Re: Overriding/extending IO::Socket::INET methods
by Corion (Patriarch) on May 06, 2002 at 18:10 UTC

    I also did implement an IO::Socket variation that limits the throughput to an arbitrary number of bytes per second. The problem I face is, that while it is quite easy to implement a subclass of IO::Socket, it dosen't work if any part of the program uses the filehandle instead of the object methods - and HTTP::Daemon does just that. You can pass the accept() method of HTTP::Daemon the name of the socket subclass you want created, but it won't get you far until you create a tied subclass that behaves like a filehandle.

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web