From owner-freebsd-net@FreeBSD.ORG Thu Jul 21 04:08:44 2005 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7BB4F16A421 for ; Thu, 21 Jul 2005 04:08:44 +0000 (GMT) (envelope-from MrSharky@iastate.edu) Received: from mailhub-3.iastate.edu (mailhub-3.iastate.edu [129.186.140.13]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4E55843D97 for ; Thu, 21 Jul 2005 04:08:31 +0000 (GMT) (envelope-from MrSharky@iastate.edu) Received: from mailout-2.iastate.edu (mailout-2.iastate.edu [129.186.140.2]) by mailhub-3.iastate.edu (8.12.10/8.12.10) with SMTP id j6L48TZo003076 for ; Wed, 20 Jul 2005 23:08:29 -0500 Message-Id: <200507210408.j6L48TZo003076@mailhub-3.iastate.edu> Received: from plan-99-98.icsincorporated.com(206.61.99.98) by mailout-2.iastate.edu via csmap id bf6db00e_f99e_11d9_8d82_003048290bef_769; Wed, 20 Jul 2005 23:20:46 -0500 (CDT) From: "Ryan Rathje" To: Date: Wed, 20 Jul 2005 23:07:58 -0500 MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook, Build 11.0.6353 Thread-Index: AcWNqcbkIiOsWVOlQpmoYLXGVxH3CQ== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: hostent modification X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jul 2005 04:08:44 -0000 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 , 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 #include #include #include 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.