Commit 8b1edfb8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Support for IPv6 multicast output interface setting

parent 91c7ab79
/*****************************************************************************
* broadcast.cpp : SAP Broadcast class
****************************************************************************
* Copyright (C) 1998-2005 VideoLAN
* Copyright (C) 1998-2006 VideoLAN
* $Id$
*
* Authors: Damien Lucas <nitrox@videolan.org>
......@@ -48,7 +48,7 @@ Broadcast::Broadcast(int i_ttl, const char *psz_iface) : fd4 (-1), fd6 (-1),
if (psz_iface != NULL)
scope_id = if_nametoindex (psz_iface);
fd6 = socket (PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
fd6 = socket (AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if (fd6 != -1)
{
int dummy = 1;
......@@ -57,6 +57,28 @@ Broadcast::Broadcast(int i_ttl, const char *psz_iface) : fd4 (-1), fd6 (-1),
struct sockaddr_in6 addr = { };
addr.sin6_family = AF_INET6;
if (psz_iface != NULL)
{
int scope_id = if_nametoindex (psz_iface);
if (scope_id != 0)
{
if (setsockopt (fd6, IPPROTO_IPV6, IPV6_MULTICAST_IF,
&scope_id, sizeof (scope_id)) == 0)
scope_id = 0;
else
perror("setsockopt(IPV6_MULTICAST_IF)");
}
else
perror (psz_iface);
if (scope_id == 0)
{
close (fd6);
fd6 = -1;
}
}
if (i_ttl != 0)
setsockopt (fd6, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
&i_ttl, sizeof(i_ttl));
......@@ -71,7 +93,7 @@ Broadcast::Broadcast(int i_ttl, const char *psz_iface) : fd4 (-1), fd6 (-1),
}
/* Initializes IPv4 socket */
fd4 = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP);
fd4 = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (fd4 != -1)
{
int dummy = 1;
......@@ -82,12 +104,12 @@ Broadcast::Broadcast(int i_ttl, const char *psz_iface) : fd4 (-1), fd6 (-1),
if (psz_iface != NULL)
{
struct ifreq sInterface;
strncpy (sInterface.ifr_name, psz_iface, IFNAMSIZ - 1);
sInterface.ifr_name[IFNAMSIZ - 1] = '\0';
if (ioctl (fd4, SIOCGIFADDR, &sInterface) < 0)
struct ifreq req;
strncpy (req.ifr_name, psz_iface, IFNAMSIZ - 1);
req.ifr_name[IFNAMSIZ - 1] = '\0';
if (ioctl (fd4, SIOCGIFADDR, &req) < 0)
{
perror("ioctl(SIOCGIFADDR)");
close (fd4);
......@@ -96,11 +118,11 @@ Broadcast::Broadcast(int i_ttl, const char *psz_iface) : fd4 (-1), fd6 (-1),
else
{
struct in_addr *ip;
ip = &((struct sockaddr_in *)(&sInterface.ifr_addr))->sin_addr;
ip = &((struct sockaddr_in *)(&req.ifr_addr))->sin_addr;
if (setsockopt(fd4, IPPROTO_IP, IP_MULTICAST_IF,
(char *)ip, sizeof (*ip)))
{
perror("setsockopt");
perror("setsockopt(IP_MULTICAST_IF)");
close (fd4);
fd4 = -1;
}
......@@ -191,7 +213,7 @@ int Broadcast::GuessDestination (const char *str,
fprintf (stderr, "%s: invalid IP address\n", str);
return -1;
}
/* str is an IPv4 address */
in_addr_t ip = ntohl (n.in.s_addr);
......@@ -216,7 +238,7 @@ int Broadcast::GuessDestination (const char *str,
return -1;
}
ip = htonl (ip);
ip = htonl (ip);
struct sockaddr_in *a4 = (struct sockaddr_in *)addr;
memset (a4, 0, sizeof (*a4));
a4->sin_family = AF_INET;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment