IP multicast on the Windows system and VxWorks system
Author Yang Defeng 2004/04/24 Multicast The application of video conference is very wide. The author will share with everyone on the experience of learning. (1) Multicast summary multicast has a control level, a control plane. (1) The control level is divided into root, nonrooted. There is a root node responsible for the establishment of multicast nodes, and the addition of other nodes. No root multicast network, each host is equivalent when the group is added. (2) The data level is also divided into roots, no roots. The root model, the data member can only exchange data with the follow-up point, and the data between ordinary members cannot be exchanged. Nothing models, data between each member can exchange each other. Just send the data to the multicast group, each node in the group will receive; as long as the data of the multicast group is received, the data sent by any group member will receive it. IP multicast is rooted at the control level and the data level.
(2) IP multicast multicast IP address is D address: 224.0.0 ~ 239.255.255.255. Some IPs are reserved. For example, 224.0.0.1 represents all systems of the subnet, 224.0.0.2 Indicates all routers on the subnet. There is a detailed description of the RFC1700 in this regard. Multicast data is transmitted within one subnet, because in a physical layer, the network port of the multicast host will receive a response multicast MAC address. Packet. Multicast MAC address configuration: 47 23 22 0 __________________________________________________________________________________________________________________________. The device drive layer, the drive layer detects whether the data packet is multicast address. Because the multicast IP is 32 bits, in addition to the start of the same start, 28 points can be fully distinguished, and only 28 after the MAC address is used to distinguish it, inevitably uniquely determined, so the drive layer To verify that the packet on the network is the multicast group data added to the host. When we created a multicast group, we should try to do the 23 digits without repeating, so you can distinguish it directly on the hardware. Don't waste valuable CPU time.
(3) IGMP protocol When the router accepts multicast data, it is necessary to know which multicow groups have been added to which hosts have added. IGMP is based on this reason. (1) When the host adds a multicast group, it will send an IGMP package that adds a multicast group to the router. (2) The router will learn about the current multicast group member by sending an IGMP query every other period of time. The host adds a multicast group will return an IGMP report. The Internet Group Management Agreement is to let all the systems on the physics network know the multicast group where the host is located. More detailed IGMP instructions see RFC 1112 [Deering 1989]
(4) Realization Details (1) Process Create a socket, create a socketbind (); bind join multicast group to join the multicast group sengto (); recvfrom (); ... ... ...
Exit multicast group to exit multicast group
(2) Windowint 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);
Irror = bind (const struct socmeddr *) & local_addr_in, / sizeof (local_addr_in)); if (socket_error == Irror) {// DEAL with the error.}
M_mcast.imr_interface.s_addr = incaddr_any; m_mcast.imr_multiaddr.s_addr = HTONL (M_IPMCastAddr);
Irror = setsockopt (m_sockmanager, ipproto_ip, ip_add_membast, sizeof (m_mcast)); if (socket_error == Irror) {// deal with the error.} // Send Multicast Data IRet = Sendto m_SockManager, sendBuf, strlen (sendBuf), 0, / (struct sockaddr *) & m_Remote, sizeof (m_Remote)); // receive multicast int iRet = recvfrom (m_SockManager, recvBuf, iLenBuf, 0, (struct sockaddr *) & SockFrom , & inelendata); if (socket_error == iret) {// deal with the error.} where the multicast port is determined based on the remote address sent. The receiving end responds to coordination.
(3) VxWorksvxWorks is basically the same as Winsock1.1 above. However, when bind (), the VXWORKS system native IP can only be set to INAddr_any, otherwise the binding failed (online, Fenghe Company has FIX). However, setsockopt () can be called after binding to specify local interface.struct in_addr in_if; in_if.s_addr = inet_addr ("10.9.1.25"); // Specific local address, depending on the case, setsockopt (SockManager , Ipproto_ip, ip_multicast_if, (char *) & IN_IF, SIZEOF (IN_IF));
The Demo instance program provided herein, Windows version is implemented on the VC6.0 development environment Win2K Professional SP4. The VxWorks version is implemented on the Tornado 2.0 development environment, implemented on the company's internal VxWorks operating system.
Due to the shallowness, improperly welcome: dengfengyang@hotmail.com