Altera_Forum
Honored Contributor
20 years agoLwIP 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 == 'G' && rq == 'E' &&
rq == 'T' && rq == ' ' &&
rq == '/' && rq == '\r' &&
rq == '\n')
{
// 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': ../webserver01.c:30: warning: passing arg 2 of `netbuf_data' from incompatible pointer type ../webserver01.c:30: warning: passing arg 3 of `netbuf_data' from incompatible pointer type ../webserver01.c:39: warning: passing arg 2 of `netconn_write' discards qualifiers from pointer target type ../webserver01.c:42: warning: passing arg 2 of `netconn_write' 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': ../webserver01.c:26: undefined reference to `netconn_recv' obj/webserver01.o(.text+0x2c):../webserver01.c:30: undefined reference to `netbuf_data' obj/webserver01.o(.text+0xcc):../webserver01.c:39: undefined reference to `netconn_write' obj/webserver01.o(.text+0xe4):../webserver01.c:42: undefined reference to `netconn_write' obj/webserver01.o(.text+0xec):../webserver01.c:45: undefined reference to `netconn_close' obj/webserver01.o(.text+0x114): In function `main': ../webserver01.c:55: undefined reference to `netconn_new' obj/webserver01.o(.text+0x128):../webserver01.c:59: undefined reference to `netconn_bind' obj/webserver01.o(.text+0x130):../webserver01.c:62: undefined reference to `netconn_listen' obj/webserver01.o(.text+0x138):../webserver01.c:68: undefined reference to `netconn_accept' obj/webserver01.o(.text+0x14c):../webserver01.c:74: undefined reference to `netconn_delete' collect2: ld returned 1 exit status make: *** [webserver01.elf] Error 1 Build completed[/b] --- Quote End ---