:: Re: [DNG] Unix Socket class: how to…
Top Page
Delete this message
Reply to this message
Author: aitor_czr
Date:  
To: dng
Subject: Re: [DNG] Unix Socket class: how to send arguments to the suid of simple-netaid
Hi again,

On 10/9/19 11:45, aitor_czr wrote:
>
> Hi all,
>
> Here you are an example of the unix socket class used in simple-netaid
> for sending the arguments
> to the suid binary through a file descriptor instead of using
> arguments in the command line:
>
> http://gnuinos.org/socket/socket-class-example/
>
> You'll need to install libglibmm-2.4-dev for the server of the socket
> (It's multithreaded and uses a
> Glib::Threads::Thread *thread pointer).
>
> As you can see in the example (have a look at the main.cpp of the
> server), the constructor of the
> serverSocket class receives the name of the file descriptor as a first
> argument:
>
> serverSocket sender( FILE_DESCRIPTOR, std::string... );
>
> The rest of the arguments in the constructor are the values of the
> arguments sent by the socket,
> and both the quantity and the length of these strings are unlimited.
> The client side of the socket
> class will use a std::vector<std::string> for the received
> arguments(look at the main.cpp of the
> server).
>
> After building the example (use the Makefile for that), just run the
> server in a secondary plane:
>
> $ ./server &
> [1] 10739
>
> It may then run the client, getting all the received mesages:
>
> $ ./client
> These are the received messages:
>     0
>     Hi
>     hello
>     folks
> [1]+  Hecho                   ./server
>
> You can download the tarball of the example from here:
>
> wget http://gnuinos.org/socket/socket_class_example.tar.gz
>
> Cheers,
>
> Aitor.
>

Maybe you are wondering about the reaseon why the server of the socket
should be multithreaded.
Well... Download the following example:

http://gnuinos.org/socket/ip/

The code of the server has been replaced by:

serverSocket( { FILE_DESCRIPTOR, "0", "wlan0" } );
system("sudo ./client");

That is, the information is sent through the file descriptor and
immediatly after the client is run *while*
the server is waiting to be heard in a separate thread.

Just run:

$ ./server

and your network interface (wlan0) will be brung down.

Cheers,

Aitor.