• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env perl
2#***************************************************************************
3#                                  _   _ ____  _
4#  Project                     ___| | | |  _ \| |
5#                             / __| | | | |_) | |
6#                            | (__| |_| |  _ <| |___
7#                             \___|\___/|_| \_\_____|
8#
9# Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@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 https://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
24BEGIN {
25    push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
26    push(@INC, ".");
27}
28
29use strict;
30use warnings;
31
32use serverhelp qw(
33    server_pidfilename
34    server_logfilename
35    );
36
37my $verbose = 0;     # set to 1 for debugging
38my $port = 8997;     # just a default
39my $ipvnum = 4;      # default IP version of tftp server
40my $idnum = 1;       # default tftp server instance number
41my $proto = 'tftp';  # protocol the tftp server speaks
42my $pidfile;         # tftp server pid file
43my $logfile;         # tftp server log file
44my $srcdir;
45my $fork;
46
47my $flags  = "";
48my $path   = '.';
49my $logdir = $path .'/log';
50
51while(@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
97if(!$srcdir) {
98    $srcdir = $ENV{'srcdir'} || '.';
99}
100if(!$pidfile) {
101    $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
102}
103if(!$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
110exec("server/tftpd $flags");
111