lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Problem trying to recieve an UDP packet


From: Simon Goldschmidt
Subject: Re: [lwip-users] Problem trying to recieve an UDP packet
Date: Mon, 28 Nov 2011 10:50:34 +0100

Iwan Budi Kusnanto <address@hidden> wrote:
> [Sorry for top posting]
> 
> Hi Victor, please read RAW API doc first, at doc/rawapi.txt
> You can take a look at my code
> https://gist.github.com/1399729
> Tested with lwip 1.4.0-rc2

Hehe, that's a good one: rawapi.txt says:
"[..] there is one main thread running the lwIP core
(also known as the "tcpip_thread"). The raw API may only be used from
this thread!"

I'm afraid your example is wrong there: the raw API *must not* be used from 
multiple threads. In other words, calling udp_bind() and udp_recv() from its 
own thread will lead to memory corruption (as it manipulates the list of udp 
pcbs while other threads might also do that). It might work for your small 
example, but it will fail eventually.

So you might want to just move the code from udpecho_raw_server_thread() to 
udpecho_raw_server_init(), leave away the sys_thread_new() and you'd have a 
good example.

Simon

> 
> 2011/11/25 Víctor Mateo <address@hidden>:
> > Hi all
> >
> >
> >
> > I´m stuck trying to recieve an UDP packet from a host (192.168.10.10)
> to a
> > LWIP on 192.168.10.11 and send it back to the host as a simple echo.
> >
> > I'm sending the UDP packet (a simple character or string) trough port 31
> > from a C# Console I've programmed and checked that it actually sends
> right.
> >
> >
> >
> > This are the functions I'm using in the NIOS II IDE enviroment:
> >
> >
> >
> >
> -------------------------------------------------------------------------------------
> >
> >
> -------------------------------------------------------------------------------------
> >
> >
> >
> > void udp_echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p,
> struct
> > ip_addr *addr, u16_t port)
> > {
> >  struct ip_addr adr;
> >  IP4_ADDR(&adr, 192, 168, 10, 11);
> >  udp_connect(pcb, &adr,  31);
> >  //udp_send(pcb, p);
> >
> >
> >    if (p != NULL) {
> >     /* FIXME: possibly use udp_connect() and udp_disconnect()
> >                   instead of manipulating the pcb directly */
> >         pcb->remote_ip = *addr;
> >         pcb->remote_port = port;
> >         udp_send(pcb, p);
> >         /* FIXME: udp_disconnect() ? */
> >     }
> >     /* free the pbuf */
> >     pbuf_free(p);
> >     printf("udp_echo OK!\n");
> > }
> >
> > void udp_echo_init(void)
> > {
> >       struct ip_addr adr;
> > //    IP4_ADDR(&adr, 192, 168, 10, 10);
> > //    udp_connect(pcb, &adr,  31);
> > //    udp_send(pcb, p);
> >     udp_remove(pcb); //Elimino el pcb anterior (el de transmision)
> >     err_t retval;
> >     struct udp_pcb * pcb;
> >
> >     pcb = udp_new();
> >     if (pcb == NULL) printf("udp_new failed!\n");
> >
> >     retval = udp_bind(pcb, IP_ADDR_ANY, 31);
> >     //retval = udp_bind(pcb, IP_ADDR_ANY, 31);
> >     if (retval != ERR_OK) printf("udp_bind failed!\n");
> >     IP4_ADDR(&adr, 192, 168, 10, 11);
> >     udp_connect(pcb, &adr,  31);
> >     //udp_bind(pcb, IP_ADDR_ANY, 31);
> >
> >
> >     udp_recv(pcb, udp_echo_recv, NULL );
> >
> >     printf("udp_rcv OK!\n");
> >     //udp_disconnect(pcb);
> > }
> >
> >
> -------------------------------------------------------------------------------------
> >
> >
> -------------------------------------------------------------------------------------
> >
> >
> >
> > and I call udd_echo_init() from the main.c as an infinite listen circle:
> >
> >
> >
> > -------------------------------
> >
> > while(1)
> >
> > {
> >
> > udp_echo_init();
> >
> > }
> >
> > -------------------------------
> >
> >
> >
> > NIOS II compiles and runs the program fine, the message "udp_recv OK" is
> > shown but "udp_echo OK" doesn't. I don't know but it seems that
> > udp_echo_recv() is not working.
> >
> > Can anybody help me with this?
> >
> >
> >
> > Thank you
> >
> > --
> >
> > Víctor Mateo Gómez
> >
> >
> >
> > _______________________________________________
> > lwip-users mailing list
> > address@hidden
> > https://lists.nongnu.org/mailman/listinfo/lwip-users
> >
> 
> _______________________________________________
> lwip-users mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/lwip-users

-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de



reply via email to

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