From dfaea22ade894f915babe28086aad2b6378624d4 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph <johannes.rudolph@gmx.com> Date: Fri, 4 Mar 2016 13:28:03 +0100 Subject: [PATCH] finish function --- libwlocate/src/getbssid.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libwlocate/src/getbssid.c b/libwlocate/src/getbssid.c index a96ab62..6d1bd5a 100644 --- a/libwlocate/src/getbssid.c +++ b/libwlocate/src/getbssid.c @@ -1,7 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <regex.h> +#include <regex.h> /* The following is the size of a buffer to contain any error messages encountered when the regular expression is compiled. */ @@ -132,19 +132,32 @@ int * getMeshBssid (){ fclose(f); string[fsize] = 0; - printf("%s",string); compile_regex(& r, regex_text); result = match_regex(& r, string); regfree (& r); - printf("\n%s\n",result); + char * str = strdup(result); + + char* tok; + tok = strtok(str, ":"); + + int number = (int)strtol(tok, NULL, 16); + bssid[0] = number; + for(int i = 1 ; i < 6 ; i++){ + tok = strtok(NULL, ":"); + int number = (int)strtol(tok, NULL, 16); + bssid[i] = number; + } return bssid; } int main (int argc, const char * argv[]) { - getMeshBssid(); + int* bssid = getMeshBssid(); + for(int i = 0; i < 6; i++){ + printf("%02x\n", bssid[i]); + } } \ No newline at end of file -- GitLab