[Solved]Open socket in a sandbox

Hello,

I am trying to open a new socket on port 102 in a sandbox, but can’t get it to work. Here is a codesnippet:

ServerSocket
TcpServerSocket_create(const char* address, int port)
{
    ServerSocket serverSocket = NULL;

    int fd;

    if ((fd = socket(AF_INET, SOCK_STREAM, 0)) >= 0) {
        struct sockaddr_in serverAddress;

        if (!prepareServerAddress(address, port, &serverAddress)) {
            close(fd);
            return NULL;
        }

        int optionReuseAddr = 1;
        setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &optionReuseAddr, sizeof(int));

        if (bind(fd, (struct sockaddr *) &serverAddress, sizeof(serverAddress)) >= 0) {
            serverSocket = GLOBAL_MALLOC(sizeof(struct sServerSocket));
            serverSocket->fd = fd;
            serverSocket->backLog = 0;

            setSocketNonBlocking((Socket) serverSocket);
        }
        else {
            close(fd);
            return NULL ;
        }

#if CONFIG_ACTIVATE_TCP_KEEPALIVE == 1
        activateKeepAlive(fd);
#endif
    }

    return serverSocket;
}

No problem to start this without a sandbox, but in a sandbox, the call to bind failes. Is there any chance to open a socket in a sandbox in legato?

Thanks

Okay… a sandbox is not running as root… good… and that is the reason, why I can’t bind a socket to port 102. Has to be above 1024 as a non root user. See c - Socket programing Permission denied - Stack Overflow

Have a nice day!