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.
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;
}
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.
Is the code you wrote running as a Legato app? If it is, have you tried setting sandboxed: false in your application definition file (.adef)? Obviously this isn’t an ideal solution, but it will let you know whether Legato’s sandboxing is the source of the issue.
Thanks for the response,
Totally forgot about this topic, because I already fixed it.
Small error on my part;
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.