Forum Discussion
Altera_Forum
Honored Contributor
20 years agoHello Danny,
As I wrote above I don’t use lwip for receiving UDP packets in my application. If you start with Nios etc. you should use lwip first, because it’s a working system. When you have built a stable system you can add some hardware accelerations to achieve higher bandwidth. The following code shows a very small UDP receive routine. I used this one for testing purposes only. After you have sent 1024 packets to port 1409 there will be a message.#include "lwip/debug.h"# include "lwip/stats.h"# include "lwip/udp.h"
u32_t udp_packets;
static void udp_test_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
struct ip_addr *addr, u16_t port)
{
/*
printf("\nUDP packet received from: %d.%d.%d.%d : %d",
(addr->addr)&0xFF, ((addr->addr)>>8)&0xFF,
((addr->addr)>>16)&0xFF, (addr->addr)>>24, port);
*/
udp_packets++;
//printf("\nlen: %d, tot_len: %d", p->len, p->tot_len);
if (udp_packets % 1024 == 0)
printf("\n%d udp_packets received", udp_packets);
pbuf_free(p);
}
/*-----------------------------------------------------------------------------------*/
void
udp_test_init(void)
{
struct udp_pcb *pcb;
printf("udp_init\n");
udp_packets = 0;
pcb = udp_new();
udp_bind(pcb, IP_ADDR_ANY, 1409);
udp_recv(pcb, udp_test_recv, NULL);
}
/*-----------------------------------------------------------------------------------*/ Regards, niosIIuser