Subversion Repositories Spectranet

[/] [trunk/] [experiments/] [ethup] - Blame information for rev 117

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 winston
#!/usr/bin/perl
2
use IO::Socket::INET;
3
use strict;
4
 
5 117 winston
my $ip=shift;
6 23 winston
my $file=shift;
7
my $addr=shift;
8
 
9
if(!$addr)
10
{
11 46 winston
        $addr=32768;
12 23 winston
}
13
 
14
if($addr < 0 || $addr > 65535)
15
{
16
        print("Address must be 16 bit.\n");
17
        exit;
18
}
19
 
20
my @info=stat($file) or die("Unable to stat $file: $!");
21
my $size=$info[7];
22
if($size == 0 | $size > 65535)
23
{
24
        print("File is an impossible size ($size)\n");
25
        exit;
26
}
27
 
28 117 winston
my $sock=IO::Socket::INET->new(PeerAddr => $ip,
29
                                PeerPort => '2000',
30 23 winston
                                Proto => 'tcp')
31
        or die("Opening socket: $!");
32
 
33
binmode($sock);
34
 
35
open FHND, "< $file" or die("Unable to open $file: $!");
36
binmode FHND;
37
 
38
# ensure the size and address data goes in little endian form.
39
my $bufdata=pack("CCCC", int($addr % 256), int($addr / 256),
40
                         int($size % 256), int($size / 256));
41
 
42
print $sock $bufdata;
43 37 winston
my $blk=0;
44 23 winston
while(my $data=<FHND>)
45
{
46 37 winston
        print("Block $blk\n");
47 23 winston
        print $sock $data;
48 37 winston
        $blk++;
49 23 winston
}
50
close $sock;
51
close FHND;
52