summaryrefslogtreecommitdiff
path: root/src/udp.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2014-10-01 01:42:23 +0200
committerChristian Pointner <equinox@spreadspace.org>2014-10-01 01:42:23 +0200
commit97c1c6af16683c2e99bf1897af2d26aea089589c (patch)
treed3a63959b9ca755bd9821dba20cefcc2de569a4f /src/udp.c
parentresolving remote rtp works now (diff)
sending keep alives works now
Diffstat (limited to 'src/udp.c')
-rw-r--r--src/udp.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/udp.c b/src/udp.c
index ee6170c..9de5d7a 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -230,7 +230,7 @@ gboolean attach_udpsinks(struct udp_sinks *sinks)
return TRUE;
}
-static gboolean send_keepalive(GstElement* source, const char* name, GInetAddress* remote)
+static gboolean send_keepalive(GstElement* source, const char* name, GInetAddress* remote, guint port)
{
if(!remote) {
log_printf(WARNING, "keepalives are enabled but no remote address is set... disabling keep alives");
@@ -241,17 +241,44 @@ static gboolean send_keepalive(GstElement* source, const char* name, GInetAddres
g_object_get(G_OBJECT(source), "used-socket", &sock, NULL);
int fd = g_socket_get_fd(sock);
- log_printf(WARNING, "if implemented keep alives would be sent out to fd: %d", fd);
+ struct sockaddr_storage addr;
+ socklen_t addrlen = sizeof(struct sockaddr_storage);
+ memset(&addr, 0, addrlen);
+ switch(g_inet_address_get_family(remote)) {
+ case G_SOCKET_FAMILY_IPV4: {
+ addrlen = sizeof(struct sockaddr_in);
+ size_t len = g_inet_address_get_native_size(remote);
+ if(len > sizeof(struct in_addr)) len = sizeof(struct in_addr);
+ memcpy(&(((struct sockaddr_in*)(&addr))->sin_addr), g_inet_address_to_bytes(remote), len);
+ ((struct sockaddr_in*)&addr)->sin_port = htons(port);
+ break;
+ }
+ case G_SOCKET_FAMILY_IPV6: {
+ addrlen = sizeof(struct sockaddr_in6);
+ size_t len = g_inet_address_get_native_size(remote);
+ if(len > sizeof(struct in6_addr)) len = sizeof(struct in6_addr);
+ memcpy(&(((struct sockaddr_in6*)&addr)->sin6_addr), g_inet_address_to_bytes(remote), len);
+ ((struct sockaddr_in6*)&addr)->sin6_port = htons(port);
+ break;
+ }
+ default: log_printf(ERROR, "remote address has unsupported protocol family - disabling keep alives"); return FALSE;
+ }
+
+ log_printf(DEBUG, "sending keep-alive out on to %s %d - %s (fd=%d)", g_inet_address_to_string(remote), port, name, fd);
+ gchar buf[] = UDP_PROTO_MAGIC UDP_PROTO_CMD_ADD_CLIENT;
+ sendto(fd, buf, UDP_PROTO_MAGIC_LEN+UDP_PROTO_CMD_ADD_CLIENT_LEN, 0, (struct sockaddr *)&(addr), addrlen);
+
return TRUE;
}
static gboolean send_keepalives(gpointer user_data)
{
struct udp_sources* sources = (struct udp_sources*)user_data;
- if(!send_keepalive(sources->rtp_video_, "RTP(video)", sources->remote_addr_) ||
- !send_keepalive(sources->rtcp_video_, "RTCP(video)", sources->remote_addr_) ||
- !send_keepalive(sources->rtp_audio_, "RTP(audio)", sources->remote_addr_) ||
- !send_keepalive(sources->rtcp_audio_, "RTCP(audio)", sources->remote_addr_)) {
+ guint port = sources->port_base_;
+ if(!send_keepalive(sources->rtp_video_, "RTP(video)", sources->remote_addr_, port++) ||
+ !send_keepalive(sources->rtcp_video_, "RTCP(video)", sources->remote_addr_, port++) ||
+ !send_keepalive(sources->rtp_audio_, "RTP(audio)", sources->remote_addr_, port++) ||
+ !send_keepalive(sources->rtcp_audio_, "RTCP(audio)", sources->remote_addr_, port++)) {
return FALSE;
}