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

**URL:** <https://forum.legato.io/t/networking-tcp-server-operation-not-permitted-errno-1/4650>\
**Category:** Uncategorized\
**Created:** [August 26, 2019, 7:46am UTC](https://forum.legato.io/t/networking-tcp-server-operation-not-permitted-errno-1/4650 "2019-08-26T07:46:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BCUbing](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@BCUbing](https://forum.legato.io/u/BCUbing)\
**Post date:** [August 26, 2019, 7:46am UTC](https://forum.legato.io/t/networking-tcp-server-operation-not-permitted-errno-1/4650/1 "2019-08-26T07:46:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [August 26, 2019, 10:09am UTC](https://forum.legato.io/t/networking-tcp-server-operation-not-permitted-errno-1/4650/2 "2019-08-26T10:09:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BCUbing](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@BCUbing](https://forum.legato.io/u/BCUbing)\
**Post date:** [August 27, 2019, 1:37pm UTC](https://forum.legato.io/t/networking-tcp-server-operation-not-permitted-errno-1/4650/3 "2019-08-27T13:37:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [August 28, 2019, 1:58am UTC](https://forum.legato.io/t/networking-tcp-server-operation-not-permitted-errno-1/4650/4 "2019-08-28T01:58:01Z")

</div>

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](https://forum.legato.io/uploads/short-url/rtNMsZzuYC3CC0QmrsWh0EfadIR.rar) (174.0 KB)

---

<div class="post-metadata">

**Author:** ![BCUbing](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@BCUbing](https://forum.legato.io/u/BCUbing)\
**Post date:** [August 28, 2019, 11:56am UTC](https://forum.legato.io/t/networking-tcp-server-operation-not-permitted-errno-1/4650/5 "2019-08-28T11:56:36Z")

</div>

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.
