<p>
following method I got to work to set in the udpsrc to connect to a multicast address. the only thing is that the line that says:</p>
<p>g_socket_bind(socketUDP, g_inet_socket_address_new(g_inet_address_new_from_string(interfaceIp), port), TRUE, &err);</p>
<p>doesn't bind to the interface. if i changed to:</p>
<p>g_socket_bind(socketUDP, g_inet_socket_address_new(g_inet_address_new_any(G_SOCKET_FAMILY_IPV4), port), TRUE, &err)</p>
<p>seems to bind the first available interface which is not the one i want. any suggestions?</p>
<pre>
<font color=green>GSocket</font>* GetTheSocketReady(<font color=blue>const</font> <font color=green>char</font>* ipaddress, <font color=blue>const int</font> portNumber, <font color=blue>const char</font>* interfaceIp)
{
<font color=green>GSocketAddress</font> *bind_addr;
<font color=green>GInetAddress</font> *bind_iaddr;
<font color=green>GSocketFamily</font> family;
<font color=green>guint16</font> port = portNumber;
<font color=green>GError</font> *err = NULL;
<font color=green>gint</font> val = 0;
<font color=blue>const</font> <font color=green>guint8</font> *native_addr;
<font color=blue>struct</font> <font color=green>ip_mreq</font> mc_req;
<font color=green>GInetSocketAddress</font> *bAddr;
<font color=green>guint16</font> bPort;
bind_iaddr = g_inet_address_new_from_string(ipaddress);
bind_addr = g_inet_socket_address_new(bind_iaddr, port);
family = g_socket_address_get_family(G_SOCKET_ADDRESS(bind_addr));
<font color=green>GSocket</font> * socketUDP = g_socket_new(family, G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, &err);
if (socketUDP == NULL)
{
<font color=purple>printf</font>("Could not create socket: %s", err->message);
g_object_unref(bind_addr);
<font color=blue>goto</font> Error;
}
if (!g_socket_bind(socketUDP, g_inet_socket_address_new(g_inet_address_new_from_string(interfaceIp), port), TRUE, &err))
{
printf("Failed to bind socket: %s", err->message);
<font color=blue>goto</font> Error;
}
g_socket_set_multicast_loopback(socketUDP, TRUE);
if (g_socket_get_option(socketUDP, SOL_SOCKET, SO_RCVBUF, &val,
NULL)) {
std::cout << "\r\nReceived\r\n";
}
else {
<font color=blue>goto</font> Error;
}
g_socket_set_broadcast(socketUDP, TRUE);
native_addr = g_inet_address_to_bytes(bind_iaddr);
memset(&mc_req, 0, sizeof(mc_req));
memcpy(&mc_req.imr_multiaddr, native_addr, sizeof(struct in_addr));
mc_req.imr_interface.s_addr = inet_addr(interfaceIp);
if (setsockopt(g_socket_get_fd(socketUDP), IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char*)&mc_req, sizeof(mc_req)))
{
<font color=purple>printf</font>("\r\nYeah\r\n");
}
End:
{
<font color=purple>g_object_unref</font>(bind_iaddr);
return socketUDP;
}
Error:
{
<font color=purple>g_object_unref</font>(bind_iaddr);
return NULL;
}
}
</pre>
<div class="signature" style="margin-top:1em;color:#666666;font-size:11px;">
------------------------------
<br/>Gstreamer 1.14.3
<br/>------------------------------
<br/>Windows
</div>
<br/><hr align="left" width="300" />
Sent from the <a href="http://gstreamer-devel.966125.n4.nabble.com/">GStreamer-devel mailing list archive</a> at Nabble.com.<br/>