when I type wget http://yahoo.com:80 on unix shell. Can some one explain me what exactly happens from entering the command to reaching the yahoo server. Thank you very much in advance.
+1
A:
RFC provide you with all the details you need and are not tied to a tool or OS.
Wget uses in your case HTTP, which bases on TCP, which in turn uses IP, then it depends on what you use, most of the time you will encounter Ethernet frames.
In order to understand what happens, I urge you to install Wireshark and have a look at the dissected frames, you will get an overview of what data belongs to which network layer. That is the most easy way to visualize and learn what happens. Beside this if you really like (irony) funny documents (/irony) have a look at the corresponding RFCs HTTP: 2616 for example, for the others have a look at the external links at the bottom of the wikipedia articles.
jdehaan
2010-07-06 05:06:25
A:
- The program uses DNS to resolve the host name to an IP. The classic API call is
gethostbyname
although newer programs should usegetaddrinfo
to be IPv6 compatible. - Since you specify the port, the program can skip looking up the default port for http. But if you hadn't, it would try a
getservbyname
to look up the default port (then again, wget may just embed port 80). - The program uses the network API to connect to the remote host. This is done with
socket
andconnect
- The program writes an http request to the connection with a call to
write
- The program reads the http response with one or more calls to
read
.
R Samuel Klatchko
2010-07-06 05:15:10