[netprotocol] Remove spurious errors
When querying for devices, don't print an error for every interface
failure. Instead, print an error if *all* interfaces fail.
ZX-3244
PT-89
Test: Ran fx shell and fx traceutil on a system that was failing
with symptoms described in bugs.
Change-Id: I6af656a4fcf8ce485fcccf7832f27445d51c206a
diff --git a/system/host/netprotocol/netprotocol.c b/system/host/netprotocol/netprotocol.c
index dda3774..e87fbe7 100644
--- a/system/host/netprotocol/netprotocol.c
+++ b/system/host/netprotocol/netprotocol.c
@@ -91,6 +91,8 @@
return -1;
}
+ bool success = false;
+
for (; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL) {
continue;
@@ -102,21 +104,25 @@
if (in6->sin6_scope_id == 0) {
continue;
}
- if (ifname && ifname[0] != 0 && strcmp(ifname, ifa->ifa_name))
+ if (ifname && ifname[0] != 0 && strcmp(ifname, ifa->ifa_name)) {
continue;
+ }
// printf("tx %s (sid=%d)\n", ifa->ifa_name, in6->sin6_scope_id);
size_t sz = sizeof(nbmsg) + hostname_len;
addr.sin6_scope_id = in6->sin6_scope_id;
ssize_t r = sendto(socket, &m, sz, 0,
(struct sockaddr*)&addr, sizeof(addr));
- if (r < 0) {
- fprintf(stderr, "error: sendto: %s\n", strerror(errno));
- } else if ((size_t)r != sz) {
- fprintf(stderr, "error: sendto: short count %zu != %zu\n", r, sz);
+ if ((r >= 0) && (size_t)r == sz) {
+ success = true;
}
}
+ if (!success) {
+ fprintf(stderr, "error: failed to find interface for sending query\n");
+ return -1;
+ }
+
return 0;
}