This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM335x network server error

Hi All,


I am working with BeagleBone black with yocto build system. 

I have created my custom yocto build and ported successfully on beagle bone black and tested ok.

I want to run network server application which can use standard port number (0-1024) ,So my server application is binding IP_address and Port number and listen on socket for client.

I am login in Beaglebone black as root and when i start my server then it shows below error,

"could not bind "0.0.0.0" port <Any Standard Port(0-1024)> (Permission denied)"

To verify it , i have checked my application on pc and when i run it as root user then it allow me to bind my IP_address with standard Port Number (0-1024)

Kindly suggest us in this matter.

Thanks

Dhaval

  • Hi,

    What server application is this?
  • Hi,

    It is a simple echo server application based on C language as below.

    #include <stdio.h>
    #include <errno.h>
    #include <sys/socket.h>
    #include <resolv.h>
    #include <arpa/inet.h>
    #include <errno.h>

    #define MAXBUF 1024

    /*
    * usage:./a.out <IP_ADDRESS> <PORT_NUMBER>
    */
    int main(int argc, char **argv)
    { int sockfd;
    struct sockaddr_in self;
    char buffer[MAXBUF];


    /*---Create streaming socket---*/
    if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
    {
    perror("Socket");
    exit(errno);
    }

    /*---Initialize address/port structure---*/
    bzero(&self, sizeof(self));
    self.sin_family = AF_INET;
    self.sin_port = htons(atoi(argv[2]));
    self.sin_addr.s_addr = INADDR_ANY;

    /*---Assign a port number to the socket---*/
    if ( bind(sockfd, (struct sockaddr*)&self, sizeof(self)) != 0 )
    {
    perror("socket--bind");
    exit(errno);
    }

    /*---Make it a "listening socket"---*/
    if ( listen(sockfd, 20) != 0 )
    {
    perror("socket--listen");
    exit(errno);
    }

    /*---Forever... ---*/
    while (1)
    { int clientfd;
    struct sockaddr_in client_addr;
    int addrlen=sizeof(client_addr);

    /*---accept a connection (creating a data pipe)---*/
    clientfd = accept(sockfd, (struct sockaddr*)&client_addr, &addrlen);
    printf("%s:%d connected\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));

    /*---Echo back anything sent---*/
    send(clientfd, buffer, recv(clientfd, buffer, MAXBUF, 0), 0);

    /*---Close data connection---*/
    close(clientfd);
    }

    /*---Clean up (should never get here!)---*/
    close(sockfd);
    return 0;
    }
  • Hello Dhaval,

    The standard ports 0-1024 in Linux requires root privileges. To run this program on your BBB either use root account or use a port number between 1024-65535. I can run this example on latest PSDK with no issues.

    Best regards,
    Kemal

  • Hi  Kemal,

    Thanks for reply.

    Yes you are correct that root privileges is require for standard port ( 0 -1024).

    However when i run whoami command i got this output,

    root@beaglebone:~# whoami

    root

    root@beaglebone:~#

    Also for below command,

    root@beaglebone:~# cat /etc/passwd |grep "/home" |cut -d: -f1
    root
    root@beaglebone:~#

    So i logged as root user.

    And I want also run  my application using standard port 0-1024 so how can resolve this error ?

    Kindly suggest.

    Thanks,

    Dhaval

  • Could you post the output of id command?

  • Hi Kemal,

    When i run my server program on board then i got below error  for standard port (0-1024),

    root@beaglebone:~# ./server 10.99.19.82 123

    socket--bind: Permission denied

    But when i run it for non standard port (>1024) then it do not give any error.

    root@beaglebone:~# ./server 10.99.19.82 1234

    root@beaglebone:~#

     

    Kindly suggest us in this matter.

    Thanks,

    Dhaval

  • Could you type this command:
    root@beaglebone:~# id
    uid=0(root) gid=0(root) groups=0(root)
    and check if this your current account is really a root account?

  • Hi Kemal,

    root@beaglebone:~# id

    uid=0(root) gid=0(root) groups=0(root)

    we get the above result and our account is a root account but we can access the standard ports(0-1024) as a root account. So, the i want to access this ports. so, please suggest.

  • I would suggest you to install the mentioned packages in this thread:
    e2e.ti.com/.../1698699

    and try with the sudo command:
    root@beaglebone:~# sudo ./server 10.99.19.82 123

    https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/791/pam_2D00_plugin_2D00_keyinit_5F00_1.1.6_2D00_r5_5F00_cortexa8hf_2D00_vfp_2D00_neon.ipk https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/791/sudo_5F00_1.8.11p2_2D00_r0_5F00_cortexa8hf_2D00_vfp_2D00_neon.ipk