Problem with QUdpSocket bind with port lower than 1024
-
Hi to everyone!
I develop my desktop application with MacOS. My application use a udp port: 1002.
I know that all the unix system has a protected ports below 1024.Initially i binded the ip and port in this way:
// create a QUDP socket socket = new QUdpSocket(this); port = 1002; QHostAddress *addr; addr = new QHostAddress(ThisHostIpAddress); if(!socket->bind(*addr, port)){ qDebug() << "I cannot bind socket with IP: " + ThisHostIpAddress + " and port: " + QString::number(port); qDebug() << socket->errorString(); } this->socket->setSocketOption(QAbstractSocket::ReceiveBufferSizeSocketOption,8000000); connect(socket, SIGNAL(readyRead()), this, SLOT(OnDataReceived()));
but in this way it didn't work.
So i tried to change the binded ip address as QHostAddress::AnyIPv4:// create a QUDP socket socket = new QUdpSocket(this); port = 1002; QHostAddress *addr; addr = new QHostAddress(ThisHostIpAddress); if(!socket->bind(QHostAddress::AnyIPv4, port)){ qDebug() << "I cannot bind socket with IP: " + ThisHostIpAddress + " and port: " + QString::number(port); qDebug() << socket->errorString(); } this->socket->setSocketOption(QAbstractSocket::ReceiveBufferSizeSocketOption,8000000); connect(socket, SIGNAL(readyRead()), this, SLOT(OnDataReceived()));
In this way, it seems work.. but not in the correct way. I'll explain: if my computer has only one network card, it works! But if you've 2 or more network cards you cannot decide the network card for outgoing the packets but it's always the first one.
Someone can help me?
-
The outgoing network interface will be whichever one has the least cost route to the destination IP, or the default gateway if no more specific route exists. Without knowing the destination IP, routing table and interfaces of your machine there's no way to be more specific.
-
Hi to everyone!
I develop my desktop application with MacOS. My application use a udp port: 1002.
I know that all the unix system has a protected ports below 1024.Initially i binded the ip and port in this way:
// create a QUDP socket socket = new QUdpSocket(this); port = 1002; QHostAddress *addr; addr = new QHostAddress(ThisHostIpAddress); if(!socket->bind(*addr, port)){ qDebug() << "I cannot bind socket with IP: " + ThisHostIpAddress + " and port: " + QString::number(port); qDebug() << socket->errorString(); } this->socket->setSocketOption(QAbstractSocket::ReceiveBufferSizeSocketOption,8000000); connect(socket, SIGNAL(readyRead()), this, SLOT(OnDataReceived()));
but in this way it didn't work.
So i tried to change the binded ip address as QHostAddress::AnyIPv4:// create a QUDP socket socket = new QUdpSocket(this); port = 1002; QHostAddress *addr; addr = new QHostAddress(ThisHostIpAddress); if(!socket->bind(QHostAddress::AnyIPv4, port)){ qDebug() << "I cannot bind socket with IP: " + ThisHostIpAddress + " and port: " + QString::number(port); qDebug() << socket->errorString(); } this->socket->setSocketOption(QAbstractSocket::ReceiveBufferSizeSocketOption,8000000); connect(socket, SIGNAL(readyRead()), this, SLOT(OnDataReceived()));
In this way, it seems work.. but not in the correct way. I'll explain: if my computer has only one network card, it works! But if you've 2 or more network cards you cannot decide the network card for outgoing the packets but it's always the first one.
Someone can help me?
@edoardo-videx said in Problem with QUdpSocket bind with port lower than 1024:
I know that all the unix system has a protected ports below 1024.
and what do you think MacOS is ?
-
@edoardo-videx said in Problem with QUdpSocket bind with port lower than 1024:
I know that all the unix system has a protected ports below 1024.
and what do you think MacOS is ?
@J-Hilk macOS is based on unix.. but i need to know if exist a workaround..
-
@J-Hilk macOS is based on unix.. but i need to know if exist a workaround..
-
@edoardo-videx
The "workaround" is why do you want to use a port lower than 1024My application use a udp port: 1002.
Why? Change it to use > 1024....
@JonB I cannot change the port. But anyway if, for example, i want to do a custom HTTP server that use the port 80, is it not possible? It's really absurd.
-
The outgoing network interface will be whichever one has the least cost route to the destination IP, or the default gateway if no more specific route exists. Without knowing the destination IP, routing table and interfaces of your machine there's no way to be more specific.
@ChrisW67 i've problem when i send a broadcast packets (255.255.255.255) in this case i cannot select the network card but MacOS choose for me
-
@JonB I cannot change the port. But anyway if, for example, i want to do a custom HTTP server that use the port 80, is it not possible? It's really absurd.
@edoardo-videx said in Problem with QUdpSocket bind with port lower than 1024:
It's really absurd.
All ports below 1024 are meant to be used with special rights. If you program don't have these rights you can't use them. Don't see anything absurd here...