diff --git a/c/client.c b/c/client.c index 4895553..de62b58 100644 --- a/c/client.c +++ b/c/client.c @@ -434,7 +434,7 @@ int main(int argc, char **argv) { srand(getpid()); { /* Option parsing */ int opt; - while ((opt = getopt(argc, argv, "A:k:o:i:Vsqvu:C:KT:I:R:S:")) != -1) { + while ((opt = getopt(argc, argv, "A:k:o:i:Vsqvu:C:KT:I:R:S:H:")) != -1) { switch (opt) { case 'A': /* Authentication options for remote server */ { /* Scan string as hostname=username:password */ @@ -519,6 +519,10 @@ int main(int argc, char **argv) { /* Interface */ want_interface = strdup(optarg); break; + case 'H': + /* Resolve Host */ + resolve_host = strdup(optarg); + break; } } } @@ -731,6 +735,7 @@ int main(int argc, char **argv) { printf("used %lld local, fetched %lld\n", local_used, http_down); free(cacert); free(want_interface); + free(resolve_host); free(referer); free(temp_file); curl_global_cleanup(); diff --git a/c/doc/zsync.1 b/c/doc/zsync.1 index 17b8f1d..06ffa66 100644 --- a/c/doc/zsync.1 +++ b/c/doc/zsync.1 @@ -61,6 +61,10 @@ Use the specified client-side certificate file when making https connections. \fB\-S\fR \fIsslkey\fP Use the specified client-side private key file when making https connections. .TP +\fB\-H\fR \fIhost:port:ip\fP +Use the curl --resolve option to map a hostname to a different IP instead of doing a dns lookup. +Example curl usage: curl --resolve foo.example.com:443:127.0.0.1 https://foo.example.com:443/ +.TP \fB\-I\fR \fIinterface\fP Attempt to use this interface name, IP address or hostname as the source of http connections. .TP diff --git a/c/http.c b/c/http.c index 2c6bfdc..6ddadb1 100644 --- a/c/http.c +++ b/c/http.c @@ -64,6 +64,9 @@ char *want_interface = NULL; char *sslcert = NULL; char *sslkey = NULL; +/* Should we tell curl to resolve a host to a particular ip? */ +char *resolve_host = NULL; + /* Should we tell curl to ignore SSL peer verification? */ int be_insecure = 0; @@ -163,6 +166,21 @@ CURL *make_curl_handle() { fprintf(stderr, "--interface: %s\n", curl_easy_strerror(res)); } } + + /* Requires CURL ver 7.21.3 or newer. */ + /* Equiv of --resolve in curl */ + if(resolve_host) { + /* -H */ + struct curl_slist *host = NULL; + host = curl_slist_append(NULL, resolve_host); + res = curl_easy_setopt( curl, CURLOPT_RESOLVE, host ); + if( res != CURLE_OK ) { + /* Warn and continue. Let's try anyway even if this setopt fails */ + fprintf(stderr, "--resolve: %s\n", curl_easy_strerror(res)); + curl_easy_cleanup(curl); + return NULL; + } + } if(be_insecure) { /* -K */ diff --git a/c/http.h b/c/http.h index 0ec81d5..5314a0d 100644 --- a/c/http.h +++ b/c/http.h @@ -21,6 +21,7 @@ extern char *referer; extern char *cacert; extern char *want_interface; +extern char *resolve_host; extern char *sslcert; extern char *sslkey; extern int be_insecure;