curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Retrieving the local address between connect() and HTTP

From: Jean-Francois Dockes via curl-library <curl-library_at_cool.haxx.se>
Date: Sun, 26 Apr 2020 16:40:23 +0200

Hi,

My apologies if this is a frequent question, I could not find an answer.

It would be convenient for me to retrieve the local address of the
connected socket used for an HTTP GET before the HTTP transaction
begins.

The pseudo HTTP protocol which my code implements (UPnP) needs to set a
HTTP header which contains a callback URL for the remote host to send
events to. In case the local machine has multiple interfaces, the easiest
way to build an URL which the remote is guaranteed to be able to connect to
seems to be just using the connected socket local address.

Unfortunately, it seems that the two callbacks in this area,
CURLOPT_SOCKOPTFUNCTION and CURLOPT_OPENSOCKETFUNCTION, occur before the
socket is connected.

I could connect the socket myself (losing the nice CURL code which does it
for me), or find another way to derive the right interface from the
remote address I am connecting to, but a getsockname() on the connected
socket would be much simpler. So I was hoping that there was a way.

This is assuming that I can call CURLOPT_HTTPHEADER from this point, which
may also not be the case. So, questions...

Thanks for this nice library !

Regards,

J.F. Dockes
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-04-26