DNS

Published on December 2016 | Categories: Documents | Downloads: 22 | Comments: 0 | Views: 199
of 3
Download PDF   Embed   Report

DNS Network Program

Comments

Content


DNS - Domain Name Server - UDP - Networks & DBMS Lab - C Program
Program :
// Client Program : dnsc.c
#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<netinet/in.h>
main()
{
struct sockaddr_in server,client;
int s,n;
char !"!##$,%"!##$;
s&socket('(_)*+,,-./0_123'4,#);
server.sin_5amily&'(_)*+,;
server.sin_port&6###;
server.sin_addr.s_addr&inet_addr(7!%8.#.#.!7);
n&si9eo5(server);
print5(7:n+nter canonical address: 7);
scan5(7;s7,%);
sendto(s,%,si9eo5(%),#,(struct sockaddr <)=server,n);
recv5rom(s,!,si9eo5(!), #,*>??,*>??);
print5(7;s :n7,!);
@
// Server Program : dnss.c
#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<strinA.h>
main()
{
()?+ <5p;
struct sockaddr_in server,client;
int s,n;
char !"!##$,%"!##$,a"!##$;
s&socket('(_)*+,,-./0_123'4,#);
server.sin_5amily&'(_)*+,;
server.sin_port&6###;
server.sin_addr.s_addr&inet_addr(7!%8.#.#.!7);
ind(s,(struct sockaddr <)=server,si9eo5(server));
n&si9eo5(client);
Bhile(!)
{
strcpy(%,77);
5p&5open(7dns.tCt7,7r7);
recv5rom(s,!,si9eo5 !, #,(struct sockaddr <)=client,=n);
Bhile(D5eo5(5p))
{
5scan5(5p,7;s7,a);
i5(strcmp(a,!)&&#)
{
5scan5(5p,7;s7,%);
reak;
@
@
i5(strcmp(%,77)&&#)
{
strcpy(%,7*ot 5ound...7);
@
5close(5p);
sendto(s,%,si9eo5 %,#,(struct sockaddr <)=client,n);
@
@
/* (DNS.txt)
BBB.%kEcs.tk F6.!8#.G%.%#
BBB.AooAle.com !F%.!HE.#.8
BBB.yahoo.com !F%.!HE.#.!H
BBB.%kEH!E.loAspot.com HH.!#%.!6.!F!
*/
Output:
Terminal1: (Client
nnIlinuCmint J K Acc dnsc.c Lo client
nnIlinuCmint J K ./client
+nter canonical address: BBB.%kEcs.tk
F6.!8#.G%.%#
nnIlinuCmint J K ./client
+nter canonical address: BBB.%kEH!E.loAspot.com
HH.!#%.!6.!F!
nnIlinuCmint J K
Terminal !: (Server
nnIlinuCmint J K Acc dnss.c Lo server
nnIlinuCmint J K ./server

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close