mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
network-utils: handle inet_ntop errors
This commit is contained in:
parent
2093fb2071
commit
1030000890
1 changed files with 15 additions and 13 deletions
|
|
@ -82,19 +82,23 @@ static inline int pw_net_parse_address_port(const char *address,
|
|||
|
||||
static inline int pw_net_get_ip(const struct sockaddr_storage *sa, char *ip, size_t len, bool *ip4, uint16_t *port)
|
||||
{
|
||||
if (ip4)
|
||||
*ip4 = sa->ss_family == AF_INET;
|
||||
|
||||
if (sa->ss_family == AF_INET) {
|
||||
struct sockaddr_in *in = (struct sockaddr_in*)sa;
|
||||
inet_ntop(sa->ss_family, &in->sin_addr, ip, len);
|
||||
if (inet_ntop(sa->ss_family, &in->sin_addr, ip, len) == NULL)
|
||||
return -errno;
|
||||
if (port)
|
||||
*port = ntohs(in->sin_port);
|
||||
} else if (sa->ss_family == AF_INET6) {
|
||||
struct sockaddr_in6 *in = (struct sockaddr_in6*)sa;
|
||||
inet_ntop(sa->ss_family, &in->sin6_addr, ip, len);
|
||||
if (inet_ntop(sa->ss_family, &in->sin6_addr, ip, len) == NULL)
|
||||
return -errno;
|
||||
if (port)
|
||||
*port = ntohs(in->sin6_port);
|
||||
if (in->sin6_scope_id == 0 || len <= 1)
|
||||
goto finish;
|
||||
|
||||
if (in->sin6_scope_id != 0 && len > 1) {
|
||||
size_t curlen = strlen(ip);
|
||||
if (len-(curlen+1) >= IFNAMSIZ) {
|
||||
ip += curlen+1;
|
||||
|
|
@ -102,11 +106,9 @@ static inline int pw_net_get_ip(const struct sockaddr_storage *sa, char *ip, siz
|
|||
if (if_indextoname(in->sin6_scope_id, ip) == NULL)
|
||||
ip[-1] = 0;
|
||||
}
|
||||
}
|
||||
} else
|
||||
return -EINVAL;
|
||||
finish:
|
||||
if (ip4)
|
||||
*ip4 = sa->ss_family == AF_INET;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue