Mike's Guide to the Sockets Lab
Forget Google to begin with!!!
Try to break the lab down into 'easy' problems.
To me
the following are a reasonable set of steps.
The list is ordered because you really need to attack
things in order!!!
-
dnsaccess.
You should write a program that takes as input a dns name
and spits out an IP address.
I did this in 2 parts:
-
main function
reads in the dns name as a parameter,
then calls the dnsaccess function, then prints out the
returned IP address.
When this is working, you know you understand the data structures
used for dns and partly for sockets.
-
dns function
takes the dns name as a parameter and returns the IP address.
A key point to understand is
the hints datastructure
and exactly what this structure is used for.
-
echoclient.c, initial version
This program should
take two parameters, the server name and port.
dnsaccess should be called to get the IP address.
Then a socket should be set up to access the server.
The socket creation function can be written such that
the server function can use the same code to get a socket.
You can convinced yourself that you have created a socket
by printing out the socketid.
Forget connecting for now,
you should then write code to read in messages from standard input
and print those messages out.
-
echoserver.c, initial version
The echoserver is a rewrite of the echoclient except for
the bind operation and port assignment.
Prove to yourself that you can set up the sockets and
that you can loop through reading and writing data
-
final versions of echoserver and echoclient
Now put them together and make the sockets connect.
-
possible header
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <err.h>
Mike Erlinger
Last Modified Tuesday, 23-Oct-2018 10:17:29 PDT