babelouest / ulfius

Web Framework to build REST APIs, Webservices or any HTTP endpoint in C language. Can stream large amount of data, integrate JSON data with Jansson, and create websocket services
https://babelouest.github.io/ulfius
GNU Lesser General Public License v2.1
1.07k stars 183 forks source link

[Issue] Not able to bind specific interface address for REST request #244

Closed Akki-401 closed 1 year ago

Akki-401 commented 1 year ago

I'm filling the client_address of _u_request with IP add to bind REST client with specific interface. But REST Request is being sent from other interface in my case. Please find below code snippet:

struct _u_request req_list; struct sockaddr_in p = (struct sockaddr_in )calloc(1,sizeof(sockaddr_in)); p->sin_family = AF_INET; p->sin_addr.s_addr = inet_addr("10.211.10.169"); p->sin_port = htons(40000); req_list.client_address = (struct sockaddr*)&p;

Please let me know If i'm doing it correctly?

babelouest commented 1 year ago

Hello,

Unfortunately, the variable client_address in the struct _u_request isn't meant to specify the client IP address during a ulfius_send_http_request call. This variable is used to get the client IP address in a webservice callback.

It is not possible to specify the interface to use in your case.

Akki-401 commented 1 year ago

Hi @babelouest,

Thanks for your quick response.

I'm using ulfius here as a standalone client. It doesn't have any callback registered. So I want REST request should being sent from specific IP address (my machine is having multiple interface (IP address)). Is there any way to achieve this scenario?

babelouest commented 1 year ago

Hello @Akki-401 ,

Unfortunately, as I said below, ulfius doesn't allow to specify a network interface for the outgoing HTTP requests, sorry. You may try with libcurl which seems to have such ways: https://curl.se/libcurl/c/CURLOPT_INTERFACE.html

Akki-401 commented 1 year ago

Hi @babelouest

Thanks for your suggestion. Will try with libcurl.

Also thanks a lot for your prompt response.