Aim:
- To Domain Name Service (DNS) using UDP protocol.
Requirement:
- PC with UNIX/ Linux Operating systems.
- C compiler in Linux Environment
Algorithm:
- Start the program
- Include necessary header files such as sys/socket.h, sys/types.h, neinet/in.h
- Create the variable for predefined structure hostent
- Get the members of the structure as Name, Address, Address type, Alias and address list with the
- help of the structure variable.
- Print all the output
- End the program.
Program:
#include <sys/types.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
int main()
{
struct hostent *h;
h=gethostbyname("www.amazon.com");
if(h==NULL)
{
herror("ERROR\n");
}
else
{
printf("\n Name :%s ",h->h_name);
printf("\n Address:%s ",inet_ntoa(*(struct in_addr*)h->h_addr));
printf("\n Addresstype is %d",h->h_addrtype);
printf("\n Alias:%s",h->h_aliases[0]);
printf("\n Address list:%s\n",inet_ntoa(*(struct in_addr *)h->h_addr_list[0]));
}
return 0;
}
Code language: PHP (php)
Output:
Name :e15316.a.akamaiedge.net
Address:23.11.225.174
Addresstype is 2
Alias:www.amazon.com
Address list:23.11.225.174
Code language: CSS (css)
Result:
The domain name service using UDP protocol was successfully verified.