Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Nov 2001 11:27:48 -0600
From:      Chris Costello <chris@FreeBSD.ORG>
To:        Igor M Podlesny <poige@morning.ru>
Cc:        freebsd-hackers@FreeBSD.ORG, Dima Dorfman <dima@trit.org>
Subject:   Re: jail.c.patch (allowing to use hostnames when invoking jail(8))
Message-ID:  <20011125112748.B511@holly.calldei.com>
In-Reply-To: <95121839796.20011124224006@morning.ru>; from poige@morning.ru on Sat, Nov 24, 2001 at 10:40:06PM %2B0700
References:  <95121839796.20011124224006@morning.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011125112748.B511>