hostent modification
Ryan Rathje
MrSharky at iastate.edu
Thu Jul 21 04:08:44 GMT 2005
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.
More information about the freebsd-net
mailing list