improved exit handling by using atexit()

Previously if the echo server/client was exited with
Ctrl-C or Ctrl-D the program would exit without calling
the cleanup functions (close(sockfd), freeaddrinfo).
Now the atexit() function has been used to guarantee
that cleanup is performed under all normal exit scenarios.