ARP : What Mac ARP does request when a Host want to communicate to Host in different Network - arp

Please Clarify my doubt in ARP. In the below Topology,.
Looking for better understanding, how ARP works when Hosts are connected between default Gateways .
Host A(10.10.10.1)-----Switch-----(10.10.10.2)Router(20.20.20.2)--------HostB
When a Host want to communicate to Host B , does hostA send an ARP request for Destination IP (20.20.20.1) or to Default Gateway (10.10.10.2) .
If it send ARP for HOST B mean, Host A identifies Host B is in different network, it will send the Packet only to the Configured Default Gateway , so will it request for Default Gateway Mac address
Host B mac will not be learnt by Host A by any cost, So does Host A will generate ARP request for each time?

Since a MAC address is only useful for a layer-2 domain which is bounded by a layer-3 device (router), a host will not ARP for a MAC address on a different subnet unless it has a misconfigured mask.
The host will ARP for the address of its configured gateway so that it can send the frame to the gateway, and the gateway will remove the layer-2 frame and try to forward the layer-3 packet to the port toward the end host. The router will then encapsulate the layer-3 packet with a new layer-2 frame (possibly using ARP if the nest hop isn't in its ARP cache) for the next link.

Related

Unable to ping from GNS3 topology to Physical Adapter

I'm trying to setup a connection b/w GNS3 Router and Local PC. Following are the steps done so far in GNS3:-
1. setup a router interface, e0/0/ = 192.168.1.1 255.255.255.0
2. created a cloud loopback adapter, interface, and assigned IP = 192.168.1.5 255.255.255.0
(Note: loopback adapter has been created as Mictosoft KM-Test loopback on my PC. and same interface has been added to cloud in GNS3 which is then connected to Router interface, e0/0)
When I tried ping from my PC to GNS3 R, arp entries get created in Router (running on GNS3 topology). See below:
RTR#sh arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 192.168.1.1 - aabb.cc00.0200 ARPA Ethernet0/0
Internet 192.168.1.5 134 0200.4c4f.4f50 ARPA Ethernet0/0
But ICMP isn't successful on Router (See below) :-
RTR#ping 192.168.1.5
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.3, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
Can anyone help here pls ??
Try setting the IP address of the KM-Test adapter to an address outside your home network. Such as 10.0.0.1/24. Attach your cloud to the network adapter and then create persistent static routes by opening a command prompt as administrator and entering the command.
route -p add [Destination] mask [Subnet Mask] [Gateway(KM-Test)]
Note that any additional network you create within GNS3 will need a static route so that windows knows to send your packets through the KM-Test rather than your home network gateway.

Using Wifi module ESP8266 to send UDP broadcast message

I need to communicate Arduino module with my Phone through ESP8266 wifi module
They all link to the local LAN network and didn't know the IP address of each other, so I plan to send UDP broadcast message from my phone, but ESP8266 module seems doesn't receive the message
The ESP8266 library I use is from here:
https://github.com/itead/ITEADLIB_Arduino_WeeESP8266
and use the function registerUDP() and recv()
Can somebody help me?
I don't have enough reputation to leave a comment so I will make an answer.
I have a feeling that your registerUDP() need to specify an IP address and I guess you are supplying your DHCP assigned IP address. Where as the UDP broadcast is sent using a multicast or broadcast IP.
You can modify the initiator code to send UDP packet to all IP within the same subnet (e.g. 192.168.1.1 to 192.168.1.254) and see if it works.

Forwarding UDP packets in C using the socket API

I am writing a content filter in C using the socket API that will intercept DNS requests, and only return the response if the domain is allowed. The pseudocode to describe this is:
Redirect all DNS queries to the content filter program which is listening on UDP port X.
Content filter program extracts domain being queried and determines if it is allowed or not.
If it is allowed, then the content filter program forwards the original DNS request packet to the original destination DNS server while maintaining the original source and IP+port so that the DNS server can send the reply directly back to the client.
If the domain is not allowed, then no reply is sent.
I currently have the program listening on UDP port X but the problem is that I can't access the IP headers, and therefore can't simply forward the DNS request to the original server while maintaining the original headers.
I have tried using socket(AF_INET, SOCK_RAW, IPPROTO_UDP) but that doesn't bind on port X (understandably), and doesn't receive any traffic.
What is the best way to go about listening on UDP port X, while still being able to access the IP headers of incoming packets?
I think recvfrom on an UDP socket should give you the correct source address. You still probably need a raw socket for forwarding the message.
The functionality for SOCK_RAW based sockets varies depending on the platform you are on. Generally, when you want to get access to the full IP datagram information, then I would recommend using the Berkeley Packet Filter to tap the data-link layer frames addressed to UDP port of interest.

Raw Sockets - Internet Protocol Layers

I have been working with Raw Berkeley Sockets in C, which allow the programmer to access Layer 2 (IP Headers) of the Internet Protocol Suite. I would like to know how the raw sockets handle transport on Layer 1 (Link Layer), specifically with regard to wireless local area networks.
For example, how does the socket know which network interface (eth0 or wlan0) to send the packet to?
If I am behind a wireless router, should I still fill the IP Source Address of my IP Header with my LAN address (192.168.1.1), or with the internet address (74.125.226.68) of my router?
If I do fill the IP Source address with my LAN address (192.168.1.1), does the IP Header get changed when it goes through the router, or does it stay that way, so that the receiving end of the packet attempts to send the response to a local host on its network?
I would appreciate any insights in this area.
For example, how does the socket know which network interface (eth0 or wlan0) to send the packet to?
You can use the socket option SO_BINDTODEVICE to bind your socket to a specific interface. Otherwise, the operating system chooses one.
If I am behind a wireless router, should I still fill the IP Source Address of my IP Header with my LAN address (192.168.1.1), or with the internet address (74.125.226.68) of my router?
You should use your LAN address. The router is responsible to take care of NAT (network address translation) if necessary.
If I do fill the IP Source address with my LAN address (192.168.1.1), does the IP Header get changed when it goes through the router, or does it stay that way, so that the receiving end of the packet attempts to send the response to a local host on its network?
If NAT is enabled at the router, the source address is changed to reflect the router's external address. Otherwise, your packages are likely to be dropped by routers or firewalls, because your source address is invalid in their context.

Communicate to public IP from a local network (WinSock, C)

I'm new to this forum (at least at asking questions), so please be patient. I'm trying to write simple client-server applications to communicate using datagram (UDP) sockets, with C and Windows.
The scenario is very simple, I want to be able to send/receive data from a machine in some local network (behind a GATEWAY/NAT) to some host having public IP. I can send the data, but it seems impossible to receive any data back, because the remote server can't see the client's local IP.
I don't want the user to perform manual port forwarding on the GATEWAY, and I also don't want to use UPnP because of security issues (though it also should be enabled by the user).
I think it is possible because applications like Skype or Browsers can do it, but how ?
Are there some automatically forwarded ports or things like that ? I'm exhausted of searching the web ... PLEASE HELP !
For UDP connections, most home NAT gateways will automatically create a temporary reverse mapping for each outbound packet.
Consider a scenario where your client is running on the internal machine with IP address 192.168.4.5, sending a UDP packet from port 65000 to the external address 64.34.119.12:6789, via a gateway with external IP address 192.0.43.10. When the gateway sees your internal client send a UDP packet from 192.168.4.5:65000 to the external address, it will NAT it to an external address and port, like 192.0.43.10:5500. Your server will see a packet with a source address of 192.0.43.10:5500 and destination address 64.34.119.12:6789. The router also sets up a reverse mapping, so that if it sees a packet arrive on the external interface with a source of 64.34.119.12:6789 and a destination of 192.0.43.10:5500, it will redirect it back to 192.168.4.5:65000. This mapping typically times out after a short while.
This means that in simple cases, all you need to do is:
On the client, use the same port to send to the server and listen for responses;
On the server, respond to the client at the address and port that the client's packet was receieved from, using the same server port that recieved the packet;
Have the client send the initial packet in the conversation;
Don't leave the "connection" idle for more than a few minutes at a time.

Resources