Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

LwIP Webserver with API

Hello,

I want to test the lwip example with the sequential API from the documentation

http://www.sics.se/~adam/lwip/documentation.html (http://www.sics.se/~adam/lwip/documentation.html)

// A simple HTTP/1.0 server using the minimal API.
# include "lwip/api.h"
// This is the data for the actual web page.
// Most compilers would place this in ROM.
const static char indexdata = "<html> 
                                <head><title>A test page</title></head> 
                                <body> 
                                This is a small test page. 
                                </body> 
                                </html>";
const static char http_html_hdr = "Content-type: text/html\r\n\r\n";
// This function processes an incomming connection.
static void process_connection( struct netconn *conn )
{
    struct netbuf *inbuf;
    char *rq;
    int len;
  
    // Read data from the connection into the netbuf inbuf.
    // We assume that the full request is in the netbuf.
    inbuf = netconn_recv( conn );
      
    // Get the pointer to the data in the first netbuf
    // fragment which we hope contains the request.
    netbuf_data( inbuf, &rq, &len );
      
    // Check if the request was an HTTP "GET /\r\n".
    if(rq == &#39;G&#39; && rq == &#39;E&#39; &&
       rq == &#39;T&#39; && rq == &#39; &#39; &&
       rq == &#39;/&#39; && rq == &#39;\r&#39; &&
       rq == &#39;\n&#39;) 
    {
        // Send the header.
        netconn_write(conn, http_html_hdr, sizeof(http_html_hdr), NETCONN_NOCOPY);
        
        // Send the actual web page.
        netconn_write(conn, indexdata, sizeof(indexdata), NETCONN_NOCOPY);
        
        // Close the connection.
        netconn_close(conn);
    }
}
    
// The main() function.
int main()
{
    struct netconn *conn, *newconn;
    
    // Create a new TCP connection handle.  
    conn = netconn_new( NETCONN_TCP );
    
    // Bind the connection to port 80 on any
    // local IP address.
    netconn_bind(conn, NULL, 80);
      
    // Put the connection into LISTEN state.
    netconn_listen(conn);
    
    // Loop forever.
    while(1) 
    {
        // Accept a new connection.
        newconn = netconn_accept(conn);
        
        // Process the incomming connection.
        process_connection(newconn);
        
        // Deallocate connection handle. */
        netconn_delete(newconn);
    }
    
    return 0;
}

I get following errors. why?

<div class='quotetop'>QUOTE </div>

--- Quote Start ---

Compiling webserver01.c...

../webserver01.c: In function `process_connection&#39;:

../webserver01.c:30: warning: passing arg 2 of `netbuf_data&#39; from incompatible pointer type

../webserver01.c:30: warning: passing arg 3 of `netbuf_data&#39; from incompatible pointer type

../webserver01.c:39: warning: passing arg 2 of `netconn_write&#39; discards qualifiers from pointer target type

../webserver01.c:42: warning: passing arg 2 of `netconn_write&#39; discards qualifiers from pointer target type

../webserver01.c:78:2: warning: no newline at end of file

Linking webserver01.elf...

obj/webserver01.o(.text+0x18): In function `process_connection&#39;:

../webserver01.c:26: undefined reference to `netconn_recv&#39;

obj/webserver01.o(.text+0x2c):../webserver01.c:30: undefined reference to `netbuf_data&#39;

obj/webserver01.o(.text+0xcc):../webserver01.c:39: undefined reference to `netconn_write&#39;

obj/webserver01.o(.text+0xe4):../webserver01.c:42: undefined reference to `netconn_write&#39;

obj/webserver01.o(.text+0xec):../webserver01.c:45: undefined reference to `netconn_close&#39;

obj/webserver01.o(.text+0x114): In function `main&#39;:

../webserver01.c:55: undefined reference to `netconn_new&#39;

obj/webserver01.o(.text+0x128):../webserver01.c:59: undefined reference to `netconn_bind&#39;

obj/webserver01.o(.text+0x130):../webserver01.c:62: undefined reference to `netconn_listen&#39;

obj/webserver01.o(.text+0x138):../webserver01.c:68: undefined reference to `netconn_accept&#39;

obj/webserver01.o(.text+0x14c):../webserver01.c:74: undefined reference to `netconn_delete&#39;

collect2: ld returned 1 exit status

make: *** [webserver01.elf] Error 1

Build completed[/b]

--- Quote End ---

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    i think the problem ist the api.c ! Where can i find this file? I copied only the directories from the LWIP_Webserver example!

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    or can i use this example only with an OS such as MicroC/OS-II ? I would like to implement a webserver without a OS using the standalone lwip stack