LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-08-2005, 10:28 AM   #1
btn_paragon
LQ Newbie
 
Registered: Sep 2005
Location: Nashville,TN, USA
Posts: 3

Rep: Reputation: 0
Why Does a Broadcast on a Raw Socket get echoed back to me?


I am working on a project that has 2 computers connected via Gig Ethernet both running linux. The idea is that one computer (Host A) will receive a bunch of data process it and send it back to the other machine (Host B)..

I am using a raw socket and broadcasting the data between the 2 machines. I want to use broadcast because I need to be able to replace Host A or B without changing any configuration (ie configuring the src an dest MAC Addresses), plus this is a point-to-point network without any other machines on it.

The problem is that when I send data this way, my recieve raw socket (on the same machine) also gets the data that I am sending out.

Why is this?

I know that I can filter the data out with recieve code but I would rather not have this happen in the first place. I don't want this data clogging up the system while I am trying to recieve the real data from the other host.

This is how my socket is created.

Code:
s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
I am binding it to an interface (ie eth0), and using sendto and recvfrom.

Any ideas?

Thanks!
 
Old 09-08-2005, 10:48 AM   #2
F0ul_Olli
Member
 
Registered: Aug 2005
Location: Flintshire, WALES, UK
Distribution: Slackware
Posts: 57

Rep: Reputation: 15
It sounds to me like you need to put the IP address of the second PC into the first PC and only send to that.

When you broadcast in a normal network, you are sending data to everyone, regardless of if they want it or not, all you are getting is the data you sent, being sent to you as a member of the network.

You could set your PC up as to ignore packets from your IP address, but I'm not sure if that is going to cripple something else.

Hope that helps a little

F0ul Oli
 
Old 09-08-2005, 10:54 AM   #3
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
I'm not very knowledgeable about this topic, but my first guess is: It's not a bug, it's a feature. Broadcasting means, sending some data to every interface on the subnet, and since the sending interface is part of the subnet, it receives the data as well.
To circumvent the problem (and still provide plug-'n'-play), you could get the addresses of all interfaces on the subnet (should be two) and filter the own one out, which leaves the destination address. However, I don't know whether and how this can be done.


Edit: Someone was faster. I should learn to type with 180 keystrokes/minute

Last edited by addy86; 09-08-2005 at 11:00 AM.
 
Old 09-08-2005, 04:16 PM   #4
btn_paragon
LQ Newbie
 
Registered: Sep 2005
Location: Nashville,TN, USA
Posts: 3

Original Poster
Rep: Reputation: 0
It make some sense to me, I had just hoped that there was a way around it.. The man page for packet lead me to think that there should be a way.

Quote:
Packet sockets are used to receive or send raw packets at the device driver
(OSI Layer 2) level. They allow the user to implement protocol modules in user space on top of the physical layer.
I seems to me that if this was true, the raw_socket would be very deep in the network stack and not even be able to cause this "loopback" to happen since this is a direct interface to the device dirver..

I think that I am going to try to implement a system to detect and configure the dst MAC addresses automatically.

Thanks
 
Old 09-09-2005, 03:05 AM   #5
F0ul_Olli
Member
 
Registered: Aug 2005
Location: Flintshire, WALES, UK
Distribution: Slackware
Posts: 57

Rep: Reputation: 15
You don't need the MAC address, just the IP address.

I would assume that the sending one would be something like 192.168.0.1 and the other is 192.168.0.2

Just send all your stuff to 192.168.0.2 and you shouldn't have any problems.


Hope this helps
 
Old 09-09-2005, 07:32 AM   #6
btn_paragon
LQ Newbie
 
Registered: Sep 2005
Location: Nashville,TN, USA
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by F0ul_Olli
You don't need the MAC address, just the IP address.
Not true. The interface does not even have an IP address set. This is not using the IP protocol. This is pure 802.3. In fact PF_PACKET with SOCK_RAW means that I have to provide the ethernet header (src MAC, dst MAC, Type/Len) in the buffer that is given to sendto. It just puts it on the wire as is.


tn
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Raw socket with perl Whiteghost Linux - General 1 10-14-2005 10:29 AM
Help with raw socket programming tuxfood Programming 2 07-25-2005 01:17 PM
Raw Socket Programing djgerbavore Programming 2 08-18-2004 12:58 PM
Socket Raw linuxanswer Programming 1 04-01-2004 09:43 PM
raw socket permition moonloader Linux - Networking 2 12-08-2003 09:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration