diff --git a/lib/modules/Protocols.pmod/Ident.pmod b/lib/modules/Protocols.pmod/Ident.pmod index 2c4c0bbc6c77f0418e6ccd2462a52beefed7e5cb..9c48a1e0ec908f9d0666c02a09b69ac9fdbb08f7 100644 --- a/lib/modules/Protocols.pmod/Ident.pmod +++ b/lib/modules/Protocols.pmod/Ident.pmod @@ -1,57 +1,54 @@ // An implementation of the IDENT protocol, specified in RFC 931. // -// $Id: Ident.pmod,v 1.2 1998/04/08 05:53:40 neotron Exp $ +// $Id: Ident.pmod,v 1.3 1998/04/08 17:25:12 neotron Exp $ -class client { +int|array (string) lookup(object fd) +{ + mixed raddr; // Remote Address. + mixed laddr; // Local Address. + array err; + object remote_fd; + if(!fd) + return 0; + err = catch(raddr = fd->query_address()); + if(err) + throw(err + ({"Error in Protocols.Ident:"})); + err = catch(laddr = fd->query_address(1)); + if(err) + throw(err + ({"Error in Protocols.Ident:" })); + if(!raddr || !laddr) + throw(backtrace() +({ "Protocols.Ident - cannot lookup address"})); - int|array (string) lookup(object fd) - { - mixed raddr; // Remote Address. - mixed laddr; // Local Address. - array err; - object remote_fd; - if(!fd) - return 0; - err = catch(raddr = fd->query_address()); - if(err) - throw(err + ({"Error in Protocols.Ident:"})); - err = catch(laddr = fd->query_address(1)); - if(err) - throw(err + ({"Error in Protocols.Ident:" })); - if(!raddr || !laddr) - throw(backtrace() +({ "Protocols.Ident - cannot lookup address"})); - - laddr = laddr / " "; - raddr = raddr / " "; + laddr = laddr / " "; + raddr = raddr / " "; - remote_fd = Stdio.File(); - if(!remote_fd->open_socket()) { - destruct(remote_fd); - throw(backtrace() +({ "Protocols.Ident: open_socket() failed."})); - } - if(err = catch(remote_fd->connect(raddr[0], 113))) - { - destruct(remote_fd); - throw(err); - } - if(remote_fd->write(raddr[1]+","+laddr[1]+"\r\n") == -1) { - destruct(remote_fd); - throw(backtrace() +({ "Protocols.Ident: write failed."})); - } - mixed response = remote_fd->read(); - if(!response || !strlen(response)) - { - destruct(remote_fd); - throw(backtrace() +({ "Protocols.Ident: read failed."})); - } - remote_fd->close(); + remote_fd = Stdio.File(); + if(!remote_fd->open_socket(0, laddr[0])) { + destruct(remote_fd); + throw(backtrace() +({ "Protocols.Ident: open_socket() failed."})); + } + if(err = catch(remote_fd->connect(raddr[0], 113))) + { + destruct(remote_fd); + throw(err); + } + if(remote_fd->write(raddr[1]+","+laddr[1]+"\r\n") == -1) { + destruct(remote_fd); + throw(backtrace() +({ "Protocols.Ident: write failed."})); + } + mixed response = remote_fd->read(); + if(!response || !strlen(response)) + { destruct(remote_fd); - response -= " "; - response -= "\r\n"; - response /= ":"; - if(sizeof(response) < 2) - return ({ "ERROR", "UNKNOWN-ERROR" }); - return response[1..]; + throw(backtrace() +({ "Protocols.Ident: read failed."})); } + remote_fd->close(); + destruct(remote_fd); + response -= " "; + response -= "\r\n"; + response /= ":"; + if(sizeof(response) < 2) + return ({ "ERROR", "UNKNOWN-ERROR" }); + return response[1..]; }