0% found this document useful (0 votes)
81 views7 pages

DOMAN Document

1) The document contains code for a basic DNS server and client program written in C. 2) The server code defines a structure to store domain names and IP addresses, then accepts user input to populate an array of these structures. 3) It then creates a socket, binds an address, and listens for connections. On receiving a request, it searches the array and sends the matching domain or IP back to the client. 4) The client code connects to the server, sends a request, and prints the received response.

Uploaded by

Narendra Babu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views7 pages

DOMAN Document

1) The document contains code for a basic DNS server and client program written in C. 2) The server code defines a structure to store domain names and IP addresses, then accepts user input to populate an array of these structures. 3) It then creates a socket, binds an address, and listens for connections. On receiving a request, it searches the array and sends the matching domain or IP back to the client. 4) The client code connects to the server, sends a request, and prints the received response.

Uploaded by

Narendra Babu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PROGRAM: SERVER: #include<stdio.h> #include<string.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<time.h> #include<arpa/inet.

h> int i; struct bash { char domain[20]; char ip[20]; }p[6]; int main(int argc,char** argv) { int sock,nsd,n; int len; time_t ti; printf("\n enter the domain IP and client IP address"); for(i=0;i<=5;i++) scanf("%s \t %s",&p[i].domain,&p[i].ip);

struct sockaddr_in servaddr,cliaddr; char buff[10],str[100]; sock=socket(AF_INET,SOCK_STREAM,0); if(sock>0) printf("\n socket is created"); bzero(&servaddr,sizeof(servaddr)); servaddr.sin_port=htons(2345); servaddr.sin_family=AF_INET; servaddr.sin_addr.s_addr=htons(INADDR_ANY); n=bind(sock,(struct sockaddr*)&servaddr,sizeof(servaddr)); if(n==0) printf("\n binded with address"); listen(sock,5); len=sizeof(cliaddr); nsd=accept(sock,(struct sockaddr*)&cliaddr,&len); if(nsd!=-1) printf("\n connection is accepted"); printf("\n domain \t IP address"); for(i=0;i<=5;i++) { printf("\n %s \t %s",p[i].domain,p[i].ip); recv(nsd,buff,200,0); }

for(i=0;i<=5;i++) { if(strcmp(p[i].domain,buff)==0) { printf("\n found"); send(nsd,p[i].domain,200,0); } else if(strcmp(p[i].domain,buff)==0) { printf("\n found"); send(nsd,p[i].ip,200,0); } } close(sock); }

CLIENT: #include<stdio.h> #include<string.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<time.h> #include<arpa/inet.h> int main(int argc,char** argv) { int sockfd,nsd,n; int len,choice; time_t ti; struct sockaddr_in servaddr,cliaddr; char buff[10],str[100]; sockfd=socket(AF_INET,SOCK_STREAM,0); bzero(&servaddr,sizeof(servaddr)); servaddr.sin_port=htons(2345); servaddr.sin_family=AF_INET; servaddr.sin_addr.s_addr=htons(INADDR_ANY); nsd=connect(sockfd,(struct sockaddr*)&servaddr,sizeof(servaddr)); if(nsd!=-1) printf("\n connected");

printf("\n enter the IP ADDRESS"); scanf("%s",buff); send(sockfd,buff,200,0); recv(sockfd,buff,200,0); printf("\n domain IP is:%s \t",buff); close(sockfd); }

OUTPUT (SERVER): [user@localhost ~]$ cc dnsserver.c [user@localhost ~]$ ./a.out enter the domain IP and client IP address google bbb ccc ddd eee fff ggg hhh iii jjj kkk lll socket is created binded with address connection is accepted domain google ccc eee ggg iii kkk IP address bbb ddd fff hhh jjj lll

OUTPUT(CLIENT): [user@localhost ~]$ cc dnss.c [user@localhost ~]$ ./a.out connected enter the IP ADDRESS bbb domain IP is:google

You might also like