-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNS.c
More file actions
36 lines (32 loc) · 673 Bytes
/
DNS.c
File metadata and controls
36 lines (32 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//DNS (Domain Name System) client server to resolve the given hostname
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<errno.h>
#include<sys/socket.h>
#include<netdb.h>
#include<netinet/in.h>
#include<arpa/inet.h>
int main(int argc,char* argv[])
{
struct hostent* hen;
struct in_addr** addr_list;
if(argc!=2)
{
printf("Usage: <Hostname>");
return 0;
}
hen=gethostbyname(argv[1]);
if(hen==NULL)
{
herror("gethostbyname");
exit(1);
}
printf("Hostname: %s\n",hen->h_name);
addr_list=(struct in_addr**)hen->h_addr_list;
for(int i=0;addr_list[i]!=NULL;i++)
{
printf("IP Address: %s\n",inet_ntoa(*addr_list[i]));
}
return 0;
}