Skip to contentSkip to conversation

alfred: add more verbose error message

PATCH New Noah Peterson 1 participant 1 message Sep 10, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 alfred: add more verbose error message

From: Noah Peterson <[email protected]>

There is an issue with some Linux distributions where network interfaces are up and active, but do not have the correct link-local address. This condition is now checked and output to stderr to better help users troubleshoot this issue.

---
v3: Add changelog, change newlines, noted by Sven <[email protected]>
v2: Fixed IPv6 address string, noted by Sven <[email protected]>

---
 netsock.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
netsock.c +14 -1
index feed21d..95dbf5e 100644
@@ -21,6 +21,7 @@
 #include <sys/types.h>
 #include <stdlib.h>
 #include <sys/epoll.h>
+#include <arpa/inet.h>
 #ifdef CONFIG_ALFRED_CAPABILITIES
 #include <sys/capability.h>
 #endif
@@ -322,7 +323,19 @@ static int netsock_open(struct globals *globals, struct interface *interface)
 	enable_raw_bind_capability(0);
 
 	if (bind(sock, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
-		perror("can't bind");
+		char ipstr_buf[INET6_ADDRSTRLEN];
+		const char *ipstr;
+
+		ipstr = inet_ntop(AF_INET6, &interface->address.ipv6.s6_addr,
+				  ipstr_buf, INET6_ADDRSTRLEN);
+
+		if (errno == EADDRNOTAVAIL)
+			fprintf(stderr, "can't bind to interface %s; "
+				"expected ipv6 address not found: %s\n",
+				interface->interface,
+				ipstr);
+		else
+			perror("can't bind");
 		goto err;
 	}
 
Signature · 1 line
2.39.3 (Apple Git-146)