There is an issue with some Linux distributions (Raspian) 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.
Signed-off-by: Noah Peterson noahbpeterson1997@gmail.com --- netsock.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/netsock.c b/netsock.c index feed21d..04f95c7 100644 --- a/netsock.c +++ b/netsock.c @@ -322,7 +322,23 @@ 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"); + if (errno == EADDRNOTAVAIL) + fprintf(stderr, "can't bind to interface %s; " + "expected ipv6 address not found: " + "%02x%02x::%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", + interface->interface, + (int)interface->address.ipv6.s6_addr[0], + (int)interface->address.ipv6.s6_addr[1], + (int)interface->address.ipv6.s6_addr[8], + (int)interface->address.ipv6.s6_addr[9], + (int)interface->address.ipv6.s6_addr[10], + (int)interface->address.ipv6.s6_addr[11], + (int)interface->address.ipv6.s6_addr[12], + (int)interface->address.ipv6.s6_addr[13], + (int)interface->address.ipv6.s6_addr[14], + (int)interface->address.ipv6.s6_addr[15]); + else + perror("can't bind"); goto err; }
On Sunday, 8 September 2024 22:46:05 CEST noahbpeterson1997@gmail.com wrote:
diff --git a/netsock.c b/netsock.c index feed21d..04f95c7 100644 --- a/netsock.c +++ b/netsock.c @@ -322,7 +322,23 @@ 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");
if (errno == EADDRNOTAVAIL)
fprintf(stderr, "can't bind to interface %s; "
"expected ipv6 address not found: "
"%02x%02x::%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
interface->interface,
(int)interface->address.ipv6.s6_addr[0],
(int)interface->address.ipv6.s6_addr[1],
(int)interface->address.ipv6.s6_addr[8],
(int)interface->address.ipv6.s6_addr[9],
(int)interface->address.ipv6.s6_addr[10],
(int)interface->address.ipv6.s6_addr[11],
(int)interface->address.ipv6.s6_addr[12],
(int)interface->address.ipv6.s6_addr[13],
(int)interface->address.ipv6.s6_addr[14],
(int)interface->address.ipv6.s6_addr[15]);
else
perror("can't bind"); goto err; }
Ehrm, no - this is not a valid way to print IPv6 addresses and it makes to many assumptions about the IPv6 address - which will then lead to more problems in the future. For creating the ip address string:
char ipstr_buf[INET6_ADDRSTRLEN]; const char *ipstr; .... ipstr = inet_ntop(AF_INET6, &interface->address.ipv6.s6_addr, ipstr_buf, INET6_ADDRSTRLEN);
Kind regards, Sven
b.a.t.m.a.n@lists.open-mesh.org