cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: TCP port# for HTTP

From: Patrick Monnerat <Patrick.Monnerat_at_datasphere.ch>
Date: Wed, 7 Nov 2012 19:06:15 +0100

 
ABULIUS, MUGUR (MUGUR) wrote:
>>... http://curl.haxx.se/libcurl/c/simple.html
<http://curl.haxx.se/libcurl/c/simple.html> .
 
>> 1) Which TCP port# is used by the HTTP request in this example?

The standard one: 80

>> 2) Is this TCP port# coming from "/etc/services"?

No, it comes from internal tables.

>> 2) There is any way to specify an external parameter (e.g..
environment variables or configuration file) to allow 2 different
running instances of this same "simple.c" program to use different TCP
ports for the HTTP request?

Not without modifying the simple.c program, but you have 2 ways to
provide a port number:
1) Using the standard URL notation: http://www.example.com:portno
2) With curl_easy_setopt(curl, CURLOPT_PORT, (long) portno);

For example: use
int main(int argc, char * * argv)
{
  CURL *curl;
  CURLcode res;
 
  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
    curl_easy_setopt(curl, CURLOPT_PORT, atol(argv[1]));
 
    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));
 
    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}
And pass the port number as single argument while launching the program.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-11-07