Question

I have some old code, which use this flags in socket:

unsigned char str_optval [8] = {0xfc, 0x08, 0xff, 0x33, 0xcc, 0xff, 0xaa, 0x0};
res=setsockopt(sid,SOL_IP,IP_OPTIONS, (char*)&str_optval,sizeof(str_optval));

How can I change this place to use QUdpSocket? I can't find any analog setsockopt in QUdpClass. QAbstractSocket provide setSocketOption, which allow only 4 variants flags (enum). I need it only in linux version, so if any native func it's ok.

Was it helpful?

Solution

http://qt-project.org/doc/qt-5.0/qtnetwork/qabstractsocket.html#SocketOption-enum

Socket options are not limited to UDP datagrams. Having said that, Qt only has a limited number of options you can set on a socket. The most common options to actually being able to set. The rest are platform specific stuff.

ASIDE: hardcoded literals, like in your quoted code, are a big no-no. Non-portable and a nightmare to maintain. Whatever you do, at least change those literals to names defined in standard headers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top