mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-07-21 10:16:14 +00:00
raop: use pw_net utils to parse address
This commit is contained in:
parent
46e4a33f27
commit
bd4d61c83c
|
@ -44,6 +44,8 @@
|
||||||
#include <pipewire/impl.h>
|
#include <pipewire/impl.h>
|
||||||
#include <pipewire/i18n.h>
|
#include <pipewire/i18n.h>
|
||||||
|
|
||||||
|
#include "network-utils.h"
|
||||||
|
|
||||||
#include "module-raop/rtsp-client.h"
|
#include "module-raop/rtsp-client.h"
|
||||||
#include "module-rtp/rtp.h"
|
#include "module-rtp/rtp.h"
|
||||||
#include "module-rtp/stream.h"
|
#include "module-rtp/stream.h"
|
||||||
|
@ -587,38 +589,25 @@ error:
|
||||||
static int connect_socket(struct impl *impl, int type, int fd, uint16_t port)
|
static int connect_socket(struct impl *impl, int type, int fd, uint16_t port)
|
||||||
{
|
{
|
||||||
const char *host;
|
const char *host;
|
||||||
struct sockaddr_in sa4;
|
struct sockaddr_storage addr;
|
||||||
struct sockaddr_in6 sa6;
|
socklen_t len = 0;
|
||||||
struct sockaddr *sa;
|
int res;
|
||||||
size_t salen;
|
|
||||||
int res, af;
|
|
||||||
|
|
||||||
host = pw_properties_get(impl->props, "raop.ip");
|
host = pw_properties_get(impl->props, "raop.ip");
|
||||||
if (host == NULL)
|
if (host == NULL)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (inet_pton(AF_INET, host, &sa4.sin_addr) > 0) {
|
if ((res = pw_net_parse_address(host, port, &addr, &len)) < 0) {
|
||||||
sa4.sin_family = af = AF_INET;
|
pw_log_error("Invalid host '%s' port:%d", host, port);
|
||||||
sa4.sin_port = htons(port);
|
|
||||||
sa = (struct sockaddr *) &sa4;
|
|
||||||
salen = sizeof(sa4);
|
|
||||||
} else if (inet_pton(AF_INET6, host, &sa6.sin6_addr) > 0) {
|
|
||||||
sa6.sin6_family = af = AF_INET6;
|
|
||||||
sa6.sin6_port = htons(port);
|
|
||||||
sa = (struct sockaddr *) &sa6;
|
|
||||||
salen = sizeof(sa6);
|
|
||||||
} else {
|
|
||||||
pw_log_error("Invalid host '%s'", host);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd < 0 &&
|
if (fd < 0 &&
|
||||||
(fd = socket(af, type | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0) {
|
(fd = socket(addr.ss_family, type | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0) {
|
||||||
pw_log_error("socket failed: %m");
|
pw_log_error("socket failed: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = connect(fd, sa, salen);
|
res = connect(fd, (struct sockaddr*)&addr, len);
|
||||||
if (res < 0 && errno != EINPROGRESS) {
|
if (res < 0 && errno != EINPROGRESS) {
|
||||||
res = -errno;
|
res = -errno;
|
||||||
pw_log_error("connect failed: %m");
|
pw_log_error("connect failed: %m");
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static int pw_net_parse_address(const char *address, uint16_t port,
|
static inline int pw_net_parse_address(const char *address, uint16_t port,
|
||||||
struct sockaddr_storage *addr, socklen_t *len)
|
struct sockaddr_storage *addr, socklen_t *len)
|
||||||
{
|
{
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
|
@ -38,7 +38,7 @@ static int pw_net_parse_address(const char *address, uint16_t port,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pw_net_get_ip(const struct sockaddr_storage *sa, char *ip, size_t len, bool *ip4, uint16_t *port)
|
static inline int pw_net_get_ip(const struct sockaddr_storage *sa, char *ip, size_t len, bool *ip4, uint16_t *port)
|
||||||
{
|
{
|
||||||
if (sa->ss_family == AF_INET) {
|
if (sa->ss_family == AF_INET) {
|
||||||
struct sockaddr_in *in = (struct sockaddr_in*)sa;
|
struct sockaddr_in *in = (struct sockaddr_in*)sa;
|
||||||
|
|
Loading…
Reference in a new issue