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 13.

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)

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:

This code works with telnet on the host system as a client. Note I am using POSIX threads. My platform is the same as yours, WP7700, FW, Legato. Nothing in .adef or .cdef for the socket. However the TCP read thread uses wait (i.e. 4th param is 0) on the call to recv().

void * SocketListen(void * args)
{
struct sockaddr addr;
struct sockaddr_in *addr_in_p = (struct sockaddr_in *) &addr;
socklen_t addr_size = sizeof(addr);
MsgStruct listenMsg = {CONN_CONFIRM, “\n”, “”};
int csock;
int lsock;
int rc;
// Make a socket
lsock = socket(AF_INET, SOCK_STREAM, 0);
if ( lsock == -1 )
{…}
memset((char *) addr_in_p, 0, addr_size);
addr_in_p->sin_family = AF_INET;
addr_in_p->sin_port = htons(LISTEN_PORT);
addr_in_p->sin_addr.s_addr = htonl(INADDR_ANY);
rc = bind(lsock, &addr, addr_size);
if ( rc != 0 )
{…}
rc = listen(lsock, MAX_ENQUEUED);
if ( rc != 0 )
{…}
// wait for connections
while (TRUE)
{
LE_INFO(“Wait for incoming connection, socket=%d”, lsock);
csock = accept(lsock, &addr, &addr_size);
if ( csock < 0 )
{…}
char *ip = inet_ntoa(addr_in_p->sin_addr);
printf(“Incoming connection from: %s, csock=%d \n”, ip, csock);
WriteUart(SerialFD, (char *) &listenMsg, sizeof(listenMsg));
// save socket value
Sock = csock;
// start tcp reader and writer threads…(code omitted)
}
// never gets here
return NULL;
}

Thanks for the response pinst!

Unfortunately it still does not resolve my issue.
Some further reading also suggests that my code should work. I’ve tested other examples but those also return ernno -1 (Operation not permitted) error upon using recv.

Any other suggestions?