From 2fbf94b0f309de9bd9153274bb475abc744afb0a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 30 Jan 2006 08:24:07 +0000 Subject: Added CURLOPT_LOCALPORT and CURLOPT_LOCALPORTRANGE to libcurl. Set with the curl tool with --local-port. Plain and simply set the range of ports to bind the local end of connections to. Implemented on to popular demand. Not extensively tested. Please let me know how it works. --- src/main.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 38eb9f0a1..549a4d892 100644 --- a/src/main.c +++ b/src/main.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -271,6 +271,8 @@ struct Configurable { char *headerfile; char *ftpport; char *iface; + int localport; + int localportrange; unsigned short porttouse; char *range; long low_speed_limit; @@ -519,12 +521,13 @@ static void help(void) " -i/--include Include protocol headers in the output (H/F)", " -I/--head Show document info only", " -j/--junk-session-cookies Ignore session cookies read from file (H)", - " --interface Specify network interface to use", + " --interface Specify network interface/address to use", " --krb4 Enable krb4 with specified security level (F)", " -k/--insecure Allow connections to SSL sites without certs (H)", " -K/--config Specify which config file to read", " -l/--list-only List only names of an FTP directory (F)", " --limit-rate Limit transfer speed to this rate", + " --local-port [-num] Force use of these local port numbers\n", " -L/--location Follow Location: hints (H)", " --location-trusted Follow Location: and send authentication even ", " to other hostnames (H)", @@ -1261,7 +1264,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */ { char letter; char subletter=0; /* subletters can only occur on long options */ - + int rc; /* generic return code variable */ const char *parse=NULL; unsigned int j; time_t now; @@ -1326,6 +1329,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */ {"$p", "ignore-content-length", FALSE}, {"$q", "ftp-skip-pasv-ip", FALSE}, {"$r", "ftp-method", TRUE}, + {"$s", "local-port", TRUE}, {"0", "http1.0", FALSE}, {"1", "tlsv1", FALSE}, @@ -1739,6 +1743,22 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */ case 'r': /* --ftp-method (undocumented at this point) */ config->ftp_filemethod = ftpfilemethod(config, nextarg); break; + case 's': /* --local-port */ + rc = sscanf(nextarg, "%d - %d", + &config->localport, + &config->localportrange); + if(!rc) + return PARAM_BAD_USE; + else if(rc == 1) + config->localportrange = 1; /* default number of ports to try */ + else { + config->localportrange -= config->localport; + if(config->localportrange < 1) { + warnf(config, "bad range input\n"); + return PARAM_BAD_USE; + } + } + break; } break; case '#': /* --progress-bar */ @@ -3972,6 +3992,12 @@ operate(struct Configurable *config, int argc, char *argv[]) /* curl 7.15.1 */ curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD, config->ftp_filemethod); + /* curl 7.15.2 */ + if(config->localport) { + curl_easy_setopt(curl, CURLOPT_LOCALPORT, config->localport); + curl_easy_setopt(curl, CURLOPT_LOCALPORTRANGE, config->localportrange); + } + retry_numretries = config->req_retry; retrystart = curlx_tvnow(); -- cgit v1.2.3