diff --git a/lib/libipfw3/basic/ipfw3_basic.c b/lib/libipfw3/basic/ipfw3_basic.c index 1506f5a..568c470 100644 --- a/lib/libipfw3/basic/ipfw3_basic.c +++ b/lib/libipfw3/basic/ipfw3_basic.c @@ -140,6 +140,10 @@ fill_iface(ipfw_insn_if *cmd, char *arg) errx(EX_DATAERR, "bad ip address ``%s''", arg); } +/* + * return -1 when failed + * return 0 when resolved the host into ipaddr + */ static int lookup_host (char *host, struct in_addr *ipaddr) { @@ -147,10 +151,11 @@ lookup_host (char *host, struct in_addr *ipaddr) if (!inet_aton(host, ipaddr)) { if ((he = gethostbyname(host)) == NULL) - return(-1); + return -1; *ipaddr = *(struct in_addr *)he->h_addr_list[0]; + return 0; } - return(0); + return -1; } /* @@ -311,7 +316,8 @@ parse_forward(ipfw_insn **cmd, int *ac, char **av[]) port = strtoport(str, &end, 0, 0); sa->sin_port = (u_short)port; } - lookup_host(tok, &(sa->sin_addr)); + if (lookup_host(tok, &(sa->sin_addr)) != 0) + errx(EX_DATAERR, "forward `%s' incorrect dst", tok); tok = strtok (NULL, ","); sa++; count++;