#!/usr/bin/env perl -w
# ``The contents of this file are subject to the Erlang Public License,
# Version 1.1, (the "License"); you may not use this file except in
# compliance with the License. You should have received a copy of the
# Erlang Public License along with this software. If not, it can be
# retrieved via the world wide web at http://www.erlang.org/.
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
# 
# The Initial Developer of the Original Code is Ericsson Utvecklings AB.
# Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
# AB. All Rights Reserved.''
# 
#     $Id$
#

require 5.002;
use strict;
use Socket;
use FileHandle;

my $port = 6669;
my $remote;
my ($iaddr, $paddr, $proto, $line);

@ARGV  or die "usage: $0 command...\n";

if (defined $ENV{'ERL_WIN32_BUILD_HOST'}) {
    $remote = $ENV{'ERL_WIN32_BUILD_HOST'};
}

die "$0: Set ERL_WIN32_BUILD_HOST to build host name.\n"
    unless defined $remote;

$iaddr = inet_aton($remote) or die "no host: $remote";
$paddr = sockaddr_in($port, $iaddr);

$proto = getprotobyname('tcp');
STDOUT->autoflush();
SOCK->autoflush();

my $cmd = join(' ', @ARGV);

socket(SOCK, PF_INET, SOCK_STREAM, $proto)
    or die "socket:  $!";
connect(SOCK, $paddr)
    or die "connect: $!";
print SOCK $cmd, "\n";

while (<SOCK>) {
    print;
}

close(SOCK) or die "close: $!";

exit 0;
