From f459d324bf7fcec3694460928efcccf3267c2f5e Mon Sep 17 00:00:00 2001 From: Chia-chi Yeh Date: Thu, 22 Sep 2011 10:53:05 -0700 Subject: [PATCH] ip-up-vpn: Handle the case where INTERNAL_NETMASK4 is empty. Also set the errno when inet_pton() fails. Change-Id: Ib98ed593fe1ceabecef4b92bf939f44ecf9fa665 --- cmds/ip-up-vpn/ip-up-vpn.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmds/ip-up-vpn/ip-up-vpn.c b/cmds/ip-up-vpn/ip-up-vpn.c index e9ee95d67680e..0e6286f9279c5 100644 --- a/cmds/ip-up-vpn/ip-up-vpn.c +++ b/cmds/ip-up-vpn/ip-up-vpn.c @@ -40,6 +40,7 @@ static const char *env(const char *name) { static int set_address(struct sockaddr *sa, const char *address) { sa->sa_family = AF_INET; + errno = EINVAL; return inet_pton(AF_INET, address, &((struct sockaddr_in *)sa)->sin_addr); } @@ -124,10 +125,11 @@ int main(int argc, char **argv) } /* Set the netmask. */ - if (!set_address(&ifr.ifr_netmask, env("INTERNAL_NETMASK4")) || - ioctl(s, SIOCSIFNETMASK, &ifr)) { - LOGE("Cannot set netmask: %s", strerror(errno)); - return 1; + if (set_address(&ifr.ifr_netmask, env("INTERNAL_NETMASK4"))) { + if (ioctl(s, SIOCSIFNETMASK, &ifr)) { + LOGE("Cannot set netmask: %s", strerror(errno)); + return 1; + } } /* TODO: Send few packets to trigger phase 2? */