MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / BindMulticast

Method BindMulticast

examples/ThirdPartyLibs/clsocket/src/PassiveSocket.cpp:49–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49bool 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

Callers

nothing calls this directly

Calls 4

SetEndTimeMethod · 0.80
SetStartTimeMethod · 0.80
CloseFunction · 0.50
InitializeMethod · 0.45

Tested by

no test coverage detected