简体   繁体   English

原始LWIP UDP广播

[英]Raw LWIP UDP Broadcast

So, I've got a working TCP Echo example working. 所以,我有一个有效的TCP Echo示例。 What I'm attempting to accomplish is to be able to receive TCP Transmissions, as well as send data over TCP and UDP. 我试图完成的是能够接收TCP传输,以及通过TCP和UDP发送数据。 I'm using raw LWIP and will have a PC App I'll interact with. 我正在使用原始LWIP,并将有一个我将与之交互的PC应用程序。 I want to be able to send a UDP Broadcast or TCP Unicast on demand. 我希望能够按需发送UDP广播或TCP单播。 I'm having issues where I get a -6 ( ERR_VAL -6 /* Illegal value. */) error from the sendto function. 我遇到问题,我从sendto函数得到-6(ERR_VAL -6 / *非法值。* /)错误。 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): 获得UDP广播工作的第一步是在这里(目前我刚刚将此函数添加到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);
}

使用udp_new()分配后,需要在PCB上设置广播选项:

ip_set_option(l_udp_pcb, SOF_BROADCAST);

this is how you must send the data after binding 这是绑定后必须发送数据的方式

char msg[] = "testingrg";
struct pbuf *p;

        while (1)
{
    //count++;
    //Allocate packet buffer and send to the remote host
    p = pbuf_alloc(PBUF_TRANSPORT, sizeof(lwiperf_txbuf_const), PBUF_RAM);
    memcpy(p->payload, &lwiperf_txbuf_const, sizeof(lwiperf_txbuf_const));

    err1 = udp_send(udpecho_raw_pcb, p);

    pbuf_free(p); //De-allocate packet buffer

    //osDelay(200);

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM