tabascoeye / lwip

a fork of the light-weight IP stack
Other
15 stars 6 forks source link

UDP broadcasts do not reach bound pcbs #6

Open tabascoeye opened 10 years ago

tabascoeye commented 10 years ago

When a UDP broadcast is received (destination IP 255.255.255.255), the udp input function checks: 1) is it a broadcast ==> yes AND 2) is the local pcb bound to INADDR_ANY? OR 3) does the destination IP match into the local IP/netmask?

So when you have bound you udp socket to a specific IP instead of INADDR_ANY, it will never receive UDP broadcasts because 2) and 3) will eval to false.

==> a third check is needed

tabascoeye commented 10 years ago

in src\core\udp.c change the udp_input() function.

#if IP_SOF_BROADCAST_RECV
            (broadcast && ip_get_option(pcb, SOF_BROADCAST) &&
             (ip_addr_isany(&pcb->local_ip) ||
              ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask) ||
             (ip_addr_cmp(IP_ADDR_BROADCAST, ip_current_dest_addr()) && ip_addr_cmp(&inp->ip_addr, &pcb->local_ip)))) {
#else /* IP_SOF_BROADCAST_RECV */
            (broadcast &&
             (ip_addr_isany(&pcb->local_ip) ||
              ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask) ||
             (ip_addr_cmp(IP_ADDR_BROADCAST, ip_current_dest_addr()) && ip_addr_cmp(&inp->ip_addr, &pcb->local_ip))))) {
#endif /* IP_SOF_BROADCAST_RECV */