<commit_before>#include "sacnsocket.h"

#include <QNetworkInterface>
#include <QNetworkAddressEntry>
#include <QDebug>
#include "ipaddr.h"
#include "streamcommon.h"

sACNRxSocket::sACNRxSocket(QObject *parent) : QUdpSocket(parent)
{

}

bool sACNRxSocket::bindMulticast(quint16 universe)
{
    bool ok = false;

    QNetworkInterface iface = Preferences::getInstance()->networkInterface();

    CIPAddr addr;
    GetUniverseAddress(universe, addr);

    // Bind to mutlicast address
    ok = bind(addr.ToQHostAddress(),
                   addr.GetIPPort(),
                   QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint);

    // Join multicast on selected NIC
    if (ok)
    {
        setMulticastInterface(iface);
        ok |= joinMulticastGroup(QHostAddress(addr.GetV4Address()), iface);
    }

    if(ok)
    {
        qDebug() << "sACNRxSocket : Bound to interface:" << iface.name();
        qDebug() << "sACNRxSocket : Joining Multicast Group:" << QHostAddress(addr.GetV4Address()).toString();
    }
    else
    {
        close();
        qDebug() << "sACNRxSocket : Failed to bind RX socket";
    }

    return ok;
}

bool sACNRxSocket::bindUnicast()
{
    bool ok = false;

    // Bind to first IPv4 address on selected NIC
    QNetworkInterface iface = Preferences::getInstance()->networkInterface();

    foreach (QNetworkAddressEntry ifaceAddr, iface.addressEntries())
    {
        if (ifaceAddr.ip().protocol() == QAbstractSocket::IPv4Protocol)
        {
            ok = bind(ifaceAddr.ip(),
                      STREAM_IP_PORT,
                      QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint);
            qDebug() << "sACNRxSocket : Bound to IP:" << ifaceAddr.ip().toString();
            break;
        }
    }

    if(!ok)
        qDebug() << "sACNRxSocket : Failed to bind RX socket";

    return ok;
}

sACNTxSocket::sACNTxSocket(QObject *parent) : QUdpSocket(parent)
{

}

bool sACNTxSocket::bindMulticast()
{
    bool ok = false;

    // Bind to first IPv4 address on selected NIC
    QNetworkInterface iface = Preferences::getInstance()->networkInterface();

    foreach (QNetworkAddressEntry ifaceAddr, iface.addressEntries())
    {
        if (ifaceAddr.ip().protocol() == QAbstractSocket::IPv4Protocol)
        {
            ok = bind(ifaceAddr.ip());
            setSocketOption(QAbstractSocket::MulticastLoopbackOption, QVariant(1));
            setMulticastInterface(iface);
            qDebug() << "sACNTxSocket : Bound to IP:" << ifaceAddr.ip().toString();
            break;
        }
    }

    if(!ok)
        qDebug() << "sACNTxSocket : Failed to bind TX socket";

    return ok;
}
<commit_msg>MacOS Fails to bind to bind multicast to correct interface<commit_after>#include "sacnsocket.h"

#include <QNetworkInterface>
#include <QNetworkAddressEntry>
#include <QDebug>
#include "ipaddr.h"
#include "streamcommon.h"

sACNRxSocket::sACNRxSocket(QObject *parent) : QUdpSocket(parent)
{

}

bool sACNRxSocket::bindMulticast(quint16 universe)
{
    bool ok = false;

    QNetworkInterface iface = Preferences::getInstance()->networkInterface();

    CIPAddr addr;
    GetUniverseAddress(universe, addr);

    // Bind to mutlicast address
    ok = bind(addr.ToQHostAddress(),
                   addr.GetIPPort(),
                   QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint);

    // Join multicast on selected NIC
    if (ok)
    {
        #if (QT_VERSION <= QT_VERSION_CHECK(5, 8, 0))
        #error setMulticastInterface() fails to bind to correct interface on systems running IPV4 and IPv6 with QT <= 5.8.0
        #endif
        setMulticastInterface(iface);
        ok |= joinMulticastGroup(QHostAddress(addr.GetV4Address()), iface);
    }

    if(ok)
    {
        qDebug() << "sACNRxSocket : Bound to interface:" << iface.name();
        qDebug() << "sACNRxSocket : Joining Multicast Group:" << QHostAddress(addr.GetV4Address()).toString();
    }
    else
    {
        close();
        qDebug() << "sACNRxSocket : Failed to bind RX socket";
    }

    return ok;
}

bool sACNRxSocket::bindUnicast()
{
    bool ok = false;

    // Bind to first IPv4 address on selected NIC
    QNetworkInterface iface = Preferences::getInstance()->networkInterface();

    foreach (QNetworkAddressEntry ifaceAddr, iface.addressEntries())
    {
        if (ifaceAddr.ip().protocol() == QAbstractSocket::IPv4Protocol)
        {
            ok = bind(ifaceAddr.ip(),
                      STREAM_IP_PORT,
                      QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint);
            qDebug() << "sACNRxSocket : Bound to IP:" << ifaceAddr.ip().toString();
            break;
        }
    }

    if(!ok)
        qDebug() << "sACNRxSocket : Failed to bind RX socket";

    return ok;
}

sACNTxSocket::sACNTxSocket(QObject *parent) : QUdpSocket(parent)
{

}

bool sACNTxSocket::bindMulticast()
{
    bool ok = false;

    // Bind to first IPv4 address on selected NIC
    QNetworkInterface iface = Preferences::getInstance()->networkInterface();

    foreach (QNetworkAddressEntry ifaceAddr, iface.addressEntries())
    {
        if (ifaceAddr.ip().protocol() == QAbstractSocket::IPv4Protocol)
        {
            ok = bind(ifaceAddr.ip());
            setSocketOption(QAbstractSocket::MulticastLoopbackOption, QVariant(1));
            setMulticastInterface(iface);
            qDebug() << "sACNTxSocket : Bound to IP:" << ifaceAddr.ip().toString();
            break;
        }
    }

    if(!ok)
        qDebug() << "sACNTxSocket : Failed to bind TX socket";

    return ok;
}

{'fraction_non_alphanumeric': 0.12205146533238027, 'fraction_numerical': 0.004646175839885632, 'mean_word_length': 2.8152692569870483, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3793097', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1704, 'n_words': 362}