Check for ipaddress local and broadcast pointers
authorMartin Xu <martin.xu@intel.com>
Tue, 9 Feb 2010 09:29:51 +0000 (10:29 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 11 Feb 2010 04:29:25 +0000 (05:29 +0100)
If local is NULL we return an error. If broadcast is NULL, we use the local
address prefix to build a broadcast one.

src/inet.c

index 5838008..4e79fe8 100644 (file)
@@ -547,6 +547,11 @@ int connman_inet_set_address(int index, struct connman_ipaddress *ipaddress)
 
        DBG("ifname %s", ifr.ifr_name);
 
+       if (ipaddress->local == NULL) {
+               close(sk);
+               return -1;
+       }
+
        memset(&addr, 0, sizeof(addr));
        addr.sin_family = AF_INET;
        addr.sin_addr.s_addr = inet_addr(ipaddress->local);
@@ -569,7 +574,13 @@ int connman_inet_set_address(int index, struct connman_ipaddress *ipaddress)
 
        memset(&addr, 0, sizeof(addr));
        addr.sin_family = AF_INET;
-       addr.sin_addr.s_addr = inet_addr(ipaddress->broadcast);
+
+       if (ipaddress->broadcast != NULL)
+               addr.sin_addr.s_addr = inet_addr(ipaddress->broadcast);
+       else
+               addr.sin_addr.s_addr = inet_addr(ipaddress->local) |
+                               htonl(0xfffffffflu >> ipaddress->prefixlen);
+
        memcpy(&ifr.ifr_broadaddr, &addr, sizeof(ifr.ifr_broadaddr));
 
        err = ioctl(sk, SIOCSIFBRDADDR, &ifr);