lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Re: Using lwip for writing a minimal HTTP proxy


From: Mandeep Sandhu
Subject: [lwip-users] Re: Using lwip for writing a minimal HTTP proxy
Date: Fri, 25 Sep 2009 12:04:29 +0530

On Thu, Sep 24, 2009 at 10:35 PM, Mandeep Sandhu
<address@hidden> wrote:
> Hi All,
>
> I'm implementing a very minimal HTTP proxy server, using lwIP (1.3.1)
> in "sequential" mode.
>
> I've based my code on the sample http webserver that is provided along
> with lwIP (httpd_sequential.c). I'm using ecos.
> The way the server works is simple. Eg: A request like http://<my
> IP>/local/index.html from client, will cause it to serve a local page.
> Whereas  http://<my IP>/REMOTE/index.html will cause it to "proxy" the
> client request to another HTTP server (pre-configured).
>
> I'm able to do the local part successfully, i.e server local content
> (the index.html response is created on the fly, it's not a file).
>
> The problem starts when I try to proxy the request to another server.
>
> Say the clients connection with my server is "client_conn". In the
> main event loop of my server, for proxy requests, I do the following:
>
> 1) proxy_conn = netconn_new(NETCONN_TCP);
> 2) netconn_connect( proxy_conn, <IP addr of other server>, <other
> server's listening port> );
> 3) netconn_write( proxy_conn, <data to be proxied>, <length>, NETCONN_COPY);
>
> 4) Listen for resp (this code is based on the TCP echo example):
>    while ((proxy_resp = netconn_recv(proxy_conn)) != NULL ) {
>        do {
>            netbuf_data(proxy_resp, &data, &len);
>            //Write response to the client
>            err = netconn_write(client_conn, data, len, NETCONN_COPY);
>
>            if (err != ERR_OK) {
>                goto error; // some error handler
>            }
>        } while (netbuf_next(proxy_resp) >= 0);
>        netbuf_delete(proxy_resp);
>    }
>
> My problem happens at step 2. The error code returned is "-5" i.e ERR_ABRT.

Oops! I think i'm in a soup on this one!

My default interface set to the interface from which the client
request is originating. Could this be the reason that the TCP packets,
of the new connection (the proxy one), are being routed out of this
interface instead of the correct one (the second interface)?!

Is there a way I can add a host specific route for the second servers
IP. So that the packets get routed properly?

I could not find any "route add" function.

Thanks,
-mandeep

>
> Is this the right approach to do this? Why is the "connect" failing?
> Is it because in sequential mode I cannot initiate a second TCP
> connection while the first one is not closed?
>
> I'm new to TCP, so pardon me if I'm missing something obvious! :)
>
> Thanks,
> -mandeep
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]