So, I've got a working TCP Echo example working. What I'm attempting to accomplish is to be able to receive TCP Transmissions, as well as send data over TCP and UDP. I'm using raw LWIP and will have a PC App I'll interact with. I want to be able to send a UDP Broadcast or TCP Unicast on demand. I'm having issues where I get a -6 ( ERR_VAL -6 /* Illegal value. */) error from the sendto function. Any input as to what I may be missing would be helpful. My first pass at getting a UDP Broadcast Working is here (at the moment I just added this function to the bottom of echo.c):
void echo_tx()
{
// Attempt a UDP Broadcast
// l_udp_pcb
err_t wr_err = ERR_OK;
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 1024, PBUF_RAM);
l_udp_pcb = udp_new();
wr_err = udp_bind(l_udp_pcb, IP_ADDR_ANY, 0);
wr_err = udp_connect(l_udp_pcb, IP_ADDR_ANY, 10);
unsigned char buffer_send[1024] = "My Name Is What";
p->payload = buffer_send;
p->len = 1024;
p->tot_len = 1024;
wr_err = udp_sendto(l_udp_pcb,p, IP_ADDR_BROADCAST, 10);
if(wr_err != ERR_OK)
{
wr_err = udp_sendto(l_udp_pcb,p, IP_ADDR_BROADCAST, 10);
}
pbuf_free(p);
}
You need to set the broadcast option on the PCB after you allocate it with udp_new()
:
ip_set_option(l_udp_pcb, SOF_BROADCAST);