RaspberryPi TCP port 502

1,380 views
Skip to first unread message

Peter Axelsson

unread,
Nov 25, 2013, 12:26:33 PM11/25/13
to libm...@googlegroups.com

Found a nice example and got it working on port 1502 (and some other ports above 1023).

Trying to run it on 502 as it should be but I immediately get the “TCP Connection started” message but my client doesn’t connect.

 

Any ideas?

 

    if (use_backend == TCP) {

        printf("Waiting for TCP connection on Port %i \n",nPort);

        ctx = modbus_new_tcp("127.0.0.1", nPort);

        socket = modbus_tcp_listen(ctx, 1);

        modbus_tcp_accept(ctx, &socket);

        printf("TCP connection started!\n");

    } else {

 

Josep L. Guallar-Esteve

unread,
Nov 25, 2013, 1:08:12 PM11/25/13
to libm...@googlegroups.com
Is there any firewall enabled between both client and server devices?

Is the server running with full permissions? In Windows, that would be "Administrator", in Unix-like, that would be "root".

Regards,
Josep

Peter Axelsson

unread,
Nov 25, 2013, 3:58:52 PM11/25/13
to libm...@googlegroups.com
Oops! Started it with sudo, worked fine.
Sorry for disturbing...
0-1023 is only for root?

/P

Josep L. Guallar-Esteve

unread,
Nov 25, 2013, 4:59:21 PM11/25/13
to libm...@googlegroups.com
Not really.

Ports 0-1024 are "protected" for "known" services. Check the /etc/services file on any Unix system (not sure if it's there on a RPi Linux distro).

By "protected", they must be used by system  daemons. Thus, a regular user cannot (should not be able to ) start them.

Best of luck,
Josep

Julien Blanc

unread,
Nov 26, 2013, 3:17:22 AM11/26/13
to libm...@googlegroups.com
Le 25/11/2013 22:59, Josep L. Guallar-Esteve a �crit :
> Not really.
>
> Ports 0-1024 are "protected" for "known" services. Check the
> /etc/services file on any Unix system (not sure if it's there on a RPi
> Linux distro).
>
> By "protected", they must be used by system daemons. Thus, a regular
> user cannot (should not be able to ) start them.
>
There are two ways for a � user � process to open ports less than 1024 :

- either you use setcap to give this specific program explicit
permission to open ports less than 1024
- either you launch the program as root, create the server socket as
root, and then the program impersonate itself using a setuid call
(usually, impersonification to a special user created for running the
service, in old times most services used nobody).

AFAIK, nearly all services uses the second way (since init scripts are
run by root, impersonification is needed anyway).

There�s also a third way of doing things : creating a local port
forwarding rule forwarding port 502 to port 1502.

Regards,
Julien

Louis Loizides

unread,
Jan 19, 2014, 3:02:30 PM1/19/14
to libm...@googlegroups.com
I've got it running on an RPi on port 502. But isn't 127.0.0.1 the localhost? Are you trying to connect to yourself?
Reply all
Reply to author
Forward
0 new messages