#include <sys/types.h>
#include <sys/wait.h>
#include <arpa/inet.h>
+#include <netdb.h>
+#include <ifaddrs.h>
#include "interface.h"
return close(intf->rxd);
}
+static int net_available(void)
+{
+ struct ifaddrs *ifs, *cur;
+ char host[NI_MAXHOST];
+ int ret, s;
+
+ ret = getifaddrs(&ifs);
+ if (ret < 0)
+ return 0;
+
+ /*
+ * TODO:
+ * On RPI-family targets it works well checking network availabilty
+ * via presence of NIC 'eth0' or 'wlan0', but it looks quite hack
+ * anyway. So, it should be changed if there is more generic way.
+ */
+ for (cur = ifs; cur != NULL; cur = cur->ifa_next) {
+ if (!strcmp(cur->ifa_name, "eth0"))
+ return 1;
+
+ if (!strcmp(cur->ifa_name, "wlan0"))
+ return 1;
+ }
+
+ return 0;
+}
+
static struct tfm_interface_driver network = {
.name = "net",
.ops = {
.disconnect = net_disconnect,
.rx_data = net_rx_data,
.tx_data = net_tx_data,
+ .available = net_available,
},
};
INTERFACE_REGISTER(network)