mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2024-11-21 19:40:11 +00:00
commit
6e283d5f2d
@ -4,9 +4,8 @@
|
||||
[![Gitter](https://badges.gitter.im/linux-wihotspot/community.svg)](https://gitter.im/linux-wihotspot/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
|
||||
### Update
|
||||
* Config files are wriiten to /etc/wh.config (Previously, configurations were wriiten to home directory as `.wh.config`).
|
||||
* `.desktop` file is added. So You can start from app launcher
|
||||
* Use `make` to build instead of `cmake`
|
||||
* Add MAC filter
|
||||
* Release Debian package
|
||||
|
||||
### Features
|
||||
|
||||
@ -32,7 +31,7 @@ If any problems with **RealTeK Wifi Adapters** see [this](docs/howto/realtek.md)
|
||||
|
||||
#### Debian/Ubuntu
|
||||
Download the debian package from latest [release](https://github.com/lakinduakash/linux-wifi-hotspot/releases/latest)
|
||||
- [linux-wifi-hotspot_3.1.2_amd64.deb](https://github.com/lakinduakash/linux-wifi-hotspot/releases/download/v3.1.2/linux-wifi-hotspot_3.1.2_amd64.deb)
|
||||
- [linux-wifi-hotspot_3.2.0_amd64.deb](https://github.com/lakinduakash/linux-wifi-hotspot/releases/download/v3.2.0/linux-wifi-hotspot_3.2.0_amd64.deb)
|
||||
|
||||
#### Arch based distributions
|
||||
|
||||
|
2
debian/changelog
vendored
2
debian/changelog
vendored
@ -1,4 +1,4 @@
|
||||
linux-wifi-hotspot (3.1.2) UNRELEASED; urgency=low
|
||||
linux-wifi-hotspot (3.2.0) UNRELEASED; urgency=low
|
||||
|
||||
* Initial release.
|
||||
|
||||
|
BIN
docs/sc1-old.png
Normal file
BIN
docs/sc1-old.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
BIN
docs/sc1.png
BIN
docs/sc1.png
Binary file not shown.
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 84 KiB |
BIN
docs/sc2-old.png
Normal file
BIN
docs/sc2-old.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 222 KiB |
BIN
docs/sc2.png
BIN
docs/sc2.png
Binary file not shown.
Before Width: | Height: | Size: 222 KiB After Width: | Height: | Size: 245 KiB |
@ -17,6 +17,11 @@ button:active {
|
||||
border-color: #ff6a6b;
|
||||
}
|
||||
|
||||
.tv-mac-error{
|
||||
border-color: #ff6a6b;
|
||||
color: #ff3f4e;
|
||||
}
|
||||
|
||||
.label-error{
|
||||
color: #ff3f4e;
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<!-- Generated with glade 3.22.2 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkApplicationWindow" id="window">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">Wi Hotspot</property>
|
||||
<child>
|
||||
<child type="titlebar">
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
@ -216,8 +216,7 @@
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="row_spacing">5</property>
|
||||
<property name="row_homogeneous">True</property>
|
||||
<property name="row_spacing">10</property>
|
||||
<property name="column_homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="cb_hidden">
|
||||
@ -362,6 +361,48 @@
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="cb_mac_filter">
|
||||
<property name="label" translatable="yes">Mac Filter</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTextView" id="tv_mac_filter">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="accepts_tab">False</property>
|
||||
<property name="input_hints">GTK_INPUT_HINT_UPPERCASE_CHARS | GTK_INPUT_HINT_NONE</property>
|
||||
<property name="monospace">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">6</property>
|
||||
<property name="height">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
|
@ -37,7 +37,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "read_config.h"
|
||||
|
||||
|
||||
#define BUFSIZE 512
|
||||
#define BUFSIZE 1024
|
||||
|
||||
|
||||
#define SUDO "pkexec --user root"
|
||||
@ -52,10 +52,12 @@ char cmd_start[BUFSIZE];
|
||||
char cmd_mkconfig[BUFSIZE];
|
||||
char cmd_config[BUFSIZE];
|
||||
char cmd_kill[BUFSIZE];
|
||||
char cmd_write_mac[BUFSIZE];
|
||||
|
||||
char h_running_info[BUFSIZE];
|
||||
char interface_list[BUFSIZE];
|
||||
char wifi_interface_list[BUFSIZE];
|
||||
char accepted_macs[BUFSIZE];
|
||||
|
||||
const char* g_ssid=NULL;
|
||||
const char* g_pass=NULL;
|
||||
@ -125,6 +127,12 @@ const char *build_wh_mkconfig_command(ConfigValues* cv){
|
||||
strcat(cmd_mkconfig, cv->mac);
|
||||
}
|
||||
|
||||
if(cv->mac_filter!=NULL && (strcmp(cv->mac_filter,"1") == 0)){
|
||||
strcat(cmd_mkconfig, " --mac-filter ");
|
||||
strcat(cmd_mkconfig, cv->mac_filter);
|
||||
write_accepted_macs(cv->accepted_mac_file,cv->accepted_macs);
|
||||
}
|
||||
|
||||
printf("%s \n",cmd_mkconfig);
|
||||
return cmd_mkconfig;
|
||||
|
||||
@ -147,6 +155,36 @@ const char* build_kill_create_ap_command(char* pid){
|
||||
return cmd_kill;
|
||||
}
|
||||
|
||||
void write_accepted_macs(char* filename, char* accepted_macs){
|
||||
|
||||
printf("%s \n",filename);
|
||||
printf("%s \n",accepted_macs);
|
||||
|
||||
snprintf(cmd_write_mac,BUFSIZE,"%s '%s' %s %s","echo", accepted_macs, "| sudo tee", filename);
|
||||
int r=system(cmd_write_mac);
|
||||
|
||||
}
|
||||
|
||||
char * read_mac_filter_file(char * filename){
|
||||
|
||||
char ch;
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen(filename, "r"); // read mode
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
perror("Error while opening the file.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while((ch = (char)fgetc(fp)) != EOF)
|
||||
strcat(accepted_macs, &ch);
|
||||
|
||||
fclose(fp);
|
||||
return accepted_macs;
|
||||
}
|
||||
|
||||
//int write_config(char* file){
|
||||
//
|
||||
// config_t cfg;
|
||||
|
@ -55,4 +55,8 @@ const char *build_wh_mkconfig_command(ConfigValues* cv);
|
||||
|
||||
char** get_wifi_interface_list(int *length);
|
||||
|
||||
void write_accepted_macs(char* filename, char* accepted_macs);
|
||||
|
||||
char * read_mac_filter_file(char * filename);
|
||||
|
||||
#endif //WIHOTSPOT_H_PROP_H
|
||||
|
@ -116,6 +116,12 @@ static void setConfigValues(const char * key, char *value){
|
||||
if( !strcmp ( USE_PSK, key ))
|
||||
configValues.use_psk = value;
|
||||
|
||||
if( !strcmp ( MAC_FILTER, key ))
|
||||
configValues.mac_filter = value;
|
||||
|
||||
if( !strcmp ( MAC_FILTER_ACCEP, key ))
|
||||
configValues.accepted_mac_file = value;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,6 +85,9 @@ typedef struct{
|
||||
char *freq;
|
||||
char *hidden;
|
||||
char *mac;
|
||||
char *mac_filter;
|
||||
char *accepted_mac_file;
|
||||
char *accepted_macs;
|
||||
} ConfigValues;
|
||||
|
||||
|
||||
|
124
src/ui/ui.c
124
src/ui/ui.c
@ -60,6 +60,9 @@ GtkEntry *entry_ssd;
|
||||
GtkEntry *entry_pass;
|
||||
GtkEntry *entry_mac;
|
||||
GtkEntry *entry_channel;
|
||||
GtkTextView *tv_mac_filter;
|
||||
|
||||
GtkTextBuffer *buffer_mac_filter;
|
||||
|
||||
GtkComboBox *combo_wifi;
|
||||
GtkComboBox *combo_internet;
|
||||
@ -74,6 +77,7 @@ GtkCheckButton *cb_mac;
|
||||
GtkCheckButton *cb_novirt;
|
||||
GtkCheckButton *cb_channel;
|
||||
GtkCheckButton *cb_open;
|
||||
GtkCheckButton *cb_mac_filter;
|
||||
|
||||
GtkProgressBar *progress_bar;
|
||||
|
||||
@ -91,10 +95,12 @@ GtkStyleContext *context_entry_pass;
|
||||
GtkStyleContext *context_entry_ssid;
|
||||
GtkStyleContext *context_entry_channel;
|
||||
GtkStyleContext *context_label_input_error;
|
||||
GtkStyleContext *context_tv_mac_filter;
|
||||
|
||||
|
||||
const char** iface_list;
|
||||
const char** wifi_iface_list;
|
||||
gchar *accepted_macs;
|
||||
int iface_list_length;
|
||||
int wifi_iface_list_length;
|
||||
char* running_info[3];
|
||||
@ -145,28 +151,6 @@ static void loadStyles(){
|
||||
screen = gdk_display_get_default_screen (display);
|
||||
gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
|
||||
// const char *style_file;
|
||||
//
|
||||
// const char* debug_style_file="glade/style.css";
|
||||
// const char* prod_style_file="/usr/share/wihotspot_gui/glade/style.css";
|
||||
// FILE *file;
|
||||
//
|
||||
// if ((file = fopen(debug_style_file, "r"))){
|
||||
// fclose(file);
|
||||
// style_file = debug_style_file;
|
||||
// gtk_css_provider_load_from_path(GTK_CSS_PROVIDER(provider),"glade/style.css",NULL);
|
||||
//
|
||||
// }
|
||||
// else if ((file = fopen(prod_style_file, "r"))){
|
||||
// fclose(file);
|
||||
// style_file = prod_style_file;
|
||||
//
|
||||
// } else{
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// gtk_css_provider_load_from_path(GTK_CSS_PROVIDER(provider),style_file,NULL);
|
||||
|
||||
//Load css description from built resource - need to generate compiled source with glib-compile-resource
|
||||
gtk_css_provider_load_from_resource(GTK_CSS_PROVIDER(provider),"/css/style.css");
|
||||
}
|
||||
@ -177,6 +161,7 @@ static void init_style_contexts(){
|
||||
context_entry_pass = gtk_widget_get_style_context((GtkWidget*)entry_pass);
|
||||
context_entry_channel = gtk_widget_get_style_context((GtkWidget*)entry_channel);
|
||||
context_label_input_error = gtk_widget_get_style_context((GtkWidget*)label_input_error);
|
||||
context_tv_mac_filter = gtk_widget_get_style_context((GtkWidget*)tv_mac_filter);
|
||||
|
||||
}
|
||||
|
||||
@ -311,6 +296,28 @@ static void* entry_channel_warn(GtkWidget *widget, gpointer data){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void* tv_mac_filter_warn(){
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_mac_filter))==TRUE){
|
||||
if (isValidAcceptedMacs(get_accepted_macs())==-1){
|
||||
gtk_style_context_add_class(context_tv_mac_filter, "tv-mac-error");
|
||||
set_error_text(ERROR_MAC_MSG);
|
||||
return FALSE;
|
||||
}
|
||||
else{
|
||||
set_error_text("");
|
||||
gtk_style_context_remove_class(context_tv_mac_filter,"tv-mac-error");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
gtk_style_context_remove_class(context_tv_mac_filter,"tv-mac-error");
|
||||
set_error_text("");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void *update_freq_toggle(){
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_freq_2)))
|
||||
@ -332,29 +339,6 @@ int initUi(int argc, char *argv[]){
|
||||
|
||||
/* Construct a GtkBuilder instance and load our UI description */
|
||||
|
||||
// const char* debug_glade_file="glade/wifih.ui";
|
||||
// const char* prod_glade_file="/usr/share/wihotspot_gui/glade/wifih.ui";
|
||||
//
|
||||
// FILE *file;
|
||||
// if ((file = fopen(debug_glade_file, "r"))){
|
||||
// fclose(file);
|
||||
// if (gtk_builder_add_from_file(builder, debug_glade_file, &error) == 0) {
|
||||
// g_printerr("Error loading file: %s\n", error->message);
|
||||
// g_clear_error(&error);
|
||||
// return 1;
|
||||
// }
|
||||
// }
|
||||
// else if ((file = fopen(prod_glade_file, "r"))){
|
||||
// fclose(file);
|
||||
// if (gtk_builder_add_from_file(builder, prod_glade_file, &error) == 0) {
|
||||
// g_printerr("Error loading file: %s\n", error->message);
|
||||
// g_clear_error(&error);
|
||||
// return 1;
|
||||
// }
|
||||
// } else{
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
builder = gtk_builder_new();
|
||||
//Load ui description from built resource - need to generate compiled source with glib-compile-resource
|
||||
gtk_builder_add_from_resource(builder,"/org/gtk/wihotspot/wifih.ui",&error);
|
||||
@ -372,6 +356,9 @@ int initUi(int argc, char *argv[]){
|
||||
|
||||
entry_mac = (GtkEntry *) gtk_builder_get_object(builder, "entry_mac");
|
||||
entry_channel = (GtkEntry *) gtk_builder_get_object(builder, "entry_channel");
|
||||
tv_mac_filter = (GtkTextView *) gtk_builder_get_object(builder, "tv_mac_filter");
|
||||
|
||||
buffer_mac_filter = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv_mac_filter));
|
||||
|
||||
combo_wifi = (GtkComboBox *) gtk_builder_get_object(builder, "combo_wifi");
|
||||
combo_internet = (GtkComboBox *) gtk_builder_get_object(builder, "combo_internet");
|
||||
@ -382,6 +369,7 @@ int initUi(int argc, char *argv[]){
|
||||
cb_novirt = (GtkCheckButton *) gtk_builder_get_object(builder, "cb_novirt");
|
||||
cb_channel = (GtkCheckButton *) gtk_builder_get_object(builder, "cb_channel");
|
||||
cb_open = (GtkCheckButton *) gtk_builder_get_object(builder, "cb_open");
|
||||
cb_mac_filter = (GtkCheckButton *) gtk_builder_get_object(builder, "cb_mac_filter");
|
||||
|
||||
rb_freq_auto = (GtkRadioButton *) gtk_builder_get_object(builder, "rb_freq_auto");
|
||||
rb_freq_2 = (GtkRadioButton *) gtk_builder_get_object(builder, "rb_freq_2");
|
||||
@ -408,6 +396,7 @@ int initUi(int argc, char *argv[]){
|
||||
g_signal_connect (entry_pass, "changed", G_CALLBACK(entry_pass_warn), NULL);
|
||||
|
||||
g_signal_connect (entry_channel, "changed", G_CALLBACK(entry_channel_warn), NULL);
|
||||
g_signal_connect (buffer_mac_filter, "changed", G_CALLBACK(tv_mac_filter_warn), NULL);
|
||||
|
||||
g_signal_connect (rb_freq_2, "toggled", G_CALLBACK(update_freq_toggle), NULL);
|
||||
g_signal_connect (rb_freq_5, "toggled", G_CALLBACK(update_freq_toggle), NULL);
|
||||
@ -433,6 +422,8 @@ void init_ui_from_config(){
|
||||
|
||||
ConfigValues *values=getConfigValues();
|
||||
|
||||
//TODO do properly
|
||||
configValues.accepted_mac_file=values->accepted_mac_file;
|
||||
|
||||
if(values->ssid!=NULL)
|
||||
gtk_entry_set_text(entry_ssd,values->ssid);
|
||||
@ -492,6 +483,15 @@ void init_ui_from_config(){
|
||||
gtk_toggle_button_set_active((GtkToggleButton*) cb_novirt,TRUE);
|
||||
}
|
||||
|
||||
if(strcmp(values->mac_filter,"1")==0){
|
||||
gtk_toggle_button_set_active((GtkToggleButton*) cb_mac_filter,TRUE);
|
||||
}
|
||||
|
||||
char *macs =read_mac_filter_file(values->accepted_mac_file);
|
||||
if (macs!=NULL || strlen(macs)<1){
|
||||
gtk_text_buffer_set_text(buffer_mac_filter,macs,strlen(macs));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -522,6 +522,7 @@ void lock_all_views(gboolean set_lock){
|
||||
gtk_widget_set_sensitive ((GtkWidget*)button_stop_hp, FALSE);
|
||||
gtk_widget_set_sensitive ((GtkWidget*)combo_internet, FALSE);
|
||||
gtk_widget_set_sensitive ((GtkWidget*)combo_wifi, FALSE);
|
||||
gtk_widget_set_sensitive ((GtkWidget*)tv_mac_filter, FALSE);
|
||||
} else{
|
||||
gtk_editable_set_editable( (GtkEditable*)entry_ssd,TRUE);
|
||||
gtk_editable_set_editable( (GtkEditable*)entry_pass,TRUE);
|
||||
@ -530,6 +531,7 @@ void lock_all_views(gboolean set_lock){
|
||||
gtk_widget_set_sensitive ((GtkWidget*)button_stop_hp, TRUE);
|
||||
gtk_widget_set_sensitive ((GtkWidget*)combo_internet, TRUE);
|
||||
gtk_widget_set_sensitive ((GtkWidget*)combo_wifi, TRUE);
|
||||
gtk_widget_set_sensitive ((GtkWidget*)tv_mac_filter, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,6 +546,8 @@ void lock_running_views(gboolean set_lock){
|
||||
|
||||
gtk_widget_set_sensitive ((GtkWidget*)combo_internet, FALSE);
|
||||
gtk_widget_set_sensitive ((GtkWidget*)combo_wifi, FALSE);
|
||||
|
||||
gtk_widget_set_sensitive ((GtkWidget*)tv_mac_filter, FALSE);
|
||||
} else{
|
||||
gtk_editable_set_editable( (GtkEditable*)entry_ssd,TRUE);
|
||||
gtk_editable_set_editable( (GtkEditable*)entry_pass,TRUE);
|
||||
@ -553,6 +557,8 @@ void lock_running_views(gboolean set_lock){
|
||||
|
||||
gtk_widget_set_sensitive ((GtkWidget*)combo_internet, TRUE);
|
||||
gtk_widget_set_sensitive ((GtkWidget*)combo_wifi, TRUE);
|
||||
|
||||
gtk_widget_set_sensitive ((GtkWidget*)tv_mac_filter, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -727,6 +733,11 @@ static gboolean validator(ConfigValues *cv){
|
||||
|
||||
}
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_mac_filter))==TRUE){
|
||||
if (isValidAcceptedMacs(get_accepted_macs())==-1)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -790,6 +801,14 @@ static int init_config_val_input(ConfigValues* cv){
|
||||
else
|
||||
cv->use_psk =NULL;
|
||||
|
||||
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb_mac_filter))){
|
||||
|
||||
cv->mac_filter = "1";
|
||||
cv->accepted_macs=get_accepted_macs();
|
||||
}
|
||||
else
|
||||
cv->mac_filter =NULL;
|
||||
|
||||
return 0;
|
||||
|
||||
} else{
|
||||
@ -799,3 +818,18 @@ static int init_config_val_input(ConfigValues* cv){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
gchar* get_accepted_macs(){
|
||||
|
||||
GtkTextIter start;
|
||||
GtkTextIter end;
|
||||
|
||||
/* Obtain iters for the start and end of points of the buffer */
|
||||
gtk_text_buffer_get_start_iter (buffer_mac_filter, &start);
|
||||
gtk_text_buffer_get_end_iter (buffer_mac_filter, &end);
|
||||
accepted_macs=gtk_text_buffer_get_text (buffer_mac_filter,&start,&end,TRUE);
|
||||
|
||||
return accepted_macs;
|
||||
|
||||
}
|
@ -68,4 +68,6 @@ static gboolean validator(ConfigValues *cv);
|
||||
|
||||
static void set_error_text(char * text);
|
||||
|
||||
gchar* get_accepted_macs();
|
||||
|
||||
#endif //WIHOTSPOT_UI_H
|
||||
|
@ -30,9 +30,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include "util.h"
|
||||
#include <regex.h>
|
||||
|
||||
regex_t regex;
|
||||
int reti;
|
||||
char msgbuf[100];
|
||||
|
||||
int find_str(char *find, const char **array, int length) {
|
||||
int i;
|
||||
@ -86,4 +92,31 @@ int isValidMacAddress(const char* mac) {
|
||||
}
|
||||
|
||||
return (i == 12 && (s == 5 || s == 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int isValidAcceptedMacs(const char *macs){
|
||||
|
||||
/* Compile regular expression */
|
||||
reti = regcomp(®ex, "^(((([0-9A-Fa-f]{2}):){5}[0-9A-Fa-f]{2}\\s*)(^((([0-9A-Fa-f]{2}):){5}[0-9A-Fa-f]{2}\\s*))*)$", REG_EXTENDED);
|
||||
if (reti) {
|
||||
//printf( "Could not compile regex\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Execute regular expression */
|
||||
reti = regexec(®ex, macs, 0, NULL, 0);
|
||||
if (!reti) {
|
||||
return 0;
|
||||
}
|
||||
else if (reti == REG_NOMATCH) {
|
||||
//puts("Invalid mac addresses");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
regerror(reti, ®ex, msgbuf, sizeof(msgbuf));
|
||||
//printf("Regex match failed: %s\n", msgbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,5 +34,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
int find_str(char *find, const char **array, int length);
|
||||
void rand_str(char *dest, size_t length);
|
||||
int isValidMacAddress(const char*);
|
||||
int isValidAcceptedMacs(const char*);
|
||||
|
||||
#endif //WIHOTSPOT_UTIL_H
|
||||
|
Loading…
Reference in New Issue
Block a user