/[pxelator]/bin/tftpd.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/tftpd.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 13 by dpavlin, Mon Jul 27 22:25:06 2009 UTC revision 24 by dpavlin, Tue Jul 28 21:03:29 2009 UTC
# Line 5  use Net::TFTPd 0.03 qw(%OPCODES); Line 5  use Net::TFTPd 0.03 qw(%OPCODES);
5    
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  our $tftp_dir;
9  my $rootdir = 'conf/' . readlink('conf/tftp.dir');  sub tftp_dir {
10  $rootdir =~ s{[^/]+/\.\./([^/]+)}{$1};          require 'config.pl';
11            warn "# config: ", readlink 'config.pl', " tftp_dir: $tftp_dir\n";
12  unless(-d $rootdir)          return $tftp_dir;
 {  
         print "$rootdir isn't directory!\nUsage: $0 path/to/rootdir\n\n";  
         exit 1;  
13  }  }
14    
15    tftp_dir;
16    
17    die "no $tftp_dir\n" unless -e $tftp_dir;
18    
19  # callback sub used to print transfer status  # callback sub used to print transfer status
20  sub callback  sub callback
21  {  {
# Line 35  sub callback Line 36  sub callback
36    
37  # create the listener  # create the listener
38  my $listener = Net::TFTPd->new(  my $listener = Net::TFTPd->new(
39          'RootDir' => $rootdir,          'RootDir' => $tftp_dir,
40          'Writable' => 0,          'Writable' => 0,
41          'Timeout' => 3600,          'Timeout' => 3600,
42          'CallBack' => \&callback,          'CallBack' => \&callback,
# Line 45  my $listener = Net::TFTPd->new( Line 46  my $listener = Net::TFTPd->new(
46          BlkSize => 1456,        # IBM GE seems to be picky          BlkSize => 1456,        # IBM GE seems to be picky
47          Debug => 99,          Debug => 99,
48  ) or die Net::TFTPd->error;  ) or die Net::TFTPd->error;
49  printf "TFTP %s:%d [timeout %d s] $rootdir\n", $listener->{'LocalAddr'} ? $listener->{'LocalAddr'} : "'any address'",  $listener->{'LocalPort'}, $listener->{'Timeout'};  printf "TFTP on %s:%d timeout: %d dir: $tftp_dir\n", $listener->{'LocalAddr'} ? $listener->{'LocalAddr'} : "'any address'",  $listener->{'LocalPort'}, $listener->{'Timeout'};
50    
51  while(1) {  while(1) {
52    
53          # wait for any request (RRQ or WRQ)          # wait for any request (RRQ or WRQ)
54          if(my $request = $listener->waitRQ()) {          if(my $request = $listener->waitRQ()) {
55    
56                    $tftp_dir = tftp_dir;
57    
58                    if ( $request->{RootDir} ne $tftp_dir ) {
59                            $request->{RootDir} = $tftp_dir;
60                            warn "new root: $tftp_dir\n";
61                    }
62    
63                  # received request                  # received request
64                  printf "Received a %s for file '%s'\n", $OPCODES{$request->{'_REQUEST_'}{'OPCODE'}}, $request->{'_REQUEST_'}{'FileName'};                  printf "Received a %s for file '%s'\n", $OPCODES{$request->{'_REQUEST_'}{'OPCODE'}}, $request->{'_REQUEST_'}{'FileName'};
65    

Legend:
Removed from v.13  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26