6 |
die "need to run $0 as root like this\nsudo $0\n" unless $< == 0; |
die "need to run $0 as root like this\nsudo $0\n" unless $< == 0; |
7 |
|
|
8 |
# change ROOTDIR to your TFTP root directory |
# change ROOTDIR to your TFTP root directory |
9 |
my $rootdir = $ARGV[0] || 'tftp'; |
my $rootdir = 'conf/' . readlink('conf/tftp.dir'); |
10 |
|
$rootdir =~ s{[^/]+/\.\./([^/]+)}{$1}; |
11 |
|
|
12 |
unless(-d $rootdir) |
unless(-d $rootdir) |
13 |
{ |
{ |
14 |
print "\nUsage: $0 path/to/rootdir\n\n"; |
print "$rootdir isn't directory!\nUsage: $0 path/to/rootdir\n\n"; |
15 |
exit 1; |
exit 1; |
16 |
} |
} |
17 |
|
|
28 |
{ |
{ |
29 |
# WRQ |
# WRQ |
30 |
printf "block: %u\/%u\n", $req->{'_REQUEST_'}{'LASTBLK'}, $req->{'_REQUEST_'}{'LASTACK'}; |
printf "block: %u\/%u\n", $req->{'_REQUEST_'}{'LASTBLK'}, $req->{'_REQUEST_'}{'LASTACK'}; |
31 |
|
} else { |
32 |
|
warn "IGNORED: ", dump( $req ); |
33 |
} |
} |
34 |
} |
} |
35 |
|
|
45 |
BlkSize => 1456, # IBM GE seems to be picky |
BlkSize => 1456, # IBM GE seems to be picky |
46 |
Debug => 99, |
Debug => 99, |
47 |
) or die Net::TFTPd->error; |
) or die Net::TFTPd->error; |
48 |
printf "TFTP listener is bound to %s:%d\nTFTP listener is waiting %d seconds for a request\n", $listener->{'LocalAddr'} ? $listener->{'LocalAddr'} : "'any address'", $listener->{'LocalPort'}, $listener->{'Timeout'}; |
printf "TFTP %s:%d [timeout %d s] $rootdir\n", $listener->{'LocalAddr'} ? $listener->{'LocalAddr'} : "'any address'", $listener->{'LocalPort'}, $listener->{'Timeout'}; |
49 |
|
|
50 |
while(1) { |
while(1) { |
51 |
|
|