1 #!/usr/bin/env perl 2 #*************************************************************************** 3 # _ _ ____ _ 4 # Project ___| | | | _ \| | 5 # / __| | | | |_) | | 6 # | (__| |_| | _ <| |___ 7 # \___|\___/|_| \_\_____| 8 # 9 # Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel (at] haxx.se>, et al. 10 # 11 # This software is licensed as described in the file COPYING, which 12 # you should have received as part of this distribution. The terms 13 # are also available at http://curl.haxx.se/docs/copyright.html. 14 # 15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell 16 # copies of the Software, and permit persons to whom the Software is 17 # furnished to do so, under the terms of the COPYING file. 18 # 19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20 # KIND, either express or implied. 21 # 22 #*************************************************************************** 23 24 BEGIN { 25 push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'}); 26 push(@INC, "."); 27 } 28 29 use strict; 30 use warnings; 31 32 use serverhelp qw( 33 server_pidfilename 34 server_logfilename 35 ); 36 37 my $verbose = 0; # set to 1 for debugging 38 my $port = 8997; # just a default 39 my $ipvnum = 4; # default IP version of tftp server 40 my $idnum = 1; # dafault tftp server instance number 41 my $proto = 'tftp'; # protocol the tftp server speaks 42 my $pidfile; # tftp server pid file 43 my $logfile; # tftp server log file 44 my $srcdir; 45 my $fork; 46 47 my $flags = ""; 48 my $path = '.'; 49 my $logdir = $path .'/log'; 50 51 while(@ARGV) { 52 if($ARGV[0] eq '--pidfile') { 53 if($ARGV[1]) { 54 $pidfile = $ARGV[1]; 55 shift @ARGV; 56 } 57 } 58 elsif($ARGV[0] eq '--logfile') { 59 if($ARGV[1]) { 60 $logfile = $ARGV[1]; 61 shift @ARGV; 62 } 63 } 64 elsif($ARGV[0] eq '--srcdir') { 65 if($ARGV[1]) { 66 $srcdir = $ARGV[1]; 67 shift @ARGV; 68 } 69 } 70 elsif($ARGV[0] eq '--ipv4') { 71 $ipvnum = 4; 72 } 73 elsif($ARGV[0] eq '--ipv6') { 74 $ipvnum = 6; 75 } 76 elsif($ARGV[0] eq '--port') { 77 if($ARGV[1] =~ /^(\d+)$/) { 78 $port = $1; 79 shift @ARGV; 80 } 81 } 82 elsif($ARGV[0] eq '--id') { 83 if($ARGV[1] =~ /^(\d+)$/) { 84 $idnum = $1 if($1 > 0); 85 shift @ARGV; 86 } 87 } 88 elsif($ARGV[0] eq '--verbose') { 89 $verbose = 1; 90 } 91 else { 92 print STDERR "\nWarning: tftpserver.pl unknown parameter: $ARGV[0]\n"; 93 } 94 shift @ARGV; 95 } 96 97 if(!$srcdir) { 98 $srcdir = $ENV{'srcdir'} || '.'; 99 } 100 if(!$pidfile) { 101 $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum); 102 } 103 if(!$logfile) { 104 $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum); 105 } 106 107 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" "; 108 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\""; 109 110 exec("server/tftpd $flags"); 111