COE 4DN4 Lab1: DNS-Domain Name Server
COE 4DN4 Lab1: DNS-Domain Name Server
1/31/2010
Objective:
The objective of this lab experiment is to create a Domain-Name- Server by editing the given Server Code.
Instead of echoing back the received string. This program reads in a Table from a text file with the URL and
its appropriate IP address. The program checks the URL received from the client and compares it with the
Table from the text file. If it finds a match it sends back the IP address of the URL. If it doesn’t it sends an
error message.
Introduction:
The DNS server stores the IP address for each and every URL . When a URL is typed into the address bar of
a browser. The browser sends a message to the DNS server requesting its IP address. The DNS server looks
up the URL using a look up and table and sends the corresponding IP address back to the browser.
Client Side
Server Flow Chart
TCPEchoServer.c
HandleTCPClient.c
Server Code
TCPEchoServer.c
if (WSAStartup(MAKEWORD(2, 0),&wsaData) != 0)
{
fprintf(stderr,"WSAStartup()failed");
exit(1);
}
/* Create socket for incoming connections */
if ((servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
DieWithError("socket() failed");
HandleTCPClient(clntSock);
}
/* NOT REACHED */
}
TCPEchoServer.h
HandleTCPClient.c
#include <stdio.h> /* for printf() and fprintf() */
#include <winsock.h>
#include <stdlib.h>
#define RCVBUFSIZE 32 /* Size of receive buffer */
} Table[16];
char testing1[128];
char testing2[32];
char junk[100];
int status=0;
strcpy(Table[j].name,testing1);
strcpy(Table[j].IP,testing2);
j++;
}
fclose(fptr);//file pointer closed
DieWithError
#include <stdio.h> /* for perror() */
#include <stdlib.h> /* for exit() */
#include <winsock.h>
Client Code
TCPEchoClient.c
if ((argc < 3) || (argc > 4)) /* Test for correct number of arguments */
{
fprintf(stderr, "Usage: %s <Server IP> <Echo Word> [<Echo Port>]\n",
argv[0]);
exit(1);
}
closesocket(sock);
WSACleanup();
exit(0);
}
DieWithError
#include <stdio.h> /* for perror() */
#include <stdlib.h> /* for exit() */
#include <winsock.h>
Conclusion:
Getting the code to run on a windows platform was the only difficulty initially incurred. The code was initially built to
run using a table initialized within the program. But then we made the program read the table in from a text file and
store it in a structure. While doing this we had some trouble compiling the code and getting it to run with the text file.
But that was quickly sorted out.