Date: Wed, 20 Jul 2005 23:07:58 -0500 From: "Ryan Rathje" <MrSharky@iastate.edu> To: <freebsd-net@freebsd.org> Subject: hostent modification Message-ID: <200507210408.j6L48TZo003076@mailhub-3.iastate.edu>
next in thread | raw e-mail | index | archive | help
I'm trying to write a custom dns program that instead of calling the "gethostbyname(query)" to resolve an IP, it calls my get_rand_ip(query) function. Now, the background is thus: I'm trying to have our gateway pick a random IP and send it back to the client that requested the query (say client asks for www.google.com <http://www.google.com/> , and custom dns programs returns 123.123.123.123). This may be confusing as to why I want to do this, think simulating the Internet within a controlled environment. I'm able to fill in all parts of the hostent struct except for **h_addr_list. struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } So to make this mess a little clearer, how to do "inject" an (random) IP into the variable "**h_addr_list"? Here is a snippet of my code: #include <string.h> #include <stdlib.h> #include <stdio.h> #include <netdb.h> struct hostent get_rand_ip(char *query); struct hostent get_rand_ip(char *query) { struct hostent myHost; char ch[] = "123.122.121.111"; myHost.h_name = query; myHost.h_aliases = NULL; myHost.h_addrtype = AF_INET; myHost.h_length = 4; myHost.h_addr_list = (char *) ch; return myHost; } Lastly, I what would the corresponding printf statement be for verifying that my random ip did get assigned properly to h_addr_list? Thanks to all that took the time to read this.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507210408.j6L48TZo003076>