summaryrefslogtreecommitdiff
path: root/res/res_rtp_multicast.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2010-07-08 22:08:07 +0000
committerMark Michelson <mmichelson@digium.com>2010-07-08 22:08:07 +0000
commitcd4ebd336f6fdd1fe5d2ad57f06654a9678d88d4 (patch)
treec05335b563c3f7cb9a3edbf3e101d8e1b80e0be4 /res/res_rtp_multicast.c
parent816f26c16ce6cf03cf97b7d0e7af64837283e79d (diff)
Add IPv6 to Asterisk.
This adds a generic API for accommodating IPv6 and IPv4 addresses within Asterisk. While many files have been updated to make use of the API, chan_sip and the RTP code are the files which actually support IPv6 addresses at the time of this commit. The way has been paved for easier upgrading for other files in the near future, though. Big thanks go to Simon Perrault, Marc Blanchet, and Jean-Philippe Dionne for their hard work on this. (closes issue #17565) Reported by: russell Patches: asteriskv6-test-report.pdf uploaded by russell (license 2) Review: https://reviewboard.asterisk.org/r/743 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@274783 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_rtp_multicast.c')
-rw-r--r--res/res_rtp_multicast.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/res/res_rtp_multicast.c b/res/res_rtp_multicast.c
index b58f4b36e..19d21bcfb 100644
--- a/res/res_rtp_multicast.c
+++ b/res/res_rtp_multicast.c
@@ -44,7 +44,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/config.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
-#include "asterisk/netsock.h"
#include "asterisk/cli.h"
#include "asterisk/manager.h"
#include "asterisk/unaligned.h"
@@ -90,7 +89,7 @@ struct multicast_rtp {
};
/* Forward Declarations */
-static int multicast_rtp_new(struct ast_rtp_instance *instance, struct sched_context *sched, struct sockaddr_in *sin, void *data);
+static int multicast_rtp_new(struct ast_rtp_instance *instance, struct sched_context *sched, struct ast_sockaddr *addr, void *data);
static int multicast_rtp_activate(struct ast_rtp_instance *instance);
static int multicast_rtp_destroy(struct ast_rtp_instance *instance);
static int multicast_rtp_write(struct ast_rtp_instance *instance, struct ast_frame *frame);
@@ -107,7 +106,7 @@ static struct ast_rtp_engine multicast_rtp_engine = {
};
/*! \brief Function called to create a new multicast instance */
-static int multicast_rtp_new(struct ast_rtp_instance *instance, struct sched_context *sched, struct sockaddr_in *sin, void *data)
+static int multicast_rtp_new(struct ast_rtp_instance *instance, struct sched_context *sched, struct ast_sockaddr *addr, void *data)
{
struct multicast_rtp *multicast;
const char *type = data;
@@ -143,22 +142,30 @@ static int multicast_send_control_packet(struct ast_rtp_instance *instance, stru
struct multicast_control_packet control_packet = { .unique_id = htonl((u_long)time(NULL)),
.command = htonl(command),
};
- struct sockaddr_in control_address, remote_address;
+ struct ast_sockaddr control_address, remote_address;
ast_rtp_instance_get_local_address(instance, &control_address);
ast_rtp_instance_get_remote_address(instance, &remote_address);
/* Ensure the user of us have given us both the control address and destination address */
- if (!control_address.sin_addr.s_addr || !remote_address.sin_addr.s_addr) {
+ if (ast_sockaddr_isnull(&control_address) ||
+ ast_sockaddr_isnull(&remote_address)) {
return -1;
}
- control_packet.ip = remote_address.sin_addr.s_addr;
- control_packet.port = htonl(ntohs(remote_address.sin_port));
+ /* The protocol only supports IPv4. */
+ if (ast_sockaddr_is_ipv6(&remote_address)) {
+ ast_log(LOG_WARNING, "Cannot send control packet for IPv6 "
+ "remote address.\n");
+ return -1;
+ }
+
+ control_packet.ip = htonl(ast_sockaddr_ipv4(&remote_address));
+ control_packet.port = htonl(ast_sockaddr_port(&remote_address));
/* Based on a recommendation by Brian West who did the FreeSWITCH implementation we send control packets twice */
- sendto(multicast->socket, &control_packet, sizeof(control_packet), 0, (struct sockaddr *)&control_address, sizeof(control_address));
- sendto(multicast->socket, &control_packet, sizeof(control_packet), 0, (struct sockaddr *)&control_address, sizeof(control_address));
+ ast_sendto(multicast->socket, &control_packet, sizeof(control_packet), 0, &control_address);
+ ast_sendto(multicast->socket, &control_packet, sizeof(control_packet), 0, &control_address);
return 0;
}
@@ -196,7 +203,7 @@ static int multicast_rtp_write(struct ast_rtp_instance *instance, struct ast_fra
{
struct multicast_rtp *multicast = ast_rtp_instance_get_data(instance);
struct ast_frame *f = frame;
- struct sockaddr_in remote_address;
+ struct ast_sockaddr remote_address;
int hdrlen = 12, res, codec;
unsigned char *rtpheader;
@@ -223,11 +230,12 @@ static int multicast_rtp_write(struct ast_rtp_instance *instance, struct ast_fra
/* Finally send it out to the eager phones listening for us */
ast_rtp_instance_get_remote_address(instance, &remote_address);
- res = sendto(multicast->socket, (void *) rtpheader, f->datalen + hdrlen, 0, (struct sockaddr *) &remote_address, sizeof(remote_address));
+ res = ast_sendto(multicast->socket, (void *) rtpheader, f->datalen + hdrlen, 0, &remote_address);
if (res < 0) {
- ast_log(LOG_ERROR, "Multicast RTP Transmission error to %s:%u: %s\n",
- ast_inet_ntoa(remote_address.sin_addr), ntohs(remote_address.sin_port), strerror(errno));
+ ast_log(LOG_ERROR, "Multicast RTP Transmission error to %s: %s\n",
+ ast_sockaddr_stringify(&remote_address),
+ strerror(errno));
}
/* If we were forced to duplicate the frame free the new one */