0

I am writing a C backup program for my Majaro Linux. It must backup files at a certain time in my home local server only if I am connecting to my home network. So I need to get an SSID and a MAC address a current network to decide if it is my network or not.

Is there Linux(Arch) default commands, C library functions or files, contain this information?

I already tried some Linux tools, ifconfig for example, but it is useless for me.

Help!

moinmaroofi
  • 359
  • 1
  • 12
Mihail HRS
  • 115
  • 1
  • 1
  • 9
  • maybe libpcap library helps to get some information about your network in c program. – moinmaroofi Jun 16 '19 at 14:03
  • 1
    you might want to take a look at: https://stackoverflow.com/a/19733653/2331445 – Stephan Schlecht Jun 16 '19 at 14:05
  • This is really a linux question, not a C question. What you want are linux libraries that vend that data. Link to those libraries in your C code, and you're good. Here's one example: https://stackoverflow.com/questions/1779715/how-to-get-mac-address-of-your-machine-using-a-c-program – Blunt Jackson Jun 16 '19 at 14:25
  • 1
    [This](https://github.com/bmegli/wifi-scan) is a good implementation of a wifi-scanner that might be of interested for you. – Iliya Iliev Jun 16 '19 at 16:40

1 Answers1

1

Done

Thank you all for your help, especially to Iliya Iliev and to this library. It works perfectly.

It exactly what I've been searching for!

I just add it to my main project.

#include "../wifi_scan.h"
#include <stdio.h>  
#include <unistd.h> 

const char *bssid_to_string(const uint8_t bssid[BSSID_LENGTH], char  bssid_string[BSSID_STRING_LENGTH])
    {
        snprintf(bssid_string, BSSID_STRING_LENGTH, "%02x:%02x:%02x:%02x:%02x:%02x",
             bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
        printf("%x\n", bssid[5]);
        return bssid_string;
    }

    int main(int argc, char **argv){

        struct wifi_scan *wifi=NULL;
        struct station_info station;
        char mac[BSSID_STRING_LENGTH]; 

        wifi=wifi_scan_init(argv[1]);
        wifi_scan_station(wifi, &station);

        printf("ssid = %s mac = %s \n", station.ssid, bssid_to_string(station.bssid, mac));

        wifi_scan_close(wifi);

    }
Mihail HRS
  • 115
  • 1
  • 1
  • 9