| 47 | } |
| 48 | |
| 49 | bool CPassiveSocket::BindMulticast(const char *pInterface, const char *pGroup, uint16 nPort) |
| 50 | { |
| 51 | bool bRetVal = false; |
| 52 | #ifdef WIN32 |
| 53 | ULONG inAddr; |
| 54 | #else |
| 55 | int32 nReuse; |
| 56 | in_addr_t inAddr; |
| 57 | |
| 58 | nReuse = IPTOS_LOWDELAY; |
| 59 | #endif |
| 60 | |
| 61 | //-------------------------------------------------------------------------- |
| 62 | // Set the following socket option SO_REUSEADDR. This will allow the file |
| 63 | // descriptor to be reused immediately after the socket is closed instead |
| 64 | // of setting in a TIMED_WAIT state. |
| 65 | //-------------------------------------------------------------------------- |
| 66 | memset(&m_stMulticastGroup, 0, sizeof(m_stMulticastGroup)); |
| 67 | m_stMulticastGroup.sin_family = AF_INET; |
| 68 | m_stMulticastGroup.sin_port = htons(nPort); |
| 69 | |
| 70 | //-------------------------------------------------------------------------- |
| 71 | // If no IP Address (interface ethn) is supplied, or the loop back is |
| 72 | // specified then bind to any interface, else bind to specified interface. |
| 73 | //-------------------------------------------------------------------------- |
| 74 | if ((pInterface == NULL) || (!strlen(pInterface))) |
| 75 | { |
| 76 | m_stMulticastGroup.sin_addr.s_addr = htonl(INADDR_ANY); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | if ((inAddr = inet_addr(pInterface)) != INADDR_NONE) |
| 81 | { |
| 82 | m_stMulticastGroup.sin_addr.s_addr = inAddr; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | //-------------------------------------------------------------------------- |
| 87 | // Bind to the specified port |
| 88 | //-------------------------------------------------------------------------- |
| 89 | if (bind(m_socket, (struct sockaddr *)&m_stMulticastGroup, sizeof(m_stMulticastGroup)) == 0) |
| 90 | { |
| 91 | //---------------------------------------------------------------------- |
| 92 | // Join the multicast group |
| 93 | //---------------------------------------------------------------------- |
| 94 | m_stMulticastRequest.imr_multiaddr.s_addr = inet_addr(pGroup); |
| 95 | m_stMulticastRequest.imr_interface.s_addr = m_stMulticastGroup.sin_addr.s_addr; |
| 96 | |
| 97 | if (SETSOCKOPT(m_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, |
| 98 | (void *)&m_stMulticastRequest, |
| 99 | sizeof(m_stMulticastRequest)) == CSimpleSocket::SocketSuccess) |
| 100 | { |
| 101 | bRetVal = true; |
| 102 | } |
| 103 | |
| 104 | m_timer.SetEndTime(); |
| 105 | } |
| 106 |
nothing calls this directly
no test coverage detected