IC221: Systems Programming (SP17)


Home Policy Calendar Units Assignments Resources

HW 11: Network Addressing

Instructions

  • You must turn in a sheet of paper that is neatly typed or written answering the questions below. (You are strongly encouraged to type your homework.)
  • This homework is graded out of 90 points. Point values are associated to each question.

Questions

  1. (5 points) What are the two parts of a packet? Which stores the address and what stores the data?
  2. (5 points) What does it mean for the Internet to be "packet switched"?
  3. (5 points) What are the different layers of the protocol stack and what purpose do they serve in delivering a packet?
  4. (5 points) An Internet address (version 4) is stored in how many bytes?
  5. (5 points) A domain name, unlike an IP address, is more human usable, what protocol enables domain names to be resolved into IP addresses?
  6. (15 points) Using the host command line tool, resolve the following domain names to an IPv4 address(es). Indicate those that also have IPv6 addresses, and also, rerun host a few times, indicate which hosts IP addressed changed on subsequent runs.
    1. www.cis.upenn.edu
    2. www.cs.swarthmore.edu
    3. www.usna.edu
    4. facebook.com
    5. microsoft.com
  7. (5 points) What is the purpose of the port address? How many bytes and what C type would naturally store a port address?
  8. (5 points) TCP provides reliable data transmission, but at what cost? Why might you want to use UDP over TCP?
  9. (20 points) For each of the descriptions below of a network type, indicate the type that best matches that description. Options include: struct in_addr, in_addr_t, s_addr, struct sockaddr, struct sockaddr_in, sin_family, sin_port, sin_addr, struct addrinfo, ai_family, ai_addr.
    1. Specifies the address type, e.g., AF_INET, for the addrinfo structure.
    2. Specifies the addres type, e.g., AF_INET, for the sockaddr_in structure.
    3. A type defined as a uint32
    4. A generic address structure for sockets
    5. A structure to store an IPv4 Internet address
    6. An unsigned short storing the port for a sockaddr_in
    7. Structure used to hint at IP addresses for resolving as well as storing results.
    8. Member of the sockaddr_in that stores the address
    9. The sole member of the in_addr structure
    10. A generic socket address returned in a addrinfo
    11. A specific address structure for sockets to store IP, port pairs
  10. (5 points) The following functions are opposites, inet_ntoa() and inet_aton(), what are their purposes? Provide a small example.
  11. (5 points) When assign a port to a socket address, which of these two conversion should you use and why? htnos() vs. nths().
  12. (10 points) Consider setting the address 10.4.32.41 on port 22. Complete the code below to do that.

    struct sockaddr_in saddr;
    
    //TODO: what assignments come next?