Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2005

Tip: Looking for answers? Try searching our database.

Socket Broadcasting with Multiple Adapters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ian Smith - 10 May 2005 19:57 GMT
I'm getting some weirdness when sending out broadcasts on a system with two
adapters. The adapters are configured with IP addresses on seperate subnets.
Packets get sent out on each interface, but the source addresses (as seen
from a packet sniffer) on both packets is the IP address for adapter #1. This
creates a problem when clients on adapter #2's network try to respond because
they can't reach the source address on adapter #1's network.

Here's some code that illustrates the problem:
public static void Main(string[] args)
{
    byte[] bytes = Encoding.UTF8.GetBytes("Testing broadcast...");
    IPEndPoint endpoint = new IPEndPoint(IPAddress.Broadcast, 10485);
    Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
   
    socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1);
    socket.SendTo(bytes, endpoint);
}

My question is, am I doing something wrong? Or is this expected (or even
desired) behavior? If so, any ideas how I could make it work correctly?
Arthur M. - 11 May 2005 19:22 GMT
From your code it is not clear what is "IPAddress" for (IPAddress.Broadcast)

Try to make sure your socket is bound to 0.0.0.0 IP address

beyond that - it is wierd

> I'm getting some weirdness when sending out broadcasts on a system with two
> adapters. The adapters are configured with IP addresses on seperate subnets.
[quoted text clipped - 18 lines]
> My question is, am I doing something wrong? Or is this expected (or even
> desired) behavior? If so, any ideas how I could make it work correctly?
Ian Smith - 11 May 2005 19:38 GMT
IPAddress.Broadcast is a reference to the broadcast address statically
provided by the IPAddress class. It's in there for code readability. I've
also tried sending to IPAddress.Parse("255.255.255.255") with the same
result. As for binding to 0.0.0.0, I've tried that before as well: no luck.

> From your code it is not clear what is "IPAddress" for (IPAddress.Broadcast)
>
[quoted text clipped - 24 lines]
> > My question is, am I doing something wrong? Or is this expected (or even
> > desired) behavior? If so, any ideas how I could make it work correctly?
Arthur M. - 11 May 2005 20:12 GMT
There are two problems here,

I have not tried broadcasting through socket - hence theory here:

If binding to 0.0.0.0 does not work (I wonder what is the source then)
you have to open a socket per network card;

Also remember, that when you broadcast, you should broadcast to a local
network doing otherwies is bad networking.

Broadcasts wont always fall into x.x.x.255 scheme, you are looking at IP
Address + MASK combination; without going into a lecture

if I have a class C with address of 192.168.1.0, which i split into 29 bit
nets, I will get

192.168.1.0 / broadcast 192.168.1.7, 192.168.1.8 / broadcast 192.168.1.15
etc...
Just watch out for that, because broadcasting to 192.168.1.255 in that case
will deliver data to supernet if it is reachable:)

Thinking of that, it does make sense to use 2 different sockets, to make
sure each of your networks gets its own handling for broadcasted data.

> IPAddress.Broadcast is a reference to the broadcast address statically
> provided by the IPAddress class. It's in there for code readability. I've
[quoted text clipped - 29 lines]
> > > My question is, am I doing something wrong? Or is this expected (or even
> > > desired) behavior? If so, any ideas how I could make it work correctly?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.