:: Re: [DNG] simple-netaid-backend deb…
Top Page
Delete this message
Reply to this message
Author: aitor_czr
Date:  
To: dng
Subject: Re: [DNG] simple-netaid-backend debugged.
Hi,

On 17/3/19 13:38, aitor_czr wrote:
>
> Hi Eward,
>
> On 7/3/19 8:38, Edward Bartolo <edbarx@???> via Dng wrote:
>> Hi Everyone,
>>
>> My version of simple-netaid-backend has been debugged to connect when
>> there is only one active wifi hotspot. It was previously failing to
>> connect because there was an error in a while loop which prevented
>> iteration from taking place when there was only one active wifi
>> hotspot.
>>
>> Please, note my graphical frontend does not use unnecessary cosmetics
>> to make it look appealing to the eyes. My aim was simplicity and low
>> use of system processing and memory. Moreover, the backend
>> establishes a connection using low level calls to avoid using
>> ifupdown. It uses instead ifconfig, iwconfig, wpa_supplicant and
>> dhclient.
> I'm working again on simple-netaid, and i 'd like to share with you
> the C code
>
> for bringing up/down a concrete network interface (void
> interface_up/down, respectivelly):
>
>
>
> /********         Bring up the interface                      *******/
>
> void interface_up (const char *if_name)
>
> {
>     struct ifreq ifr;
>     int skfd = 0;
>
>     strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
>
>     /* Create a channel to the NET kernel. */
>     if((skfd = iw_sockets_open()) < 0)
>     {
>         perror("socket");
>         return -1;
>     }
>
>     skfd = socket (AF_INET, SOCK_DGRAM, 0);
>     if (skfd && ioctl(skfd, SIOCGIFFLAGS, &ifr) >= 0) {
>         printf("Activating interface %s", if_name);
>         strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
>         ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
>         ioctl(skfd, SIOCSIFFLAGS, &ifr);
>     } else {
>         printf("Getting flags for interface %s failed, not activating
> interface.", if_name);
>     }
>
>     /* Close the socket. */
>     iw_sockets_close(skfd);
>
> }
>
>
> /********         Bring down the interface                      *******/
>
> void interface_down (const char *if_name)
> {
>     struct ifreq ifr;
>     int skfd = 0;
>
>     strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
>
>     /* Create a channel to the NET kernel. */
>     if((skfd = iw_sockets_open()) < 0)
>     {
>         perror("socket");
>         return -1;
>     }
>
>     if (skfd && ioctl(skfd, SIOCGIFFLAGS, &ifr) >= 0) {
>         printf("Taking down interface %s", if_name);
>         strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
>         ifr.ifr_flags &= ~IFF_UP;
>         ioctl(skfd, SIOCSIFFLAGS, &ifr);
>     } else {
>         printf("Getting flags for interface %s failed, not taking down
> interface.", if_name);
>     }
>
>     /* Close the socket. */
>     iw_sockets_close(skfd);
> }
>
> HTH,
>
> Aitor.
>

I took the code from debian-installer, more concretly from the netcfg
udeb package.

Aitor.