Lab: DNS & Sockets
Introduction
In this lab, you will experiment with DNS and Sockets by creating code.
Goals
- Become familiar with the new DNS library and the C sockets interface.
- Play with UDP sockets.
- Prepare for More Wireshark experience.
Acknowledgments
Parts of this assignment are adapted from
exercises in Peterson & Davie (cs105),
and in Kurose & Ross (cs125).
The assignment
also draws upon many other socket problems.
References
-
Course FAQs - some key ideas here
-
Goggle getaddrinfo and sockets and go from there.
-
Also, there is a book,
TCP/IP Sockets in C by Donahoo & Calvert
on the bookshelf in the B111.
Use it, but please do not remove from the area.
- Stevens, UNIX Network Programming, Volume 1, Chapter 6
- man 2 socket and other related manpages from section 2:
- UDP sockets: sendto, recvfrom
-
CS 105 text book.
-
All of these give you too much code, but that is fine. Try not to cut and paste.
Be sure to comment each field in the structs.
Logistics
Once again you are to work in Pairs.
If you are alone or the team is having difficulty
creating code, email mike.
There is code that can be provided to you.
Preparation
While KR references Python solutions, you are to write your solutions in
C or CC.
We strongly recommend that you and
your partner brainstorm before codng.
If you are having
trouble attacking this problem,
look at the socket and ports FAQs which can be found among the course FAQs.
Assignment
Part A: DNS
-
You are to write a DNS access function,
dnsaccess.c,
that takes input from the command line
a fully qualified DNS name
and prints out ALL the returned IP addresses and/or names.
You are creating your own version of NSlookup.
To implement this
function you are to use the new DNS system routines, e.g., getaddrinfo.
dnsaccess.c,
is a standalone program, the results of which you will use in implementing
your echo.
-
Once you are happy with your
dnsaccess.c,
fire up Wireshark and monitor a series of DNS inquires. Namely:
-
Google
-
Amazon
-
MIT
-
choose 3 more
Capture the DNS responses that are replies to your
dnsaccess
requests.
-
Besides your code, the key output of this step
is a printout of ALL the IP addresses that are returned
by the local resolver.
What to Turn-in
-
turn in dnsaccess.c,
-
For each of your DNS queries, the number of IP addresses provided followed by the printout of your
dnsaccess.c that includes addres.
For example, if Wireshark shows 5 IP addresses returned for Google, and your
dnsaccess.c
prints out 3, then your response is: Google, 5:3
-
Be prepared to demo
dnsaccess
to me.
Part B: Sockets
You are to create your own version of
echo.
Modify the client and server from my lecture
(also available in CS 105 book, and everywhere else on
the web)
so that each time the client sends a line to the server, the
server sends the line back to the client.
Note: you also need some print statements as illustrated below.
You (can) are to follow the lecture example with the following additions/clarifications:
-
Do not download any code from anywhere, i.e., enter the code yourselves.
-
Make the Server 'NAME' and Port number
input parameters to your Client (this allows you to easy run on two machine in B105).
-
Use your
dnsaccess.
to get the IP address of the Server.
-
When running use the UNIX id of one partner as the
port number for your Server with the Client port number the UNIX id
of the other partner.
(check out the
id command).
This should (hopefully) avoid conflicts with other services, and with other users.
-
Use IPv4.
-
Run your Server and your Client on different machines, e.g., Knuth and Wilkes or two lab machines.
-
Do not use any of the encapsulated functions provided in the lecture
and the CS105 text, e.g., open clientfd.
Rather, write your own versions in C,
i.e., use standard C or Unix IO libraries.
-
Catch any and all errors that might be generated by any of your library calls.
The extreme of error handling is to recognize an error
and then check the details of the individual error code.
You only need to recognize the error, and quit appropriately.
-
Document your code very well,
i.e., you should mention the man pages and library functions
that your found particularly helpful.
-
Have the Server and the Client use print statements
to indicate what is happening.
For example, each Server or Client print of the echo exchange should begin with:
client: sent XX bytes, "the string..." .
server: received XX bytes from Client IPAddress
server: echoed "the string..."
client: received XX bytes, "the string..." .
etc
When completed have the Server and Client print out the total number of bytes
exchanged.
What to Do and What to Turn-in
-
Once the Server is running, use
netstat to investigate the Socket.
Turn in an annotated screen shot of the Socket that shows whatever fields you can
identify. Look at the Tim Ports FAQ.
-
Fireup Wireshark inorder to watch and capture
the exchange between your Client and Server.
-
Find the Gettysburg Address and use it as the source of your
echo.
-
Start from the beginning and
Type in the Gettsburg Address in phrases that are:
5, 7, 13, 17, 25, 6, 5, 25 words.
-
Capture the exchange on both the Client and the Server screens.
-
Use Wireshark to capture the exchange of 7 words of the Gettsburg Address
- Turn in a screen shot of the Server reply.
-
Finally, enter the entire Gettsburg Address as input to your echo program,
and indicate what happens.
(Trying to blow up your echo, feel free to try a different approach)
Assessment
To earn the equivalent of a B, complete parts A and B .
To earn an A, complete parts A, B, and provide WELL documented code,
along with the discussion
questions.
Advice
This assignment involves programming, so start early and ask for
help if you run into trouble. Keep me posted on how it is going.
Lab Notebook
Besides including the specifics asked for in Parts A and B,
and answers to the discussion questions..
EMAIL ME WHEN YOU HAVE FINISHED THE LAB.
In
your writeup, copy and paste a small amount of output from the terminal
showing that these programs work correctly.
Mark this up using <verbatim></verbatim> tags.
Discussion Questions
-
You were told to run the server on a different machine
from the client. Why?
-
What are the relative merits (pros and cons) of using TCP
versus UDP for a multi-client chat room application?
- How much time did you spend on the three parts of this lab?
In particular, how much time did you spend programming.
CS 105 provides experience in C.
I am curious how long this took for students without CS 105,
i.e., only having had CS 70.
Mike Erlinger
Last Modified Thursday, 26-Sep-2019 16:21:03 PDT