user5794711
user5794711

Reputation:

Send Packets to another subnet/network using Sockets

I am trying to find out whether the machines in a network are running a certain app. More like, I am trying to resolve addresses of nodes in a network.

I built a small code based on ARP, but it works only on a local network(same subnet). What I want to do is resolve addresses out of the subnet i.e. all other nodes.

I read these answers: UDP broadcast packets across subnets and Broadcast on different subnets

But they all talk about changing router setting or creating a multicast network.

  1. From what I read for multicasting to work, I need to create a multitask network beforehand. Is it really necessary?
  2. And for changing router setting, does it really have to be a "special" router?

This is all for a college assignment and would be demonstrating it probably on an ad-hoc network or something like that. I am open to ideas to solve the original problem.

PS: 1. I am a beginner in networking so do excuse me for any fault or misinterpretation.

  1. I am using sockets and C(No other option).

Edit 1: I am well aware ARP is useless outside the subnet. I mentioned it because I used it and it helped explaining the problem.

Edit 2:

The original problem is:

Building a chat application, nothing fancy sending messages from one point to another, without using a central server of any kind. Not even a hybrid network with a central store is allowed.

i.e. if A and B are two clients, A should directly connect to B and vice versa. I did some research and decided to use P2P architecture. And now I am stuck to how will A discover address of B. If I know the subnet of B, I can brute force and locate B but since I don't have such information what do I do?

Upvotes: 0

Views: 1904

Answers (3)

Gil Hamilton
Gil Hamilton

Reputation: 12347

Adding to what other answers have provided:

ARP is not useful for a system in another subnet. Even if you were able to send an ARP request to a system in the other subnet, and receive its response somehow -- providing you with that system's MAC address -- you could not use it to send a packet to that system because Ethernet does not provide a routing mechanism, and so the system will never see any Ethernet packet you address to it.

If you are simply trying to identify which systems within another IP subnet are live, you can probably do this by other means. Take a look at the nmap command, for example. It supports a wide variety of IP communications methods that will be routed to the other subnet and can often detect what machines are present and which services are available on the machines found.

And you can of course duplicate what nmap does yourself. For example, if you want to find out which systems in subnet 192.168.10.0/24 are listening on TCP port 80, one way is to simply attempt to connect to port 80 on each system in that subnet. In general, there are four answers you may receive back:

  1. Connection success (No error: the machine is present and there is a program listening to that port)

  2. Connection refused (errno ECONNREFUSED: the machine is present but there is no program listening to that port)

  3. No route to host (EHOSTUNREACH: there is no machine answering to that IP address)

  4. No response (ETIMEDOUT: several reasons why this can happen; for example, the system could have firewall settings causing it to simply ignore the request)

(And there are other less likely possibilities as well.) Using other IP access methods (ICMP/ping, UDP packets) will have a different matrix of possible results.

As others have explained, multicast mechanisms would only be helpful for discovering a set of cooperating machines that are pre-configured to join a multicast group.

Upvotes: 0

Ron Maupin
Ron Maupin

Reputation: 6452

The Limited Broadcast (255.255.255.255, which is used by ARP requests as the destination address, and ARP only works for IPv4 on the local LAN) cannot cross a router, and a Network Broadcast (last network address, where the host is all ones) by default cannot cross a router (Directed Broadcast) because it is a security risk (see RFC 2644, Changing the Default for Directed Broadcasts in Routers).

Some routers can be configured to forward directed broadcasts, but this can be dangerous.

Multicast is a form of broadcast. Multicast routing is very different than unicast routing, and every router in a path must be configured for multicast routing. Also, hosts must subscribe to a multicast group before they will even listen for packets from a multicast group. Additionally, there are some multicast groups that all hosts listen for, but those are link-local multicasts that cannot be forwarded off the local LAN.

Upvotes: 1

John Bollinger
John Bollinger

Reputation: 180103

ARP is not intended to be routed outside the local network, where in IPv4, the "local network" typically corresponds to a subnet. You should not expect ARP traffic to transit routers from inside to outside or vise versa.

Similarly, UDP broadcasts generally do not propagate outside the local network, and it's a good thing that they don't, for reasons related to both security and traffic volume.

  1. From what I read for multicasting to work, I need to create a multitask network beforehand. Is it really necessary?

Basically, yes. Your routers need to be configured to support multicasting (which may be their default). All participants need to agree on and join the same multicast group. There might not be a need for any new networking hardware, but multicast communication has its own protocols and network requirements; it is not merely a broadcast that can traverse network boundaries.

  1. And for changing router setting, does it really have to be a "special" router?

If you mean changing router settings so that UDP broadcasts are routed between networks, you do indeed need a router that exposes this capability. But I urge you not to do this, as it will let broadcasts from all other sources, for all other reasons transit the router, too. At minimum, this will significantly increase the noisiness of all networks involved, but it could produce bona fide misbehavior of applications and services other than yours.

Upvotes: 1

Related Questions