Into the ip addresses required to communicate with

Info icon This preview shows pages 549–551. Sign up to view the full content.

into the IP addresses required to communicate with the machines (or hosts , as the entities associated with IP addresses are conventionally called). Example 13-22 uses the Dns class in the System.Net namespace to look up the IP addresses for a particular hostname. DNS can associate multiple addresses with a name; for example, a DNS name may have both an IPv4 and an IPv6 address. This code loops through all the addresses, printing their type and value. (If you call ToString() on an IPAddress , which is what Console.WriteLine will do in Example 13-22 , it’ll return the standard string representation for the numeric address.) Example 13-22. Getting the IP addresses for a hostname IPHostEntry hostDnsEntry = Dns.GetHostEntry("localhost"); foreach(IPAddress address in hostDnsEntry.AddressList) { Console.WriteLine("Type: {0}, Address: {1}", address.AddressFamily, address); } This example looks up the special hostname localhost , which always refers to the local machine on which the program is running. Both IPv4 and IPv6 define special addresses that are reserved to refer to the local machine, so if you run Example 13-22 , you’ll see that it prints out two addresses, one for IPv6 and one for IPv4: Type: InterNetworkV6, Address: ::1 Type: InterNetwork, Address: 127.0.0.1 For years, IPv4 was the only IP version in use, so it’s often not qualified with a version number, which is why this IPv4 address’s AddressFam ily property is just displayed as InterNetwork , and not InterNetworkV4 . Many DNS entries don’t have an IPv6 address, and if you modify Example 13-22 to look up such an address (e.g., at the time of this writing, w3.org has only an IPv4 address) you’ll see just one address back from GetHostEntry : Type: InterNetwork, Address: 128.30.52.45 Armed with an IP address for the machine we want to talk to, we now have enough information for the Internet to deliver IP packets to the target machine. But there are a couple of issues to resolve. First, there’s the question of how the receiving machine will know what to do with the packet when it arrives. Second, there’s the problem that the Internet is fundamentally unreliable. TCP (the Transmission Control Protocol ) offers a solution to both of these problems. The Internet does not guarantee to deliver all IP packets. It can’t. Suppose you are using a machine connected to the Internet with a 100 Mbps connection and you try to send data at full speed to a machine that is connected with a 56 Kb modem. (Remember those? In some parts of the world, they’re still used. If you get a chance, try using a Sockets | 525
Image of page 549

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

modern website via a 56 Kb dial-up connection, and then marvel at the fact that 56 kbps modems were once considered really fast.) As we send data to this bandwidth- impoverished machine, the routers between us and them will initially try to manage the speed difference—a router connecting a fast network to a slower network will store incoming packets from the fast network in its memory, and they queue up while it plays them out in slow motion to the target network. But eventually it’ll run out of memory, at which point it’ll just start discarding packets.
Image of page 550
Image of page 551
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '15

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern