Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong MAC when sending broadcast #59

Closed
thefrip opened this issue Nov 1, 2012 · 9 comments
Closed

Wrong MAC when sending broadcast #59

thefrip opened this issue Nov 1, 2012 · 9 comments

Comments

@thefrip
Copy link

thefrip commented Nov 1, 2012

Hello,

When sending a broadcast packet (255.255.255.255) the recipient MAC remains to 00:00:00:00:00:00. If not wrong, it should be also set to the broadcast MAC (as for the WOL packets for instance).

I made the following fix in tcpip.cpp, function EtherCard::udpPrepare:

replaced
if ((dip[0] & 0xF0) == 0xE0) // multicast address

by
if ((dip[0] & 0xF0) == 0xE0 || *((long *) dip) == 0xFFFFFFFF) // multicast or broadcast address

Seems to work.

Rgds,

L.

@jcw
Copy link

jcw commented Nov 1, 2012

Committed, thanks.

@jcw jcw closed this as completed Nov 1, 2012
@rawouter
Copy link

rawouter commented Nov 1, 2012

Hi there!

First post so: thanks a lot for the work, I'm using this lib for a while now! Best one IMO :-)

I was actually using the following hack to cope with this issue, because I want to send the packets to the network broadcast IP, not full broadcast (i.e. 192.168.1.255) :

if ((dip[0] & 0xF0) == 0xE0 || dip[3] == 0xFF)

Thanks!
R.

@thefrip
Copy link
Author

thefrip commented Nov 2, 2012

Indeed, works as well. But I thought the partial broadcast was not
working on the card, only the full one?

Le 01/11/2012 20:54, RaphYot a écrit :

Hi there!

First post so: thanks a lot for the work, I'm using this lib for a
while now! Best one IMO :-)

I was actually using the following hack to cope with this issue,
because I want to send the packets to the network broadcast IP, not
full broadcast (i.e. 192.168.1.255) :

if ((dip[0] & 0xF0) == 0xE0 || dip[3] == 0xFF)

Thanks!
R.


Reply to this email directly or view it on GitHub
#59 (comment).

@thefrip
Copy link
Author

thefrip commented Nov 2, 2012

You are welcome.

Le 01/11/2012 10:19, Jean-Claude Wippler a écrit :

Committed, thanks.


Reply to this email directly or view it on GitHub
#59 (comment).

@rawouter
Copy link

rawouter commented Nov 2, 2012

I can send broadcast packet that way without issue. The only problem I see is that it's just a partial solution as without the mask you don't know the real broadcast address.

What kind of issue do you mean? With the new lib it seems I'm not receiving my network broadcast anymore on the arduino (although I enabled broadcast), but it was working on an older project so I suppose this should be feasible.

@jcw
Copy link

jcw commented Nov 2, 2012

I'd be happy to change it to a single-byte check, and just make 255.255.255.0 the default netmask that way. Ought to work for msot cases.

@shagru
Copy link

shagru commented Oct 25, 2013

I am having problem with sendUdp() and I traced the problem to this line
if ((dip[0] & 0xF0) == 0xE0 || ((long) dip) == 0xFFFFFFFF)
EtherCard::copyMac(gPB + ETH_DST_MAC, allOnes);
After commenting out this line, and sendUdp() works nicely. With this line, the sending would fail. The problem is reported in the following post by others as well...
http://jeelabs.net/boards/7/topics/1179

Does anyone know what the problem is?

@jnogues
Copy link

jnogues commented Feb 3, 2015

I'm try use sendTcp() and doesn't work, but if comment the line proposed for shagru, then works OK.
Thanks for your trick, but why is not change in the library?

@comotion
Copy link

The problem @shagru has might be related to the multicast check (I don't know) but @jnogues makes no sense, those lines are unrelated to sendTcp()

I also have the problem that UDP broadcast has a mac of 0x00000000, and the proposed fix doesn't work for me because I do

  ether.sendUdp((char*) buf, pos, srcport, ether.broadcastip, dstport);

Would the fix be more correct if the check was for ether.broadcastip?

    if ((dip[0] & 0xF0) == 0xE0 || *((unsigned long*) dip) == 0xFFFFFFFF 
            || (memcmp(dip, EtherCard::broadcastip, 4) == 0)) //not subnet broadcast
        EtherCard::copyMac(gPB + ETH_DST_MAC, allOnes);

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants