1
0
mirror of https://github.com/PHJArea217/socket-enhancer synced 2024-11-25 18:20:58 +02:00

Set scope ID to 0 on failure

This commit is contained in:
Peter H. Jin 2021-06-17 00:38:05 -05:00
parent 73c76996b5
commit fc16a9f4cc

View File

@ -22,7 +22,8 @@ static int parse_ipv6_with_scope(char *str, struct ipv6_with_scope *result) {
index = strtoul(interface_name, NULL, 0); index = strtoul(interface_name, NULL, 0);
} else { } else {
index = if_nametoindex(interface_name); index = if_nametoindex(interface_name);
if (!index) return -1; /* index = 0 on failure, which fails gracefully */
// if (!index) return -1;
} }
struct in6_addr res_addr = {0}; struct in6_addr res_addr = {0};
if (inet_pton(AF_INET6, str, &res_addr) != 1) return -1; if (inet_pton(AF_INET6, str, &res_addr) != 1) return -1;
@ -230,7 +231,7 @@ int connect(int fd, const struct sockaddr *addr_, socklen_t len_) {
} }
if (config->has_v6_linklocal) { if (config->has_v6_linklocal) {
bind_addr = &config->ipv6_linklocal; bind_addr = &config->ipv6_linklocal;
if (IN6_IS_ADDR_UNSPECIFIED(&bind_addr->address) && bind_addr->scope_id) { if (IN6_IS_ADDR_UNSPECIFIED(&bind_addr->address)) {
if (!new_addr.ipv6_addr.sin6_scope_id) { if (!new_addr.ipv6_addr.sin6_scope_id) {
new_addr.ipv6_addr.sin6_scope_id = bind_addr->scope_id; new_addr.ipv6_addr.sin6_scope_id = bind_addr->scope_id;
} }