How does a device search for available wifi networks?

view full story

http://serverfault.com – Say you have a wifi device (D) and a wifi router (R) that have never shared radio waves before, and are within range. How does D discover that R exists? Does R constantly broadcast a message with its MAC, SSID, etc that D will eventually passively pick up? The other way around? Some combination? In general, what messages are sent between D and R that will ultimately produce that wonderful list of available networks to choose from (including details such as SSID [or lack thereof], encryption mechanism, etc)? Bonus: What, if any, is the difference between this and ARP? (HowTos)