njh / EtherCard

EtherCard is an IPv4 driver for the ENC28J60 chip, compatible with Arduino IDE
https://www.aelius.com/njh/ethercard/
GNU General Public License v2.0
1.04k stars 455 forks source link

Sending broadcast UDP packets #34

Closed olebrun closed 12 years ago

olebrun commented 12 years ago

Hi,

I use ethercard for an implemetation of the xPL protocol on arduino.

I have a problem sending broadcast UDP packets. On a network 192.168.1.0 sending packet to 255.255.255.255 don't work, I need to specify the real broadcast address of the network ( 192.168.1.255 ) and to modify the tcpip.cpp file, line 317

From : if ((dip[0] & 0xF0) == 0xE0) // multicast address To : if ((dip[0] & 0xF0) == 0xE0 || dip[3] == 0xff) // multicast/broadcast address

This is ugly since a broadcast address don't necessary finish by 255 ... but I don't know how to simply detect if the destination Ip address is the broadcast address of the network ? or Am I missing something ?

Thanks for reading me, sorry for my english.

olebrun commented 12 years ago

It seems it can be calculate in EtherCard::udpPrepare with myip and mymask and compare the result with dip, am I right ?

olebrun commented 12 years ago

For clarity, in fact sending to 255.255.255.255 work but the daemon who listen to the packets on the network is waiting packets for the network broadcast ip, not for for 255.255.255.255.

olebrun commented 12 years ago

I have found how to force the dameon to listen to 255.255.255.255 broadcast message, so It's not an issue, perhaps a evolution ? ... sorry for the mess you can close this post :/