Skip to main content
Visitor II
May 17, 2022
Question

Receive UDP broadcast from a particular source port

  • May 17, 2022
  • 0 replies
  • 958 views

Hi all,

I am working on a project that transmits UDP packet to a remote IP and port. I need to receive a broadcast packet from a particular source port. Below is my current UDP initialization.

I am using LWIP stack for UDP communication. How should I initialize the UDP connection to receive a broadcast packet?

void UdpClientConnect()

{

err_t ErrVal;

NewUdp = udp_new(); // Creates new UDP control block.

ip_set_option(NewUdp, SOF_BROADCAST);

ip_addr_t MyIpAddr;

IP_ADDR4(&MyIpAddr, MODULE_IP_ADDR0, MODULE_IP_ADDR1, MODULE_IP_ADDR2, NodeID);

udp_bind(NewUdp, &MyIpAddr,1234); // Binds the UDP block to module's IP and Port.

//udp_bind(NewUdp, IP_ADDR_BROADCAST, 8800);

ip_addr_t DestIpAddr;

IP_ADDR4(&DestIpAddr, DEVICE_IP_ADDR0, DEVICE_IP_ADDR1, DEVICE_IP_ADDR2, DEVICE_IP_ADDR3); // Configure Destination IP and Port.

ErrVal = udp_connect(NewUdp, &DestIpAddr, OUTGOING_PORT_ADDR); // Connects the UDP block to the Destination, using Destination IP and Port.

if(ErrVal == ERR_OK)

{

udp_recv(NewUdp, udp_receive_callback, NULL); // Receive Callback function executes for the UDP block.

}

}

My default IP for the MCU is 192.168.0.3 and port is 1234.

    This topic has been closed for replies.