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 |
| [EMAIL PROTECTED] | to fit the program than vice versa.      |
+-------------------+------------------------------------------+

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to