I wrote a test program to capture packets for a given domain name. I was using gethostbyname() to retrieve ip address and pcap to capture packets destined for that ip address. The pcap_loop() count was set to -1 so it is supposed to keep capturing.
Theoretically, all packets that send from my pc to that ip address would be captured, regardless of if that domain name is visited by web browser or just by pinging it, right?
After testing, although this is true for many websites, it is not applicable for high-traffic sites like google or ebay. Meaning if I ping the ip address retrieved from the gethostbyname(), the ping packets will be captured by the program, but if I visit google.com on firefox, no packets is captured. That shows there might be a different ip address for the same domain name like google.com.
If that is the case, why the DNS server returns different ips for google.com while others are identical? And what is the different, if there's any, between requests from gethostbyname() and those from web browser?
Thanks in advance.