gst_avtp_sink_start (GstBaseSink * basesink)
{
int fd, res;
- struct ifreq req;
+ unsigned int index;
guint8 addr[ETH_ALEN];
struct sockaddr_ll sk_addr;
GstAvtpSink *avtpsink = GST_AVTP_SINK (basesink);
+ index = if_nametoindex (avtpsink->ifname);
+ if (!index) {
+ GST_ERROR_OBJECT (avtpsink, "Failed to get if_index: %s", strerror (errno));
+ return FALSE;
+ }
+
fd = socket (AF_PACKET, SOCK_DGRAM | SOCK_NONBLOCK, htons (ETH_P_TSN));
if (fd < 0) {
GST_ERROR_OBJECT (avtpsink, "Failed to open socket: %s", strerror (errno));
goto err;
}
- snprintf (req.ifr_name, sizeof (req.ifr_name), "%s", avtpsink->ifname);
- res = ioctl (fd, SIOCGIFINDEX, &req);
- if (res < 0) {
- GST_ERROR_OBJECT (avtpsink, "Failed to ioctl(): %s", strerror (errno));
- goto err;
- }
-
sk_addr.sll_family = AF_PACKET;
sk_addr.sll_protocol = htons (ETH_P_TSN);
sk_addr.sll_halen = ETH_ALEN;
- sk_addr.sll_ifindex = req.ifr_ifindex;
+ sk_addr.sll_ifindex = index;
sk_addr.sll_hatype = 0;
sk_addr.sll_pkttype = 0;
memcpy (sk_addr.sll_addr, addr, ETH_ALEN);
gst_avtp_src_start (GstBaseSrc * basesrc)
{
int fd, res;
+ unsigned int index;
guint8 addr[ETH_ALEN];
- struct ifreq req = { 0 };
struct sockaddr_ll sk_addr = { 0 };
struct packet_mreq mreq = { 0 };
GstAvtpSrc *avtpsrc = GST_AVTP_SRC (basesrc);
+ index = if_nametoindex (avtpsrc->ifname);
+ if (!index) {
+ GST_ERROR_OBJECT (avtpsrc, "Failed to get if_index: %s", strerror (errno));
+ return FALSE;
+ }
+
fd = socket (AF_PACKET, SOCK_DGRAM, htons (ETH_P_TSN));
if (fd < 0) {
GST_ERROR_OBJECT (avtpsrc, "Failed to open socket: %s", strerror (errno));
return FALSE;
}
- snprintf (req.ifr_name, sizeof (req.ifr_name), "%s", avtpsrc->ifname);
- res = ioctl (fd, SIOCGIFINDEX, &req);
- if (res < 0) {
- GST_ERROR_OBJECT (avtpsrc, "Failed to ioctl(): %s", strerror (errno));
- goto err;
- }
-
sk_addr.sll_family = AF_PACKET;
sk_addr.sll_protocol = htons (ETH_P_TSN);
- sk_addr.sll_ifindex = req.ifr_ifindex;
+ sk_addr.sll_ifindex = index;
res = bind (fd, (struct sockaddr *) &sk_addr, sizeof (sk_addr));
if (res < 0) {
goto err;
}
- mreq.mr_ifindex = req.ifr_ifindex;
+ mreq.mr_ifindex = index;
mreq.mr_type = PACKET_MR_MULTICAST;
mreq.mr_alen = ETH_ALEN;
memcpy (&mreq.mr_address, addr, ETH_ALEN);