lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] updated raw api UDP echo server example


From: Juri Haberland
Subject: [lwip-users] updated raw api UDP echo server example
Date: Thu, 14 Jun 2007 11:29:28 +0200
User-agent: Thunderbird 1.5.0.12 (X11/20070604)

Hi Dominik, Kirean, list...

here is an updated version of my little example UDP echo server. It uses
now udp_sendto(), which I totally overlooked the first time...

It would be nice if you could include this in the rawapi.txt or some
other documentation file distributed with the source (and of course:
more documentation on the website, please).

Cheers,
Juri
#include "lwip/udp.h"
#include "lwip/debug.h"


void udp_echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct 
ip_addr *addr, u16_t port)
{
    if (p != NULL) {
        /* send received packet back to sender */
        udp_sendto(pcb, p, addr, port);
        /* free the pbuf */
        pbuf_free(p);
    }
}


void udp_echo_init(void)
{
    struct udp_pcb * pcb;

    /* get new pcb */
    pcb = udp_new();
    if (pcb == NULL) {
        LWIP_DEBUGF(UDP_DEBUG, ("udp_new failed!\n"));
        return;
    }

    /* bind to any IP address on port 7 */
    if (udp_bind(pcb, IP_ADDR_ANY, 7) != ERR_OK) {
        LWIP_DEBUGF(UDP_DEBUG, ("udp_bind failed!\n"));
        return;
    }

    /* set udp_echo_recv() as callback function
       for received packets */
    udp_recv(pcb, udp_echo_recv, NULL);
}

reply via email to

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