Problem Trying to unicast packets to available networks
Asked Answered
V

3

1

Trying to unicast packets to available networks. There are totally 3 networks. Managed to get packets in only one network.But i am not able to receive the packets in different networks.

using this code..

        foreach (var i in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
        {
            foreach (var ua in i.GetIPProperties().UnicastAddresses)
            {
                System.Windows.Forms.MessageBox.Show(ua.Address.ToString());
                IPAddress Tip = IPAddress.Parse(ua.Address.ToString());
                IPEndPoint targetEndPoint = new IPEndPoint(Tip, iTargetPort);
                MyUdpClient sendUdpClient = new MyUdpClient();
                int numBytesSent = sendUdpClient.Send(CombineHeaderBody, CombineHeaderBody.Length, targetEndPoint);
            }
        }

What is the prob ? Thanks.

Voleta answered 8/7, 2009 at 6:58 Comment(0)
R
1

I think that you're trying to send packets to yourself?

Are you sure you're not confusing unicast and multicast addresses?

Ok so you're not trying to multicast...

Each of your network interface has an ip address. What you're doing here is sending a packet to your network card. It is not really a matter of network because your machine most probably knows its own ip addresses and reroute it to 127.0.0.1

Rectitude answered 8/7, 2009 at 7:12 Comment(1)
Yes Eric, i am sure. I want to Unicast the packets to the available networks adapters. I guess the above code does that. I am not getting any error. I am able to get all the network address and send the packets to them. But not receiving the packets in the IPaddress in different network adapters. The code shud be able to unicast to all the available network adapters.Voleta
E
1

Since you have more than one interface you are multihomed. For each interface you will have an IPaddress. So with three interfaces you will have three local IP's. When you use the UdpClient you need to specify which interface to send out by using it's IP.

lets assume you have the following three local IP's

10.1.0.1
10.2.0.1
10.4.0.1
with a netmask of 255.255.0.0

and you want to send a UDP packet to 10.2.5.5 you need to send it out 10.2.0.1 so use the following code

IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("10.2.0.1"), 0);
IPEndPoint targetEndPoint = new IPEndPoint(IPAddress.Parse("10.2.5.5"), iTargetPort);
UdpClient sendUdpClient = new UdpClient(localEndPoint);
int numBytesSent = sendUdpClient.Send(CombineHeaderBody, CombineHeaderBody.Length, targetEndPoint);

and to send a UDP packet to 10.1.90.5 you need to send it out 10.1.0.1 so use the following code

IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("10.1.0.1"), 0);
IPEndPoint targetEndPoint = new IPEndPoint(IPAddress.Parse("10.1.90.5"), iTargetPort);
UdpClient sendUdpClient = new UdpClient(localEndPoint);
int numBytesSent = sendUdpClient.Send(CombineHeaderBody, CombineHeaderBody.Length, targetEndPoint);

The difference between the two are the localEndPoint and the targetEndPoint.

Eurypterid answered 9/7, 2009 at 1:22 Comment(0)
P
0

I'm not much of a network guru, but I'll try to take a stab at it. I assume that all the packets are sent through the default interface which knows of three adresses: it's own, loopback, and gateway. Therefore a packet from 192.168.1.111 destined for 10.10.1.117 would need to pass through the default gateway (let's just say this is 192.168.1.1), but what if 192.168.1.1 does not know the route to 10.10.0.0, then destination host unreachable right? I don't know, that's my guess.

Although, maybe I'm wrong. Maybe it doesn't use a default device and instead uses all available interfaces along with the TCP/IP stack. Anyway, I'm curious to see what you find though. Please keep us updated.

Additionally, noting down the addresses might be helpful. Trace route is your friend.

Pattani answered 8/7, 2009 at 7:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.