mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-12-29 11:08:35 -05:00
parent
9334d900e5
commit
dc590c7d0a
15 changed files with 179 additions and 23 deletions
|
|
@ -38,7 +38,9 @@
|
|||
|
||||
const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) {
|
||||
struct in_addr *in = (struct in_addr*)src;
|
||||
#ifdef HAVE_IPV6
|
||||
struct in6_addr *in6 = (struct in6_addr*)src;
|
||||
#endif
|
||||
|
||||
assert(src && dst);
|
||||
|
||||
|
|
@ -57,6 +59,7 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) {
|
|||
(int)(in->s_addr >> 24) & 0xff);
|
||||
#endif
|
||||
break;
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6:
|
||||
pa_snprintf(dst, cnt, "%x:%x:%x:%x:%x:%x:%x:%x",
|
||||
in6->s6_addr[ 0] << 8 | in6->s6_addr[ 1],
|
||||
|
|
@ -68,6 +71,7 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) {
|
|||
in6->s6_addr[12] << 8 | in6->s6_addr[13],
|
||||
in6->s6_addr[14] << 8 | in6->s6_addr[15]);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,9 @@
|
|||
|
||||
int inet_pton(int af, const char *src, void *dst) {
|
||||
struct in_addr *in = (struct in_addr*)dst;
|
||||
#ifdef HAVE_IPV6
|
||||
struct in6_addr *in6 = (struct in6_addr*)dst;
|
||||
#endif
|
||||
|
||||
assert(src && dst);
|
||||
|
||||
|
|
@ -48,8 +50,10 @@ int inet_pton(int af, const char *src, void *dst) {
|
|||
if (in->s_addr == INADDR_NONE)
|
||||
return 0;
|
||||
break;
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6:
|
||||
/* FIXME */
|
||||
#endif
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,9 @@ struct acl_entry {
|
|||
PA_LLIST_FIELDS(struct acl_entry);
|
||||
int family;
|
||||
struct in_addr address_ipv4;
|
||||
#ifdef HAVE_IPV6
|
||||
struct in6_addr address_ipv6;
|
||||
#endif
|
||||
int bits;
|
||||
};
|
||||
|
||||
|
|
@ -109,6 +111,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
|
|||
if (e.bits < 32 && (uint32_t) (ntohl(e.address_ipv4.s_addr) << e.bits) != 0)
|
||||
pa_log_warn("Host part of ACL entry '%s/%u' is not zero!", a, e.bits);
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
} else if (inet_pton(AF_INET6, a, &e.address_ipv6) > 0) {
|
||||
|
||||
e.bits = bits == (uint32_t) -1 ? 128 : (int) bits;
|
||||
|
|
@ -138,6 +141,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
|
|||
if (t)
|
||||
pa_log_warn("Host part of ACL entry '%s/%u' is not zero!", a, e.bits);
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
pa_log_warn("Failed to parse address: %s", a);
|
||||
|
|
@ -183,14 +187,20 @@ int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
|
|||
if (getpeername(fd, (struct sockaddr*) &sa, &salen) < 0)
|
||||
return -1;
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
if (sa.ss_family != AF_INET && sa.ss_family != AF_INET6)
|
||||
#else
|
||||
if (sa.ss_family != AF_INET)
|
||||
#endif
|
||||
return -1;
|
||||
|
||||
if (sa.ss_family == AF_INET && salen != sizeof(struct sockaddr_in))
|
||||
return -1;
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
if (sa.ss_family == AF_INET6 && salen != sizeof(struct sockaddr_in6))
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
for (e = acl->entries; e; e = e->next) {
|
||||
|
||||
|
|
@ -203,6 +213,7 @@ int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
|
|||
if (e->bits == 0 || /* this needs special handling because >> takes the right-hand side modulo 32 */
|
||||
(ntohl(sai->sin_addr.s_addr ^ e->address_ipv4.s_addr) >> (32 - e->bits)) == 0)
|
||||
return 1;
|
||||
#ifdef HAVE_IPV6
|
||||
} else if (e->family == AF_INET6) {
|
||||
int i, bits ;
|
||||
struct sockaddr_in6 *sai = (struct sockaddr_in6*) &sa;
|
||||
|
|
@ -230,6 +241,7 @@ int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
|
|||
if (bits == 0)
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -278,7 +278,11 @@ static int sockaddr_prepare(pa_socket_client *c, const struct sockaddr *sa, size
|
|||
|
||||
pa_make_fd_cloexec(c->fd);
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
if (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)
|
||||
#else
|
||||
if (sa->sa_family == AF_INET)
|
||||
#endif
|
||||
pa_make_tcp_socket_low_delay(c->fd);
|
||||
else
|
||||
pa_make_socket_low_delay(c->fd);
|
||||
|
|
@ -353,6 +357,7 @@ void pa_socket_client_set_callback(pa_socket_client *c, pa_socket_client_cb_t on
|
|||
c->userdata = userdata;
|
||||
}
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
pa_socket_client* pa_socket_client_new_ipv6(pa_mainloop_api *m, uint8_t address[16], uint16_t port) {
|
||||
struct sockaddr_in6 sa;
|
||||
|
||||
|
|
@ -367,6 +372,7 @@ pa_socket_client* pa_socket_client_new_ipv6(pa_mainloop_api *m, uint8_t address[
|
|||
|
||||
return pa_socket_client_new_sockaddr(m, (struct sockaddr*) &sa, sizeof(sa));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBASYNCNS
|
||||
|
||||
|
|
@ -470,7 +476,15 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
|
|||
pa_snprintf(port, sizeof(port), "%u", (unsigned) a.port);
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = a.type == PA_PARSED_ADDRESS_TCP4 ? PF_INET : (a.type == PA_PARSED_ADDRESS_TCP6 ? PF_INET6 : PF_UNSPEC);
|
||||
if (a.type == PA_PARSED_ADDRESS_TCP4)
|
||||
hints.ai_family = PF_INET;
|
||||
#ifdef HAVE_IPV6
|
||||
else if (a.type == PA_PARSED_ADDRESS_TCP6)
|
||||
hints.ai_family = PF_INET6;
|
||||
#endif
|
||||
else
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
#if defined(HAVE_LIBASYNCNS)
|
||||
|
|
@ -509,11 +523,13 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
|
|||
struct hostent *host = NULL;
|
||||
struct sockaddr_in s;
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
/* FIXME: PF_INET6 support */
|
||||
if (hints.ai_family == PF_INET6) {
|
||||
pa_log_error("IPv6 is not supported on Windows");
|
||||
goto finish;
|
||||
}
|
||||
#endif
|
||||
|
||||
host = gethostbyname(a.path_or_host);
|
||||
if (!host) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ typedef struct pa_socket_client pa_socket_client;
|
|||
typedef void (*pa_socket_client_cb_t)(pa_socket_client *c, pa_iochannel*io, void *userdata);
|
||||
|
||||
pa_socket_client* pa_socket_client_new_ipv4(pa_mainloop_api *m, uint32_t address, uint16_t port);
|
||||
#ifdef HAVE_IPV6
|
||||
pa_socket_client* pa_socket_client_new_ipv6(pa_mainloop_api *m, uint8_t address[16], uint16_t port);
|
||||
#endif
|
||||
pa_socket_client* pa_socket_client_new_unix(pa_mainloop_api *m, const char *filename);
|
||||
pa_socket_client* pa_socket_client_new_sockaddr(pa_mainloop_api *m, const struct sockaddr *sa, size_t salen);
|
||||
pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char *a, uint16_t default_port);
|
||||
|
|
|
|||
|
|
@ -289,6 +289,7 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t address[16], uint16_t port, const char *tcpwrap_service) {
|
||||
pa_socket_server *ss;
|
||||
int fd = -1;
|
||||
|
|
@ -347,6 +348,7 @@ fail:
|
|||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
pa_socket_server* pa_socket_server_new_ipv4_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
|
||||
pa_assert(m);
|
||||
|
|
@ -355,12 +357,14 @@ pa_socket_server* pa_socket_server_new_ipv4_loopback(pa_mainloop_api *m, uint16_
|
|||
return pa_socket_server_new_ipv4(m, INADDR_LOOPBACK, port, tcpwrap_service);
|
||||
}
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
pa_socket_server* pa_socket_server_new_ipv6_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
|
||||
pa_assert(m);
|
||||
pa_assert(port > 0);
|
||||
|
||||
return pa_socket_server_new_ipv6(m, in6addr_loopback.s6_addr, port, tcpwrap_service);
|
||||
}
|
||||
#endif
|
||||
|
||||
pa_socket_server* pa_socket_server_new_ipv4_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
|
||||
pa_assert(m);
|
||||
|
|
@ -369,12 +373,14 @@ pa_socket_server* pa_socket_server_new_ipv4_any(pa_mainloop_api *m, uint16_t por
|
|||
return pa_socket_server_new_ipv4(m, INADDR_ANY, port, tcpwrap_service);
|
||||
}
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
pa_socket_server* pa_socket_server_new_ipv6_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
|
||||
pa_assert(m);
|
||||
pa_assert(port > 0);
|
||||
|
||||
return pa_socket_server_new_ipv6(m, in6addr_any.s6_addr, port, tcpwrap_service);
|
||||
}
|
||||
#endif
|
||||
|
||||
pa_socket_server* pa_socket_server_new_ipv4_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) {
|
||||
struct in_addr ipv4;
|
||||
|
|
@ -389,6 +395,7 @@ pa_socket_server* pa_socket_server_new_ipv4_string(pa_mainloop_api *m, const cha
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
pa_socket_server* pa_socket_server_new_ipv6_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) {
|
||||
struct in6_addr ipv6;
|
||||
|
||||
|
|
@ -401,6 +408,7 @@ pa_socket_server* pa_socket_server_new_ipv6_string(pa_mainloop_api *m, const cha
|
|||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void socket_server_free(pa_socket_server*s) {
|
||||
pa_assert(s);
|
||||
|
|
@ -441,6 +449,7 @@ char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
|
|||
pa_assert(l > 0);
|
||||
|
||||
switch (s->type) {
|
||||
#ifdef HAVE_IPV6
|
||||
case SOCKET_SERVER_IPV6: {
|
||||
struct sockaddr_in6 sa;
|
||||
socklen_t sa_len = sizeof(sa);
|
||||
|
|
@ -476,6 +485,7 @@ char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
|
|||
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
||||
case SOCKET_SERVER_IPV4: {
|
||||
struct sockaddr_in sa;
|
||||
|
|
|
|||
|
|
@ -34,13 +34,15 @@ typedef struct pa_socket_server pa_socket_server;
|
|||
pa_socket_server* pa_socket_server_new(pa_mainloop_api *m, int fd);
|
||||
pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *filename);
|
||||
pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address, uint16_t port, const char *tcpwrap_service);
|
||||
pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t address[16], uint16_t port, const char *tcpwrap_service);
|
||||
pa_socket_server* pa_socket_server_new_ipv4_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
|
||||
pa_socket_server* pa_socket_server_new_ipv6_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
|
||||
pa_socket_server* pa_socket_server_new_ipv4_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
|
||||
pa_socket_server* pa_socket_server_new_ipv6_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
|
||||
pa_socket_server* pa_socket_server_new_ipv4_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service);
|
||||
#ifdef HAVE_IPV6
|
||||
pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t address[16], uint16_t port, const char *tcpwrap_service);
|
||||
pa_socket_server* pa_socket_server_new_ipv6_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
|
||||
pa_socket_server* pa_socket_server_new_ipv6_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
|
||||
pa_socket_server* pa_socket_server_new_ipv6_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service);
|
||||
#endif
|
||||
|
||||
void pa_socket_server_unref(pa_socket_server*s);
|
||||
pa_socket_server* pa_socket_server_ref(pa_socket_server *s);
|
||||
|
|
|
|||
|
|
@ -93,7 +93,9 @@ void pa_socket_peer_to_string(int fd, char *c, size_t l) {
|
|||
union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in in;
|
||||
#ifdef HAVE_IPV6
|
||||
struct sockaddr_in6 in6;
|
||||
#endif
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
struct sockaddr_un un;
|
||||
#endif
|
||||
|
|
@ -112,6 +114,7 @@ void pa_socket_peer_to_string(int fd, char *c, size_t l) {
|
|||
ip & 0xFF,
|
||||
ntohs(sa.in.sin_port));
|
||||
return;
|
||||
#ifdef HAVE_IPV6
|
||||
} else if (sa.sa.sa_family == AF_INET6) {
|
||||
char buf[INET6_ADDRSTRLEN];
|
||||
const char *res;
|
||||
|
|
@ -121,6 +124,7 @@ void pa_socket_peer_to_string(int fd, char *c, size_t l) {
|
|||
pa_snprintf(c, l, "TCP/IP client from [%s]:%u", buf, ntohs(sa.in6.sin6_port));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
} else if (sa.sa.sa_family == AF_UNIX) {
|
||||
pa_snprintf(c, l, "UNIX socket client");
|
||||
|
|
@ -298,8 +302,10 @@ pa_bool_t pa_socket_address_is_local(const struct sockaddr *sa) {
|
|||
case AF_INET:
|
||||
return ((const struct sockaddr_in*) sa)->sin_addr.s_addr == INADDR_LOOPBACK;
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6:
|
||||
return memcmp(&((const struct sockaddr_in6*) sa)->sin6_addr, &in6addr_loopback, sizeof(struct in6_addr)) == 0;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
|
|
@ -311,7 +317,9 @@ pa_bool_t pa_socket_is_local(int fd) {
|
|||
union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in in;
|
||||
#ifdef HAVE_IPV6
|
||||
struct sockaddr_in6 in6;
|
||||
#endif
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
struct sockaddr_un un;
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue