blob: 9db73433096107a15991d2d1a94ee506911fbfc5 [file] [log] [blame]
xf.li6c8fc1e2023-08-12 00:11:09 -07001#!/usr/bin/env perl
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) 1998 - 2022, 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.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# SPDX-License-Identifier: curl
23#
24#***************************************************************************
25
26BEGIN {
27 push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
28 push(@INC, ".");
29}
30
31use strict;
32use warnings;
33
34use serverhelp qw(
35 server_pidfilename
36 server_logfilename
37 );
38
39use sshhelp qw(
40 exe_ext
41 );
42
43my $verbose = 0; # set to 1 for debugging
44my $port = 8997; # just a default
45my $ipvnum = 4; # default IP version of tftp server
46my $idnum = 1; # default tftp server instance number
47my $proto = 'tftp'; # protocol the tftp server speaks
48my $pidfile;
49my $portfile;
50my $logfile;
51my $srcdir;
52my $fork;
53
54my $flags = "";
55my $path = '.';
56my $logdir = $path .'/log';
57
58while(@ARGV) {
59 if($ARGV[0] eq '--pidfile') {
60 if($ARGV[1]) {
61 $pidfile = $ARGV[1];
62 shift @ARGV;
63 }
64 }
65 elsif($ARGV[0] eq '--portfile') {
66 if($ARGV[1]) {
67 $portfile = $ARGV[1];
68 shift @ARGV;
69 }
70 }
71 elsif($ARGV[0] eq '--logfile') {
72 if($ARGV[1]) {
73 $logfile = $ARGV[1];
74 shift @ARGV;
75 }
76 }
77 elsif($ARGV[0] eq '--srcdir') {
78 if($ARGV[1]) {
79 $srcdir = $ARGV[1];
80 shift @ARGV;
81 }
82 }
83 elsif($ARGV[0] eq '--ipv4') {
84 $ipvnum = 4;
85 }
86 elsif($ARGV[0] eq '--ipv6') {
87 $ipvnum = 6;
88 }
89 elsif($ARGV[0] eq '--port') {
90 if($ARGV[1] =~ /^(\d+)$/) {
91 $port = $1;
92 shift @ARGV;
93 }
94 }
95 elsif($ARGV[0] eq '--id') {
96 if($ARGV[1] =~ /^(\d+)$/) {
97 $idnum = $1 if($1 > 0);
98 shift @ARGV;
99 }
100 }
101 elsif($ARGV[0] eq '--verbose') {
102 $verbose = 1;
103 }
104 else {
105 print STDERR "\nWarning: tftpserver.pl unknown parameter: $ARGV[0]\n";
106 }
107 shift @ARGV;
108}
109
110if(!$srcdir) {
111 $srcdir = $ENV{'srcdir'} || '.';
112}
113if(!$pidfile) {
114 $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
115}
116if(!$logfile) {
117 $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
118}
119
120$flags .= "--pidfile \"$pidfile\" ".
121 "--portfile \"$portfile\" ".
122 "--logfile \"$logfile\" ";
123$flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
124
125$| = 1;
126exec("exec server/tftpd".exe_ext('SRV')." $flags");