ntruchsess / arduino_uip

UIPEthernet: A plugin-replacement of the stock Arduino Ethernet library for ENC28J60 shields and breakout boards. Full support for persistent (streaming) TCP-connections and UDP (Client and Server each), ARP, ICMP, DHCP and DNS. Build around Adam Dunkels uIP Stack. Further developed version can be found on https://github.com/UIPEthernet/UIPEthernet
489 stars 212 forks source link

UDP Broadcast - Local Network Broadcast #83

Open nbl1268 opened 10 years ago

nbl1268 commented 10 years ago

Hi there, looking for some guidance with sending UDP broadcast messages.

Have written a small program to send data via UDP to my local network; packets are very short (maybe 10 bytes of data).

The problem i am experiencing is that the local network broadcast (eg n.n.n.255) doesnt seem to be working, whereas 255.255.255.255 does work.

Here is extracts from my code to help explain what i am doing

// \ ETHERNET SETTING ** byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 }; IPAddress ip(192, 168, 42, 111); // My network

//IPAddress ipB(192, 168, 42, 255); // doesnt work?? unsure why IPAddress ipB(255, 255, 255, 255); // works int portB = 42673; // broadcast UDP port

i have set a local Port so i know what port number the UDP messages are coming from // Setup UDP Messaging EthernetUDP udp; unsigned int localPort = 2390;

i use this command/constructor to setup my arduino with the right local ip address Ethernet.begin(mac, ip); // use specified IP

and this command to setup my UDP messaging udp.begin(portB); // start UDP service

and this command to send the UDP message (with the result being stored in 'success') success = udp.beginPacket(ipB,portB);

my network is 192.168.12.1/24 (or 255.255.255.0)

If i set the broadcast address to 255.255.255.255 then i receive the UDP packets on my PC from my arduino.

However, when i use the local broadcast address, eg 192.168.42.255 my network packet application (on my PC) doesnt receive any UDP packets from my arduino which is on ip address 192.168.42.111. (have tried this on another network and have the same results.)

I have used a network packet monitoring application and can see my arduino sending ARP messages requesting the address for 192.168.42.255... i dont see any responses being sent back to the arduino either.

Can you help me understand why this is and what i need to look at to resolve this problem? I'm thinking that if 255.255.255.255 works (UDP and DHCP) then 192.168.42.255 should also work.

Thanks Neil

ntruchsess commented 10 years ago

So far there is no support for directed broadcast in UIPEthernet. It doesn't detect 192.168.42.255 is to be interpreted as a broadcast-address and therefore fires the ARP-request instead of just using FF:FF:FF:FF:FF:FF as ethernet-address. Use limited broadcast to 255.255.255.255 instead.

sitkowsp commented 9 years ago

Hi,

i've got one question about this problem - is there or will be a fix for it?

PS. Good job :)

Best regards Paul