UdpSrc?
killerrats
koreysjunkmail at gmail.com
Thu Oct 10 23:43:33 UTC 2019
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:
g_socket_bind(socketUDP,
g_inet_socket_address_new(g_inet_address_new_from_string(interfaceIp),
port), TRUE, &err);
doesn't bind to the interface. if i changed to:
g_socket_bind(socketUDP,
g_inet_socket_address_new(g_inet_address_new_any(G_SOCKET_FAMILY_IPV4),
port), TRUE, &err)
seems to bind the first available interface which is not the one i want. any
suggestions?
GSocket* GetTheSocketReady(const char* ipaddress, const int portNumber,
const char* interfaceIp){ GSocketAddress *bind_addr; GInetAddress
*bind_iaddr; GSocketFamily family; guint16 port = portNumber; GError *err =
NULL; gint val = 0; const guint8 *native_addr; struct ip_mreq mc_req;
GInetSocketAddress *bAddr; guint16 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)); GSocket *
socketUDP = g_socket_new(family, G_SOCKET_TYPE_DATAGRAM,
G_SOCKET_PROTOCOL_UDP, &err); if (socketUDP == NULL) { printf("Could not
create socket: %s", err->message); g_object_unref(bind_addr); goto 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);
goto 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 { goto 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))) { printf("\r\nYeah\r\n"); } End: {
g_object_unref(bind_iaddr); return socketUDP; } Error: {
g_object_unref(bind_iaddr); return NULL; }}
-----
------------------------------
Gstreamer 1.14.3
------------------------------
Windows
--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20191010/7e4a5306/attachment.html>
More information about the gstreamer-devel
mailing list