[asterisk-commits] tzafrir: branch tzafrir/monitor-rtp r214070 - /team/tzafrir/monitor-rtp/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 25 14:31:01 CDT 2009


Author: tzafrir
Date: Tue Aug 25 14:30:57 2009
New Revision: 214070

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214070
Log:
helper functions to generate a socket from address

Modified:
    team/tzafrir/monitor-rtp/res/res_monitor.c

Modified: team/tzafrir/monitor-rtp/res/res_monitor.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/tzafrir/monitor-rtp/res/res_monitor.c?view=diff&rev=214070&r1=214069&r2=214070
==============================================================================
--- team/tzafrir/monitor-rtp/res/res_monitor.c (original)
+++ team/tzafrir/monitor-rtp/res/res_monitor.c Tue Aug 25 14:30:57 2009
@@ -254,7 +254,9 @@
 static unsigned long seq = 0;
 
 static const char *config_file = "monitor.conf";
+/*! Remote RTP server */
 static char rtp_server_name[BUFSIZ];
+/*! Sender hostname in SIP packets we send */
 static char reporting_host[BUFSIZ];
 static in_port_t rtp_portbase_rx = 9000;
 static in_port_t rtp_portbase_tx = 11000;
@@ -276,6 +278,45 @@
 	chan->monitor->state = state;
 	UNLOCK_IF_NEEDED(chan, 1);
 	return 0;
+}
+
+static int get_ipaddr(const char *str, struct in_addr *addr)
+{
+	struct ast_hostent he;
+
+	if(!ast_gethostbyname(str, &he)) {
+		ast_log(LOG_NOTICE, "Failed to resolve hostname '%s'\n", str);
+		return 0;
+	}
+	memcpy(&(addr->s_addr), he.hp.h_addr, sizeof(addr->s_addr));
+	return 1;
+}
+
+static int udp_stream(const char *server, in_port_t port, struct sockaddr_in *saddr)
+{
+	int sock;
+
+	if(!get_ipaddr(server, &(saddr->sin_addr)))
+		return -EINVAL;
+	ast_log(LOG_NOTICE, "%s: %s:%d\n", __FUNCTION__, server, port);
+	saddr->sin_family = AF_INET;
+	saddr->sin_port = htons(port);
+	if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+		ast_log(LOG_NOTICE, "Failed to create UDP socket: %s\n", strerror(errno));
+		return -errno;
+	}
+	return sock;
+}
+
+static int sip_stream(const char *server, in_port_t port, struct sockaddr_in *saddr)
+{
+	int			sock;
+
+	if((sock = udp_stream(server, port, saddr)) < 0) {
+		ast_log(LOG_WARNING, "Failed to create SIP stream to '%s:%d'\n", server, port);
+		return -errno;
+	}
+	return sock;
 }
 
 /*! \brief Start monitoring a channel




More information about the asterisk-commits mailing list