# this file is included by all plugins, their is nu usefullness in
# running it standalone!

use FileHandle;

sub OpenSocket {
# Make a Berkeley socket connection between this program and a TCP port
#  on another (or this) host. Port can be a number or a named service
#
  local($OtherHostname, $Port) = @_;
  local($OurHostname, $sockaddr, $name, $aliases, $proto, $type, $len,
        $ThisAddr, $that);
  local @RemoteHostname = gethostbyname($OtherHostname); 
  $OurHostname = "localhost";
 
  @RemoteHostname || return 0; 
 
  ($name, $aliases, $proto) = getprotobyname('tcp'); 
  ($name, $aliases, $Port) = getservbyname($Port, 'tcp') unless $Port =~ /^\d+$/; 
  ($name, $aliases, $type, $len, $ThisAddr) = gethostbyname($OurHostname); 
  ($name, $aliases, $type, $len, $OtherHostAddr) = @RemoteHostname; 

  $sockaddr = 'S n a4 x8';    # Format for packed network address
  $that = pack($sockaddr, &AF_INET, $Port, $OtherHostAddr);

  $result = socket(S, &PF_INET, &SOCK_STREAM, $proto) || return 0;

  $result = connect(S, $that) || return 0;

  S->autoflush(1);			# set S to be un-buffered  
  return 1;                           	# success
}

return 1;
