wificurse

wifi jamming tool
git clone git://git.2f30.org/wificurse
Log | Files | Refs | README | LICENSE

ap_list.c (2033B)


      1 /*
      2     wificurse - WiFi Jamming tool
      3     Copyright (C) 2012  oblique
      4 
      5     This program is free software: you can redistribute it and/or modify
      6     it under the terms of the GNU General Public License as published by
      7     the Free Software Foundation, either version 3 of the License, or
      8     (at your option) any later version.
      9 
     10     This program is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13     GNU General Public License for more details.
     14 
     15     You should have received a copy of the GNU General Public License
     16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 */
     18 
     19 #include <stdlib.h>
     20 #include <string.h>
     21 #include <time.h>
     22 #include "iw.h"
     23 #include "error.h"
     24 #include "ap_list.h"
     25 
     26 
     27 void init_ap_list(struct ap_list *apl) {
     28 	apl->head = NULL;
     29 	apl->tail = NULL;
     30 }
     31 
     32 void free_ap_list(struct ap_list *apl) {
     33 	struct access_point *tmp;
     34 
     35 	while (apl->head != NULL) {
     36 		tmp = apl->head;
     37 		apl->head = apl->head->next;
     38 		free(tmp);
     39 	}
     40 
     41 	apl->head = apl->tail = NULL;
     42 }
     43 
     44 void link_ap(struct ap_list *apl, struct access_point *ap) {
     45 	if (apl->head == NULL)
     46 		apl->head = apl->tail = ap;
     47 	else {
     48 		ap->prev = apl->tail;
     49 		apl->tail->next = ap;
     50 		apl->tail = ap;
     51 	}
     52 }
     53 
     54 void unlink_ap(struct ap_list *apl, struct access_point *ap) {
     55 	if (ap->prev)
     56 		ap->prev->next = ap->next;
     57 	else
     58 		apl->head = ap->next;
     59 	if (ap->next)
     60 		ap->next->prev = ap->prev;
     61 	else
     62 		apl->tail = ap->prev;
     63 }
     64 
     65 int add_or_update_ap(struct ap_list *apl, struct ap_info *api) {
     66 	struct access_point *ap;
     67 
     68 	ap = apl->head;
     69 	while (ap != NULL) {
     70 		if (memcmp(ap->info.bssid, api->bssid, IFHWADDRLEN) == 0)
     71 			break;
     72 		ap = ap->next;
     73 	}
     74 
     75 	if (ap == NULL) {
     76 		ap = malloc(sizeof(*ap));
     77 		if (ap == NULL)
     78 			return_error("malloc");
     79 
     80 		memset(ap, 0, sizeof(*ap));
     81 		memcpy(&ap->info, api, sizeof(ap->info));
     82 		ap->last_beacon_tm = time(NULL);
     83 		link_ap(apl, ap);
     84 	} else
     85 		ap->last_beacon_tm = time(NULL);
     86 
     87 	return 0;
     88 }