Before continuing, keep in mind that a home "router" works like this:
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/eKwmu.png)
That is, it's a "2 in 1" box that has a router and an Ethernet switch.
In such devices, forwarding between MAC addresses is not done by the 'router' – it's all done by the Ethernet switch. The router's CPU doesn't get any packets that aren't addressed to its MAC address (or the broadcast address).
a) To know the MAC address of B, does A broadcast the message to each machine in the network and populate it in the ARP table or it simply talks to the router since router is the one with whom all device must have registered, so it should know?
The router is not the one with whom all device must have registered. A router really has nothing to do with the functioning of a single subnet – its only job is to forward packets between subnets, but within the same subnet everything is done directly between the hosts themselves, and an isolated subnet could exist without a router at all.
(The closest thing to "router registration" is the automatic IP address configuration through DHCP, which just happens to be usually run on the router for convenience but has zero effect on what the router "knows".)
What connects hosts is just Ethernet itself: packets go through Ethernet switches, or (in older days) through Ethernet hubs, or (in even older times) through a long coax cable, "directly" from one host to another. The router is just another device that's connected to the Ethernet, and it might even be completely unaware of some hosts if they haven't talked to the router specifically.
So the normal answer is "option 1": host A has to broadcast the ARP query and wait until host B itself responds with its own MAC address in the ARP response.
(Of course, networks are flexible enough that there can be exceptions that completely change the behavior, such as Proxy-ARP – e.g. in Wi-Fi networks, often the access point may answer ARP "on behalf of" its wireless devices – but they are still exceptions and not the "normal" way Ethernet networks work.)
b) Once IP and MAC of B are known, does A still send the message to each machine i.e. B and C and C simply rejects it, or it sends to router and router only forwards it to B, so C never gets it?
Technically, neither.
Host A doesn't attempt to broadcast the packet, but it also doesn't attempt to send it to the router either – it attempts to send the packet directly to B; that's why A needed to learn B's MAC address in the first place. But what happens next depends more on the network itself:
In modern Ethernet networks, devices are connected through Ethernet switches, which make sure that a packet addressed to B's MAC address is only forwarded to B and never seen by C (nor by the router, for that matter).
In very old Ethernet networks (which used either hubs or coaxial cables), all packets would reach every device; hosts would have to ignore packets that weren't a) broadcast or b) addressed to them specifically.
When Wi-Fi is involved, you have a mix of both types: packets that stay entirely on wired Ethernet are switched directly to the destination host, but packets that go over Wi-Fi may reach all wireless devices (because Wi-Fi is radio, and radio is broadcast by nature).
So if you have the above "Router" diagram with e.g. host A connected to 'LAN1' and host B connected to 'LAN2', what happens is:
- Host A learns B's MAC address using ARP.
- Host A sends the packet with "destination MAC = (B's MAC address)".
- The router's built-in switch receives it through port LAN1.
- The switch checks its MAC-to-port table to see which Ethernet port B's MAC is at. (Switches "learn" this based on previously seen packets.)
- The switch forwards the packet only through 'LAN2' to host B.
who has xxx.xxx.xxx.xxx?
. If Host A does not know B's IP address, then a DHCP request is first issued for it based on host name. b) Host A sends Ethernet frames addressed to Host B. Only the switches in your LAN are involved; the router is not involved.