summaryrefslogtreecommitdiff
path: root/src/sydra.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2014-09-24 00:46:07 +0200
committerChristian Pointner <equinox@spreadspace.org>2014-09-24 00:46:07 +0200
commit1fc208a9d2cd0ac0b1526399612f2ed947f8e5be (patch)
treeac2461b72254d02853ee4fea8a4dee1d8207a723 /src/sydra.c
parentbinding to address/port (diff)
adding host to udp sink when incoming packet is seen works now
Diffstat (limited to 'src/sydra.c')
-rw-r--r--src/sydra.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/sydra.c b/src/sydra.c
index e1c67db..faa6641 100644
--- a/src/sydra.c
+++ b/src/sydra.c
@@ -478,35 +478,37 @@ static GstElement* create_pipeline(options_t* opt, struct udp_elements *udp)
}
-static char* sockaddr_to_string(struct sockaddr_storage *addr, socklen_t addrlen, char* buf, int buflen)
+static void udp_add_client(struct sockaddr_storage *addr, socklen_t addrlen, GstElement* udp)
{
- if(!buf)
- return NULL;
-
- if(!addr)
- return strncpy(buf, "<null>", buflen);
-
- char addrstr[INET6_ADDRSTRLEN + 1], portstr[6];
+ char addrstr[INET6_ADDRSTRLEN + 1];
+ u_short port;
char addrport_sep = ':';
switch(addr->ss_family)
{
- case AF_INET: addrport_sep = ':'; break;
- case AF_INET6: addrport_sep = '.'; break;
- default: return strncpy(buf, "<unknown address type>", buflen);
+ case AF_INET: addrport_sep = ':'; port = ntohs(((struct sockaddr_in*)addr)->sin_port); break;
+ case AF_INET6: addrport_sep = '.'; port = ntohs(((struct sockaddr_in6*)addr)->sin6_port); break;
+ default: return;
}
- int errcode = getnameinfo((struct sockaddr *)addr, addrlen, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST | NI_NUMERICSERV);
- if (errcode != 0) strncpy(buf, "<getnameinfo error>", buflen);
- int len = snprintf(buf, buflen, "%s%c%s", addrstr, addrport_sep ,portstr);
- if(len == -1) return strncpy(buf, "<snprintf error>", buflen);
-
- return buf;
+ int errcode = getnameinfo((struct sockaddr *)addr, addrlen, addrstr, sizeof(addrstr), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV);
+ if (errcode != 0) {
+ log_printf(WARNING, "getnameinfo() error: %s", gai_strerror(errcode));
+ return;
+ }
+ gchar* name = gst_element_get_name(udp);
+ log_printf(DEBUG, "adding host %s%c%d to list of receivers to element %s", addrstr, addrport_sep, port, name);
+ g_free(name);
+ g_signal_emit_by_name(udp, "add", addrstr, port, NULL);
}
static gboolean on_udp_desc_ready(gint fd, GIOCondition cond, gpointer user_data)
{
- log_printf(DEBUG, "%d is ready for reading", fd);
+ GstElement* udp = (GstElement*)user_data;
+ if(!udp) {
+ log_printf(WARNING, "File descriptor %d is ready for reading - but supplied element is NULL removing callback", fd);
+ return FALSE;
+ }
struct sockaddr_storage addr;
socklen_t addrlen = sizeof(addr);
@@ -520,8 +522,7 @@ static gboolean on_udp_desc_ready(gint fd, GIOCondition cond, gpointer user_data
return FALSE;
}
- log_printf(DEBUG, "received %d bytes from %s\n", bytes, sockaddr_to_string(&addr, addrlen, buf, sizeof(buf)));
-
+ udp_add_client(&addr, addrlen, udp);
return TRUE;
}