Implement IP Multicast on Windows and VxWorks Systems

Source: Internet
Author: User

Implement IP Multicast on Windows and VxWorks Systems

Author: Yang Dengfeng 2004/04/24
Multicast is widely used in video conferencing. I will share my experiences with you.
(1) multicast Overview
Control Plane and control plane ).
(1) The control layer is divided into root and non-root ). The root node is responsible for the establishment of multicast nodes and the addition of other nodes. In a non-root multicast network, the conditions for each host to join a group are equivalent.
(2) The data layer is also rooted and rootless. With a root model, data members can only exchange data with nodes, but data cannot be exchanged between common members. In a non-heel model, data can be exchanged between members. If you send data to multicast groups, each node in the group receives the data. If you receive data from Multicast Groups, the data sent by any group member receives the data.
IP multicast is rootless at the control and data layers.

(2) IP Multicast
The IP address of multicast is Class D: 224.0.0.0 ~ 239.00000000255. Some of these IP addresses are retained. For example, 224.0.0.1 indicates all the systems in the subnet and 224.0.0.2 indicates all the routers in the subnet. Rfc1700 provides detailed descriptions.
When multicast data is transmitted within a sub-network, it is transmitted to the subnet through the multicast MAC address on a physical layer, the network port of the multicast host receives a packet in response to the multicast MAC address.
Composition of multicast MAC addresses:
47 23 22 0
______________________________
| 0x01005e | 0 | the last 23 digits of the multicast IP address |
| _________ |__ | ______________ |
The network port receives the MAC address packet corresponding to the multicast group and then transmits the packet to the device driver layer. The driver layer checks whether the packet contains the book multicast address. Because the multicast IP address is a 32-bit IP address, apart from the first four identical bits, it requires 28 BITs to be fully differentiated, while the MAC address only uses the last 23 bits of 28 to distinguish, it cannot be uniquely identified. Therefore, the driver layer must check whether the data packets on the network are multicast group data added to the host. When creating multicast groups, we should try to ensure that the last 23 bits are not repeated, so that we can distinguish multicast directly on the hardware. Do not waste valuable CPU time.

(3) IGMP Protocol
When a vro receives multicast data, it must know which hosts and multicast groups are added to the network. IGMP is generated for this reason.
(1) When a host is added to a multicast group, an IGMP packet is sent to the vro.
(2) The router sends an IGMP query at intervals to learn about the current multicast group members. An IGMP report is returned for the host that joins the multicast group.
The internet group management protocol is used to let all systems on the physical network know the multicast group of the host.
For more detailed IGMP instructions, see RFC 1112 [Deering 1989].

(4) Implementation Details
(1) Process
Create a socket and a socket
BIND (); Bind
Add multicast group to multicast group
Sengto (); recvfrom ();
......

Withdraw from multicast group

(2) window
Int ret = wsastartup (makeword (2, 2), & wsadata );
If (Ret! = 0 ){
// Deal with the error.
}

M_sockmanager = socket (af_inet, sock_dgram, 0 );
If (invalid_socket = m_sockmanager)
{
// Deal with the error.
}

Struct sockaddr_in local_addr_in;
Local_addr_in.sin_family = af_inet;
Local_addr_in.sin_port = htons (m_uport );
Local_addr_in.sin_addr.s_addr = htonl (inaddr_any );

Ierror = BIND (m_sockmanager, (const struct sockaddr *) & local_addr_in ,/
Sizeof (local_addr_in ));
If (socket_error = ierror)
{
// Deal with the error.
}

M_mcast.imr_interface.s_addr = inaddr_any;
M_mcast.imr_multiaddr.s_addr = htonl (m_ipmcastaddr );

Ierror = setsockopt (m_sockmanager, ipproto_ip, ip_add_membership ,/
(Char *) & m_mcast, sizeof (m_mcast ));
If (socket_error = ierror)
{
// Deal with the error.
}
// Send multicast data
Int iret = sendto (m_sockmanager, sendbuf, strlen (sendbuf), 0 ,/
(Struct sockaddr *) & m_remote, sizeof (m_remote ));
// Receives Multicast Data
Int iret = recvfrom (m_sockmanager, recvbuf, ilenbuf, 0,
(Struct sockaddr *) & sockfrom, & ilendata );
If (socket_error = iret)
{
// Deal with the error.
}
The multicast port must be determined based on the remote address sent. The receiving end then responds to the coordination.

(3) VxWorks
VxWorks is basically the same as winsock1.1 above.
However, in BIND (), the IP address of the machine on VxWorks can only be set to inaddr_any. Otherwise, the binding fails. (on the Internet, Fenhe has fixed this bug ). However, you can call setsockopt () after binding to specify the local interface.
Struct in_addr in_if;
In_if.s_addr = inet_addr ("10.9.1.25"); // The local address, depending on the situation.
Setsockopt (sockmanager, ipproto_ip, ip_multicast_if, (char *) & in_if, sizeof (in_if ));

The demo instance program attached to this article is implemented in the development environment Win2k Professional SP4 of vc6.0 for Windows. The VxWorks version is implemented in the tornado 2.0 development environment on the company's internal VxWorks operating system.

Due to learning shortest, improper welcome points: dengfengyang@hotmail.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.