From owner-freebsd-hackers Sun Nov 25 9:27:34 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from holly.dyndns.org (adsl-208-191-149-232.dsl.hstntx.swbell.net [208.191.149.232]) by hub.freebsd.org (Postfix) with ESMTP id 1D9C237B419 for ; Sun, 25 Nov 2001 09:27:31 -0800 (PST) Received: (from chris@localhost) by holly.dyndns.org (8.11.6/8.9.3) id fAPHRmn02576; Sun, 25 Nov 2001 11:27:48 -0600 (CST) (envelope-from chris) Date: Sun, 25 Nov 2001 11:27:48 -0600 From: Chris Costello To: Igor M Podlesny Cc: freebsd-hackers@FreeBSD.ORG, Dima Dorfman Subject: Re: jail.c.patch (allowing to use hostnames when invoking jail(8)) Message-ID: <20011125112748.B511@holly.calldei.com> Reply-To: chris@FreeBSD.ORG References: <95121839796.20011124224006@morning.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <95121839796.20011124224006@morning.ru>; from poige@morning.ru on Sat, Nov 24, 2001 at 10:40:06PM +0700 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Saturday, November 24, 2001, Igor M Podlesny wrote: > i = inet_aton(argv[3], &in); > - if (!i) > - errx(1, "Couldn't make sense of ip-number\n"); > + if (!i) { > + /* check if it is resolveable */ > + struct hostent *hp; > + hp = gethostbyname(argv[3]); > + if (hp == NULL) { > + errx(1, "Couldn't make sense of the jail address\n"); > + } > + else { > + char **p = hp->h_addr_list; > + if (p[1] != NULL) { > + errx(1, "Jail should have only one ip-address associated with!\n"); > + } > + else { > + memcpy(&in.s_addr, p[0], sizeof(in.s_addr)); > + } > + } > + } I'd rewrite the above (`i = inet_aton' all the way down) as hp = gethostbyname(argv[3]); if (hp == NULL) { errx(1, "%s: %s", argv[3], hstrerror(h_errno)); } in = *(struct in_addr *)hp->h_addr_list[0]; This makes the call to inet_aton() unnecessary (and really shortens the code!). -- +-------------------+------------------------------------------+ | Chris Costello | It is easier to change the specification | | chris@FreeBSD.org | to fit the program than vice versa. | +-------------------+------------------------------------------+ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message