:: Re: [DNG] netman GIT project
トップ ページ
このメッセージを削除
このメッセージに返信
著者: Edward Bartolo
日付:  
To: Tilman Kranz, dng
題目: Re: [DNG] netman GIT project
Oooops, forgot the attachment! Here it is.

On 27/08/2015, Edward Bartolo <edbarx@???> wrote:
> I am trying to write a C function to start the wired network
> interfaces eth0, eth1 up to eth2. This is how I wrote it, but I would
> like your opinion about it especially where I should declare err.
>
> The attachment is best viewed with medit with a tab space of 2.
>
>
> On 27/08/2015, Edward Bartolo <edbarx@???> wrote:
>> I don't think it is necessary to daemonise the backend as connection
>> to and disconnecting from a network is not something that is done
>> continuously. Therefore, in my humble opinion, running the backend on
>> request seems to be the best approach. This also avoids additional
>> complexity of requiring a dedicated init script. An SUID belonging to
>> root is enough for the backend to be allowed privileges automatically
>> whenever it is invoked. This means, the post installation script will
>> only need to "chmod u+s backend" and create a launcher on user
>> request.
>>
>> I will now test an installation to /usr/bin of both backend and
>> frontend using an SUID for the backend. If everthing goes well, it
>> would mean, the time for an ALPHA release of a .deb package for
>> netman, is possible now.
>>
>> I included more functionality in the frontend to recognise the
>> existence of an /etc/network/interfaces displaying and option to
>> connect to eth0 if that is found. I also included a compiler
>> conditional directive to compile the frontend so as to bypass the
>> requirement of sudo.
>>
>> When I am ready, and I think the project can be package, I will upload
>> to git.devuan.org
>>
>>
>> Edward
>>
>> On 26/08/2015, Isaac Dunham <ibid.ag@???> wrote:
>>> On Wed, Aug 26, 2015 at 02:27:57PM +0200, tilt! wrote:
>>>> On 08/26/2015 01:36 PM, Irrwahn wrote:
>>>> >[...]
>>>> >Or, even better, you could easily pass the IF name as an additional
>>>> >parameter to the backend (and possily even use it as additional
>>>> > component
>>>> >to construct the interface file names).
>>>>
>>>> An easy way to obtain a list of interface names on Linux is:
>>>>
>>>> awk 'NR>2{gsub(/:/,"");print $1}' /proc/net/dev
>>>
>>> Or "ls /sys/class/net".
>>> For listing non-loopback devices only, use
>>> ls -d /sys/class/net/*/device | cut -d/ -f5
>>>
>>> For wireless, check for the files "phy80211" or "wireless".
>>>
>>> The equivalent can be done trivially in C with readdir(); ask if you'd
>>> like
>>> an example.
>>>
>>> HTH,
>>> Isaac Dunham
>>> _______________________________________________
>>> Dng mailing list
>>> Dng@???
>>> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
>>>
>>
>

int connectWired(
    const char * ethx
) {
    int err;
    int valid_eth = 0;
    if (strcmp("eth0", ethx) == 0 || strcmp("eth1", ethx) == 0 || strcmp("eth2", ethx) == 0)
        valid_eth = 1;

        
    if (!valid_eth) {
        fprintf(stderr, "ERROR: only eth0, eth1 and eth2 are allowed; err=%d\n", err);


        return err;
    }

        
    err = execl("/sbin/ifup ", ethx, "-i", "/etc/network/interfaces", char * NULL)

    
    fprintf(
        stderr, 
        "ERROR: connectWired(): "
        "\"/sbin/ifup %s -i /etc/network.interfaces\" failed; err=%d\n",
        ethx, err
    );

            
    return err;
}