[asterisk-commits] tzafrir: branch tzafrir/monitor-rtp-14 r213890 - /team/tzafrir/monitor-rtp-14...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Aug 24 18:21:20 CDT 2009
Author: tzafrir
Date: Mon Aug 24 18:21:17 2009
New Revision: 213890
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=213890
Log:
helper functions to generate a socket from address
Modified:
team/tzafrir/monitor-rtp-14/res/res_monitor.c
Modified: team/tzafrir/monitor-rtp-14/res/res_monitor.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/tzafrir/monitor-rtp-14/res/res_monitor.c?view=diff&rev=213890&r1=213889&r2=213890
==============================================================================
--- team/tzafrir/monitor-rtp-14/res/res_monitor.c (original)
+++ team/tzafrir/monitor-rtp-14/res/res_monitor.c Mon Aug 24 18:21:17 2009
@@ -64,7 +64,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;
@@ -133,6 +135,45 @@
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;
+}
+
/* Start monitoring a channel */
int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
const char *fname_base, int need_lock)
More information about the asterisk-commits
mailing list