0

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.

  • 1
    You might have to just continue using `setsockopt`. Just get the socket descriptor from the `QUdpSocket`. Refer to `QAbstractSocket::socketDescriptor()`. – RA. Mar 21 '14 at 16:40

1 Answers1

0

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.

user3427419
  • 1,769
  • 11
  • 15
  • Aside: sure this is the reason why I start refactor. I don't know what means that hex consts )) – Belyakov Max Mar 24 '14 at 11:37
  • If this is for Linux, you can look at socket options in /usr/include/bits/in.h . It seems that the actual structure this represents is struct ip_opts { struct in_addr ip_dst; /* First hop; zero without source route. */ char ip_opts[40]; /* Actually variable in size. */ }; Good luck. – user3427419 Mar 31 '14 at 05:35