MCProxy

mc_socket Class Reference

Wrapper for a multicast socket.

#include "mc_socket.hpp"

List of all members.

Public Member Functions

bool bind_udp_socket (int port)
bool choose_if (const char *interface)
virtual bool create_udp_ipv4_socket ()
virtual bool create_udp_ipv6_socket ()
int get_addr_family ()
bool is_udp_valid ()
bool join_group (const char *addr, const char *interface)
bool leave_group (const char *addr, const char *interface)
 mc_socket ()
bool receive_msg (struct msghdr *msg, int &sizeOfInfo)
bool receive_packet (unsigned char *buf, int sizeOfBuf, int &sizeOfInfo)
bool send_packet (const char *addr, int port, const unsigned char *data, unsigned int data_size)
bool send_packet (const char *addr, int port, string data)
bool set_loop_back (bool enable)
bool set_own_socket (int socket, int addr_family)
bool set_receive_timeout (long msec)
virtual ~mc_socket ()

Static Public Member Functions

static void test_join_leave_send ()

Protected Member Functions

 mc_socket (const mc_socket &copy)

Protected Attributes

int m_addrFamily
int m_ifIndex
bool m_own_socket
int m_sock

Constructor & Destructor Documentation

mc_socket::mc_socket ( const mc_socket copy  )  [protected]

Mc_socket mustnt be copied because its contain an unique socket.

mc_socket::mc_socket (  ) 

Create a multicast socket.

References HC_LOG_TRACE.

mc_socket::~mc_socket (  )  [virtual]

Close the internal datagram socket.

References HC_LOG_TRACE, is_udp_valid(), m_own_socket, and m_sock.


Member Function Documentation

bool mc_socket::bind_udp_socket ( int  port  ) 

Bind IPv4 or IPv6 socket to a specific port.

Returns:
Return true on success.

References HC_LOG_DEBUG, HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), m_addrFamily, and m_sock.

bool mc_socket::choose_if ( const char *  interface  ) 

Choose a specific network interface.

! interface: IPv4 ==> InterfaceIpAddress , IPv6 ==> InterfaceName

Parameters:
interface (with IPv4) specific network interface address
interface (with IPv6) interface name
Attention:
The parameter interface has different meaning with different ip versions!!
Returns:
Return true on success.

References HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), m_addrFamily, m_ifIndex, and m_sock.

Referenced by test_join_leave_send().

bool mc_socket::create_udp_ipv4_socket (  )  [virtual]

Create an IPv4 datagram socket.

References HC_LOG_DEBUG, HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), m_addrFamily, m_own_socket, and m_sock.

Referenced by test_join_leave_send().

bool mc_socket::create_udp_ipv6_socket (  )  [virtual]

Create IPv6 datagram socket.

References HC_LOG_DEBUG, HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), m_addrFamily, m_own_socket, and m_sock.

Referenced by test_join_leave_send().

int mc_socket::get_addr_family (  ) 
Returns:
Get the address family (AF_INET | AF_INET6).

References m_addrFamily.

Referenced by mroute_socket::test_add_route(), and mroute_socket::test_del_route().

bool mc_socket::join_group ( const char *  addr,
const char *  interface 
)

Join a multicast group on a specific network interface.

! interface: IPv4 ==> InterfaceIpAddress , IPv6 ==> InterfaceName

Parameters:
addr group to join in clear text
interface (with IPv4) specific network interface address
interface (with IPv6) interface name
Attention:
The parameter interface has different meaning with different ip versions!!
Returns:
Return true on success.

References HC_LOG_DEBUG, HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), m_addrFamily, and m_sock.

Referenced by mld_sender::send_report(), igmp_sender::send_report(), and test_join_leave_send().

bool mc_socket::leave_group ( const char *  addr,
const char *  interface 
)

Leave a multicast group on a specific network interface.

! interface: IPv4 ==> InterfaceIpAddress , IPv6 ==> InterfaceName

Parameters:
addr group to join in clear text
interface (with IPv4) specific network interface address
interface (with IPv6) interface name
Attention:
The parameter interface has different meaning with different ip versions!!
Returns:
Return true on success.

References HC_LOG_DEBUG, HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), m_addrFamily, and m_sock.

Referenced by mld_sender::send_leave(), igmp_sender::send_leave(), and test_join_leave_send().

bool mc_socket::receive_msg ( struct msghdr *  msg,
int &  sizeOfInfo 
)

Receive a message with the kernel function recvmsg().

Parameters:
[out] msg received message
[out] sizeOfInfo size of the received message
Returns:
Return true on success.

References HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), and m_sock.

bool mc_socket::receive_packet ( unsigned char *  buf,
int  sizeOfBuf,
int &  sizeOfInfo 
)

Receive a datagram.

Parameters:
[out] buf read N bytes into buf from socket
[in] sizeOfBuf size of buf
[out] sizeOfInfo filled with the effective packet length less then sizeOfBuf
Returns:
Return true on success.

References HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), and m_sock.

bool mc_socket::send_packet ( const char *  addr,
int  port,
const unsigned char *  data,
unsigned int  data_size 
)

Send data to a specific ip address and to a specific port.

Parameters:
addr destination address of the packet in clear text
port destination port
data data to send
data_size size of the data
Returns:
Return true on success.

References HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), m_addrFamily, m_ifIndex, m_sock, and MC_SCOKET_IF_CHOOSE_INIT.

bool mc_socket::send_packet ( const char *  addr,
int  port,
string  data 
)

set the socket option for receive all multicast packet only used for ipv4

Send a string to a specific ip address and to a specific port.

Parameters:
addr destination address of packet in clear text
port destination port
data message to send
Returns:
Return true on success.

Referenced by mld_sender::send_general_query(), igmp_sender::send_general_query(), mld_sender::send_group_specific_query(), igmp_sender::send_group_specific_query(), and test_join_leave_send().

bool mc_socket::set_loop_back ( bool  enable  ) 

Enable or disable multicast loopback.

Returns:
Return true on success.

References HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), m_addrFamily, and m_sock.

Referenced by sender::init().

bool mc_socket::set_own_socket ( int  socket,
int  addr_family 
)

Set an extern socket.

Parameters:
socket socket descriptor
addr_family used address family (AF_INET or AF_INET6)
Returns:
Return true on success.

References HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), m_addrFamily, m_own_socket, and m_sock.

bool mc_socket::set_receive_timeout ( long  msec  ) 

Set a receive timeout.

Parameters:
msec timeout in millisecond
Returns:
Return true on success.

References HC_LOG_ERROR, HC_LOG_TRACE, is_udp_valid(), and m_sock.

Referenced by receiver::init().

void mc_socket::test_join_leave_send (  )  [static]

Member Data Documentation

int mc_socket::m_ifIndex [protected]

Used interface index if the socket is bind to an interface.

Referenced by choose_if(), and send_packet().