lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] UDP Raw receive / pbuf_free?


From: Friedrico
Subject: [lwip-users] UDP Raw receive / pbuf_free?
Date: Thu, 17 Jul 2014 17:36:50 +0200
User-agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

Hello,
I've been using the following code (lwip 1.4.1 on Infineon Tricore).
It only processes approx. 10 packages, after that it doesn't even process incoming packages (nor responds to pings). Without calling the udpInit I can send/receive a lot of icmp messages - even tcp works, so I guess that its related to my code.

A question in advance: are the pbuf_frees called in the right moment? At least it doesnt work for me. (Though there are a lot of code snippets similar to this)

Thanks

struct udp_pcb *udpPcb;


void udpReceive(void *arg, struct udp_pcb *pcb, struct pbuf *p,
        ip_addr_t *addr, u16_t port) {
   sendMsgUdp((char*)p->payload, /*some ip*/);
    pbuf_free(p);
}

err_t sendMsgUdp(char *msg, u32_t ip) {
    err_t err = ERR_OK;
    ip_addr_t ip_addr;
    struct pbuf *pb;
    pb = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
    if (pb == NULL) {
        return ERR_MEM;
    }
    ip_addr.addr = ip;
    pb->payload = msg;
    pb->len = pb->tot_len = messageSize;
        err = udp_connect(udpPcb, &ip_addr, MY_PORT);
        if (err != ERR_OK) {
            return err;
        }
        err = udp_send(udpPcb, pb);
        pbuf_free(pb);
        return err;
}


err_t initUdp() {
    err_t err = ERR_OK;
    udpPcb = udp_new();
    if (udpPcb == NULL) {
        return ERR_MEM;
    }
    err = udp_bind(udpPcb, IP_ADDR_ANY, MY_PORT);

    if (err != ERR_OK) {
        return err;
    }
     udp_recv(udpPcb, udpReceive, NULL);
    return err;
}




reply via email to

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