Subversion Repositories Spectranet

[/] [trunk/] [experiments/] [ethup] - Rev 570

Go to most recent revision | Compare with Previous | Blame | View Log

#!/usr/bin/perl
use IO::Socket::INET;
use strict;

my $ip=shift;
my $file=shift;
my $addr=shift;

if(!$addr)
{
        $addr=32768;
}

if($addr < 0 || $addr > 65535)
{
        print("Address must be 16 bit.\n");
        exit;
}

my @info=stat($file) or die("Unable to stat $file: $!");
my $size=$info[7];
if($size == 0 | $size > 65535)
{
        print("File is an impossible size ($size)\n");
        exit;
}

my $sock=IO::Socket::INET->new(PeerAddr => $ip,
                                PeerPort => '2000',
                                Proto => 'tcp')
        or die("Opening socket: $!");

binmode($sock);

open FHND, "< $file" or die("Unable to open $file: $!");
binmode FHND;

# ensure the size and address data goes in little endian form.
my $bufdata=pack("CCCC", int($addr % 256), int($addr / 256),
                         int($size % 256), int($size / 256));

print $sock $bufdata;
my $blk=0;
while(my $data=<FHND>)
{
        print("Block $blk\n");
        print $sock $data;
        $blk++;
}
close $sock;
close FHND;

Go to most recent revision | Compare with Previous | Blame | View Log