lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] UDP RawAPI Sample?


From: Juri Haberland
Subject: Re: [lwip-users] UDP RawAPI Sample?
Date: Thu, 14 Jun 2007 10:11:30 +0200
User-agent: Thunderbird 1.5.0.12 (X11/20070604)

Spies, Dominik wrote:
> Hallo!

Hi,

> Is there somewhere a simple piece of code which shows how udp connection
> with the rawapi works?
> I read the rawapi.txt but that is very ehm let's say basic..

See my little example that I attached (it's just a proof of concept).
It's a simple UDP echo server listening on port 7 sending back the
packet it just got.

> I managed to recieve a packet and send one, but the packet I sent was
> not correct.
> I created 2 pcb, one recieving one sending? is this correct? or do i
> just need one? if yes, in what order do I have to call bin, connect and
> so on?

Concerning the order of calls:
receiving:
udp_bind()
udp_recv()

sending:
<prepare pcb>
udp_send()

Preparing the pcb for sending might be better done with udp_connect()
and udp_disconnect() I suppose, but I haven't tried it yet - see my example.

> The packet I sent had a pbuf with size 1 and PBUF_TRANSPORT. What do I
> have to do to form the packet? Because for example IP-addresses were
> wrong.. How do I do that?

I manipulated the pcb directly, but again, udp_connect() might be the
correct solution.

> And last but not least, after recieving about 30 packets, the callback
> function i registerd isn't called anymore. Also there are no UDP debug
> messages.

Can' help you with this one, sorry.

Cheers,
Juri


#include "lwip/udp.h"


void udp_echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct 
ip_addr *addr, u16_t port)
{
    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);
}

void udp_echo_init(void)
{
    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, 7);
    if (retval != ERR_OK) printf("udp_bind failed!\n");

    udp_recv(pcb, udp_echo_recv, NULL);
}

reply via email to

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