Recent

Author Topic: Raspberry and network library  (Read 2771 times)

ilserver

  • Newbie
  • Posts: 3
Raspberry and network library
« on: January 15, 2018, 12:13:27 am »
Greeting to all,
i try to use synapse 4 lib in raspberry pi3 without success.
More precisely I am try to send a ping to an host but seems that this simple task is not possible.
Sendping gime me no error but simply host is not reach.
Now my question is: is my fault or simply synapse don't work with pi3?

And if ther is no hope to get synapse work, is there another free network lib that work with pi?

Thanks at all and forgive me for my poor english...
 

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Raspberry and network library
« Reply #1 on: January 15, 2018, 07:15:26 am »
Full example with synapse on the Raspberry Pi:
Code: Pascal  [Select][+][-]
  1. program pingme;
  2. {$ifdef windows}{$apptype console}{$endif}
  3. {$ifdef fpc}{$mode delphi}{$H+}{$I-}{$endif}
  4. uses {$ifdef unix}cthreads,{$endif}sysutils,pingsend;
  5. var i:integer;
  6. begin
  7.   for i := 1 to 5 do
  8.   begin
  9.     writeln(PingHost('http:/www.thaddy.com')); // this is my own server and ping is allowed
  10.     writeln(PingHost('thaddy.com')); // this is my own server and ping is allowed
  11.   end;
  12. end.

Compile, then sudo ./pingme
Code: Bash  [Select][+][-]
  1. pi@thaddy_rpi3_1:~/synapse $ sudo ./pingme
  2. 14
  3. 22
  4. 11
  5. 16
  6. 13
  7. 13
  8. 11
  9. 11
  10. 11
  11. 17

If that works - it does work as you can see - you can elevate the rights permanently by performing:
Code: Bash  [Select][+][-]
  1. sudo chown root:root /path/to/pingme
  2. sudo chmod 4755 /path/to/pingme

This is officially not recommended! As you can see on the screenshot the app runs now with root rights.
Code: Bash  [Select][+][-]
  1. pi@thaddy_rpi3_1:~/synapse $ ./pingme
  2. 15
  3. 11
  4. 13
  5. 13
  6. 11
  7. 12
  8. 11
  9. 11
  10. 13
  11. 15
« Last Edit: January 15, 2018, 08:44:44 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Lutz Mändle

  • Jr. Member
  • **
  • Posts: 65
Re: Raspberry and network library
« Reply #2 on: January 15, 2018, 09:39:19 am »
The official way to elevate privileges is to use file capabilities, which has to be supported by the filesystem and the kernel. Actual linux distros (OpenSuse, Debian, ArchLinux) have this support. Read the man pages for getcap and setcap. Reading the file capabilities of the ping binary gives the following output:

[root@odroid-logger:~]# getcap `which ping`
/usr/bin/ping = cap_net_raw+ep

To set the capabilities of an own binary to the above read values run the setcap utility in this way:

setcap cap_net_raw+ep <my binary>

ilserver

  • Newbie
  • Posts: 3
Re: Raspberry and network library
« Reply #3 on: January 15, 2018, 09:42:15 am »
Hi Thaddy,
my fault is that I ran my app whithout sudo.
Probably synapse need high privileges to gain access low level function tu use networking...

Thank a lot for your suggest.

ilserver

  • Newbie
  • Posts: 3
Re: Raspberry and network library
« Reply #4 on: January 15, 2018, 09:43:55 am »
thanks Lutz,
i'll try also this...

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Raspberry and network library
« Reply #5 on: January 15, 2018, 10:33:40 am »
The official way to elevate privileges is to use file capabilities, which has to be supported by the filesystem and the kernel. Actual linux distros (OpenSuse, Debian, ArchLinux) have this support. Read the man pages for getcap and setcap. Reading the file capabilities of the ping binary gives the following output:

[root@odroid-logger:~]# getcap `which ping`
/usr/bin/ping = cap_net_raw+ep

To set the capabilities of an own binary to the above read values run the setcap utility in this way:

setcap cap_net_raw+ep <my binary>

It is the modern way and recommended way if available. Not every distro supports it and on Raspbian it is available but not used by default.  E.g. getcap /bin/ping reports nothing, but your solution works at least on Raspbian with systemd, Stretch.
But indeed your solution is preferred when it is available.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Lutz Mändle

  • Jr. Member
  • **
  • Posts: 65
Re: Raspberry and network library
« Reply #6 on: January 15, 2018, 11:22:54 am »
I have my Raspberries running with ArchLinux, therefore I have no experience with Raspbian, but Debian supports it at least from Debian 8 on. As I wrote the support depends on the filesystem and the kernel config. The needed config options for ext4 are:

CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_EXT4_FS_SECURITY=y

I stumbled in this issue shortly as I've set up an odroid-c2 with ArchLinux and a self baked 4.14.xx kernel with a configuration derived from make defconfig. The device was running fine (of course without HDMI output) but ping fails as ordinary user. Asking the capabilities with getcap gave "operation not supported" message, wat nu?
After reading about the prerequisites to use this feature I was looking first at the filesystem with tune2fs, what I've found was ok. Then I've compared the kernel config with the config used by the standard kernel of ArchLinux for Raspberry. That was revealing that make defconfig was not setting CONFIG_EXT4_FS_SECURITY. After enabling this option and recompiling the kernel it was working.

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Raspberry and network library
« Reply #7 on: January 15, 2018, 12:02:02 pm »
Well, it works on Raspbian Jessie (But not on Raspbian Wheezy it seems) out-of the box when used on your own compiled software. But the provided binaries in /bin do not yet use it.
Re-compiling a kernel is not an option for an average Raspberry Pi user. (although it is not difficult)
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018