Question
I've covered over some of the url's, if you could just put a placeholder for them (and mark where) I can put the actual ones
I've covered over some of the url's, if you could just put a placeholder for them (and mark where) I can put the actual ones in after
ADDITIONAL INFO GIVEN: The host command on Linux/Unix allows you to map between host names and IP addresses by doing DNS server lookups.
The host command is useful, but also has a wide range of options, most of which you might never need. The aim of this lab is to write a simple version of a DNS lookup program that maps between hostnames and IP addresses.
To do this, you could use some simple library functions:
struct hostent *gethostbyname(char *name) - Takes a hostname (e.g. tuba00.cse.____.edu.__) and returns a pointer to a hostent structure that contains, among other things, an array of IP addresses associated with the hostname. If it cannot resolve the hostname, it returns a NULL pointer.
struct hostent *gethostbyaddr(struct in_addr *ip, socklen_t len, int typ) - Takes an IP address, packaged in an in_addr structure, the size of the structure and an address family, and returns a a pointer to a hostent structure that contains, among other things, an array of IP addresses associated with the hostname. If it cannot resolve the hostname, it returns a NULL pointer. For our purposes, the only useful value for typ is AF_INET.
int inet_aton(char *addr, struct in_addr *ip) - Converts a string representing an IP address (e.g. 129.94.242.51) and converts it to an internet address (in_addr) structure which is used in various network functions. If the addr looks like a "dotted-quad" IP address, then the function returns 1, otherwise it returns 0.
char *inet_ntoa(struct in_addr *ip) - Produces a printable string representation of an IP address stored in an in_addr structure. The string is dynamically allocated, and the function returns a pointer to the first character in the string. CODE GIVEN:
#include
int main(int argc, char **argv) { struct in_addr ip; // see "man 3 inet_aton" struct hostent *hp; // see "man 3 gethostbyname"
if (argc
return 0; }
Exercise You need to write the rest of the main program so that it does DNS lookups and reports results as follows edu. www.cse.edu. -> 129.94.242.51 ./dns 127.0.0.1 127.0.0.1 - localhost $. . /dns 202. 58. 60, 194 No name associated with 202.58.60.194 $ ./dns 129.94.242.51 129.94.242.51 - albeniz.orchestra.cse $ ./dns abc.def.ghi Can't resolve abc.def.ghi EDU. To achieve this requires only about 15 lines of code, but you will need to understand the functions and data types mentioned above. The program will look something like this pseduo-code if (argv [1] looks like an IP address) { use gethostbyaddr) to determine its hostname if (no match) print error message else print "IP -> hostname" else // might be a hostname use gethostbyname) to determine its IP address if (no match) print error message else print "hostname -> IP" You can check your results by comparing the output from your program against the output of the host command. The outputs will not match exactly, but you should be able to determine whether your program has found one of the correct names or IP addressesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started