/[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 17 by dpavlin, Tue Jul 28 10:29:33 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  sub tftp_dir {
9  my $rootdir = 'conf/' . readlink('conf/tftp.dir');          my $dir = 'conf/' . readlink('conf/tftp.dir');
10  $rootdir =~ s{[^/]+/\.\./([^/]+)}{$1};          $dir =~ s{[^/]+/\.\./([^/]+)}{$1};
11            return $dir;
 unless(-d $rootdir)  
 {  
         print "$rootdir isn't directory!\nUsage: $0 path/to/rootdir\n\n";  
         exit 1;  
12  }  }
13    
14    my $tftp_dir = tftp_dir;
15    
16    die "no $tftp_dir\n" unless -e $tftp_dir;
17    
18  # callback sub used to print transfer status  # callback sub used to print transfer status
19  sub callback  sub callback
20  {  {
# Line 35  sub callback Line 35  sub callback
35    
36  # create the listener  # create the listener
37  my $listener = Net::TFTPd->new(  my $listener = Net::TFTPd->new(
38          'RootDir' => $rootdir,          'RootDir' => $tftp_dir,
39          'Writable' => 0,          'Writable' => 0,
40          'Timeout' => 3600,          'Timeout' => 3600,
41          'CallBack' => \&callback,          'CallBack' => \&callback,
# Line 45  my $listener = Net::TFTPd->new( Line 45  my $listener = Net::TFTPd->new(
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 %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'};
49    
50  while(1) {  while(1) {
51    
52          # wait for any request (RRQ or WRQ)          # wait for any request (RRQ or WRQ)
53          if(my $request = $listener->waitRQ()) {          if(my $request = $listener->waitRQ()) {
54    
55                    $tftp_dir = tftp_dir;
56    
57                    if ( $request->{RootDir} ne $tftp_dir ) {
58                            $request->{RootDir} = $tftp_dir;
59                            warn "new root: $tftp_dir\n";
60                    }
61    
62                  # received request                  # received request
63                  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'};
64    

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

  ViewVC Help
Powered by ViewVC 1.1.26