Networking: TCP server Operation not permitted (errno -1)

Hi,

I’m currently working on a application that must run a TCP server to send and receive data.
The server is implemented in a standard way via sockets.

Simplified code of TCP server:

sockaddr_in serv_addr = {};
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(port);
m_listen_fd = socket(AF_INET, SOCK_STREAM, 0);

setsockopt(m_listen_fd, SOL_SOCKET, SO_BINDTODEVICE, iface.c_str(), iface.size());
bind(m_listen_fd, reinterpret_cast<sockaddr*>(&serv_addr), sizeof(serv_addr));

listen(m_listen_fd, 1) ;
m_listen_thread = std::make_uniquestd::thread(&TCPServer::acceptClient, this);

The TCP server can be started and it will wait for a client to connect.
However when a client connects, i got a ernno 1: Operation not permitted.

ssize_t result = recv(m_client_fd, buffer, s_c_recv_buffer_size, MSG_DONTWAIT); // << this will return a errno -1.

I’ve read other topics mentioning that the application probably doesn’t have permission to read/write to the network interface, which is in my case ecm0.
Is there a way to grant my application permission to use the specific network interface? Or is there some other issue that I am not aware of that is causing this error?

Things which I already configured or tried:

  • Firewall configuration changed to allow TCP communication on a specific port and interface
  • Running processes with sandboxed: false (still operation not permitted error)
  • Other samples using a TCP server, also result in an errno -1.

Platform details

  • Device: Sierra Wireless WP7700
  • Board: MangOH Red
  • Firmware version: SWI9X06Y_02.22.12.00
  • Legato Framework: 18.9.2.wp77xx

Hope that somebody can help me resolve this issue. :slight_smile:

you can refer to \apps\sample\fwupdateDownloader to see how it accepts tcp connection through port 5000.

Hi,

Thanks for the response, unfortunately I already tried to implement it via a fdMonitor but it give me the same error(s) when calling the recv functionallity:
either:

  • Errno -1: Operation not permitted
  • Errno -11: Unknown error

I discovered that when I use the flag MSG_DONTWAIT in the recv function that I get the errors as described above. But when I just set the flag to 0 than I can receive data without a problem. However I want a non-blocking socket, so I want to use the flag MSG_DONTWAIT.

Anyone encountered this problem before?

You can use my TCP echo server application which uses read() instead of recv().
Procedure:

  1. compile and download attached application
  2. iptables -I INPUT -j ACCEPT
  3. app start fwupdateDownloader
  4. in Linux PC, type “nc 192.168.2.2 5000”
  5. after connected, you can type some characters and the application will echo back to linux PC.

fwupdateDownloader.rar (174.0 KB)

Thanks for the code.
I got both up and running, even my code with the recv() function.

The error handler got the return value of the recv mixed up with the result from errno:
recv returns -1 when an error occurs (or 0 when clients disconnect), the actual error must be read via errno.

Small mistake which is easily overlooked and can cause some weird behavior.