Danny,
At least, initially, it makes sense to model your code after the example shipped with Standalone LWIP. In other words, get the example working, understand what it's doing, and then add something like the following to it (in the ./apps subdirectory):
#include "echo_udp.h"# include "lwip/debug.h"# include "lwip/stats.h"# include "lwip/udp.h"# include "system.h"# include "alt_types.h"# include "altera_avalon_pio_regs.h"# include "stdlib.h"# include "stdio.h"# include "ctype.h"# include <unistd.h>
static void
echo_udp_recv( void* arg, struct udp_pcb *pcb,
struct pbuf *p,
struct ip_addr *addr,
u16_t port )
{
err_t err;
err = udp_connect( pcb, addr, port );
if (err != ERR_OK)
{
printf( "ERROR: udp_connect() error: %d\n", err );
}
err = udp_send( pcb, p );
if (err != ERR_OK)
{
printf( "ERROR: udp_send() error: %d\n", err );
}
pbuf_free( p );
udp_remove( pcb );
echo_udp_init();
return;
}
void
echo_udp_init(void)
{
struct udp_pcb *pcb;
pcb = udp_new();
udp_bind( pcb, IP_ADDR_ANY, 8 );
udp_recv( pcb, &echo_udp_recv, NULL );
}
echo_udp_init() initializes a new pcb, binds to local port 8, and then registers echo_udp_recv() as the callback when anything is received on port 8.
Keep in mind that UDP is connectionless and we're not talking about sockets, at all, with stand alone LWIP. It's a totally separate distribution, available from this website.
In any case, the above code works, if you can get the example shipped with the stand alone distribution working...
Cheers,
- slacker