discover/sysinfo: Add network availability helper
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Thu, 23 Mar 2017 06:42:03 +0000 (17:42 +1100)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 11 Jul 2017 04:32:23 +0000 (14:32 +1000)
Add a helper function that describes interfaces as available if they
have an assigned address.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/sysinfo.c
discover/sysinfo.h

index e8e6d52bce971452ebff7f6d714c2005ccd58715..74d1eae573f230a53ea018aab36a713d34686d84 100644 (file)
@@ -17,6 +17,15 @@ const struct system_info *system_info_get(void)
        return sysinfo;
 }
 
+bool system_info_network_available(void)
+{
+       unsigned int i;
+
+       for (i = 0; i < sysinfo->n_interfaces; i++)
+               if (sysinfo->interfaces[i]->address)
+                       return true;
+       return false;
+}
 
 void system_info_set_interface_address(unsigned int hwaddr_size,
                uint8_t *hwaddr, const char *address)
index c570951db312e3c3385d5d66ce91ff7c9ff165c3..835dfbe949811f7978e9b4ed9a63bd0cdabbf924 100644 (file)
@@ -7,6 +7,7 @@ struct discover_server;
 
 const struct system_info *system_info_get(void);
 
+bool system_info_network_available(void);
 void system_info_set_interface_address(unsigned int hwaddr_size,
                uint8_t *hwaddr, const char *address);
 void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,