X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2Fap_search.c;h=fd89e868fe35e1d4467af10d48b7c18263c46ca5;hb=63444196dd1edb154f81d9418b3d0bc2367163e5;hp=13d67be672b8e4acd1affbf1a4823e5ab9b84414;hpb=67fc54773e1504698e80c9cb83977bde32665350;p=ap-utils.git diff --git a/lib/ap_search.c b/lib/ap_search.c index 13d67be..fd89e86 100644 --- a/lib/ap_search.c +++ b/lib/ap_search.c @@ -40,18 +40,17 @@ #include #include "ap-utils.h" #include "config.h" -#include "ap-curses.h" #if defined (__GLIBC__) #include #endif - -#define SEARCH_HEADER _(" # Type IP Name") - +#define SEARCH_COMMUNITY _("Community name: ") +#define SEARCH_HEADER _(" NUM IP ADDRESS MIB TYPE NAME") #define MAX_APS LAST_ROW-7 extern int atmel410_filter; +extern char *community; char q_pressed = 0; int i, f_ifctr; @@ -66,23 +65,25 @@ void scan_local_segment (struct sockaddr_in *from, struct sockaddr_in *to, extern WINDOW *main_sub; extern char *ap_types[]; unsigned char message[1024], *start; -/* + extern int atmel410_filter; /* to check is this function called from ap-gl utility */ + + char Wireless[3][12] = { {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x01, 0x00}, {0x2B, 0x06, 0x01, 0x02, 0x01, 0x01, 0x01, 0x00}, {0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x01, 0x01, 0x00} }; -*/ + /* - * operAccessPointName OIDs used to detect AP type [in order of appearance - * according to the 'for' loop below: ATMEL410, NWN, ATMEL12350] + * operAccessPointName OIDs used to detect AP MIB type [in order + * of appearance in the 'for' loop below: ATMEL410, NWN, ATMEL12350] */ - char operAccessPointName[3][12] = { +/* char operAccessPointName[3][12] = { {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x0A, 0x00}, {0x2B, 0x06, 0x01, 0x02, 0x01, 0x01, 0x05, 0x00}, {0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x01, 0x0A, 0x00} }; - +*/ int scd_ap_type, last_searched_type=ATMEL12350; int c, s2, errno, len, client_len = SIZE; struct in_addr to_addr_reserv; @@ -99,13 +100,13 @@ void scan_local_segment (struct sockaddr_in *from, struct sockaddr_in *to, print_help(_("Please wait while scanning, or press 'Q' to quit.")); if ((s2 = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { - print_helperr(CREATE_SOCKET_ERROR); + print_helperr(ERR_CREATING_SOCKET); getch(); return; } if (bind(s2, (struct sockaddr *) from, SIZE) == -1) { - print_helperr(BIND_SOCKET_ERROR); + print_helperr(ERR_BINDING_SOCKET); getch(); goto close_ret; } @@ -142,14 +143,16 @@ void scan_local_segment (struct sockaddr_in *from, struct sockaddr_in *to, for (scd_ap_type = ATMEL410; scd_ap_type <= last_searched_type; scd_ap_type++) { clear_main_new(LAST_ROW - 1, LAST_ROW); - sprintf(message, _("Scanning for AP type: %s"), ap_types[scd_ap_type]); + sprintf(message, _("Scanning for AP with MIB type: %s"), + ap_types[scd_ap_type]); mvwaddstr(main_sub, LAST_ROW - 1, 1, message); wrefresh(main_sub); - varbinds[0].oid = operAccessPointName[scd_ap_type]; - varbinds[0].len_oid = - (scd_ap_type == ATMEL410 || scd_ap_type == ATMEL12350) ? - sizeof(operAccessPointName[scd_ap_type]) : 8; +/* varbinds[0].oid = operAccessPointName[scd_ap_type];*/ + varbinds[0].oid = Wireless[scd_ap_type]; + varbinds[0].len_oid = (scd_ap_type == NWN ? +/* 8 : sizeof(operAccessPointName[scd_ap_type]));*/ + 8 : sizeof(Wireless[scd_ap_type])); varbinds[0].len_val = 0; varbinds[0].type = NULL_VALUE; len = ber(message, varbinds, 1, GET); @@ -287,16 +290,18 @@ void scan_local_segment (struct sockaddr_in *from, struct sockaddr_in *to, fapsa[i].ip = from->sin_addr; fapsa[i].type = scd_ap_type; - sprintf(message, "%2i %11s %15s", i, ap_types[fapsa[i].type], - inet_ntoa(fapsa[i].ip)); - + for (len = 0; len < varbinds[0].len_val && start[len]; len++); + start[len + 1] = '\0'; + if (len > 25) { + /* Truncate (limited screen size) and screen-width independent! */ + start[COLS-53-atmel410_filter] = '>'; + start[COLS-52-atmel410_filter] = '\0'; + } + sprintf(message, " %3i %-15s %-10s %s", i, + inet_ntoa(fapsa[i].ip), ap_types[fapsa[i].type], start); i++; mvwaddstr(main_sub, i, 0, message); - - for (len = 0; len < 32 && start[len]; len++); - start[len + 1] = '\0'; - mvwaddstr(main_sub, i, 30 + ((32 - len) / 2), start); wrefresh(main_sub); /* Bail out if the number of found devices exceeds sane limit. */ @@ -323,13 +328,26 @@ void ap_search() struct ifconf ifc; struct ifreq *ifr; char *ifbuf_ptr = NULL, *ifrec_ptr; + char *old_community; + char buf[16]; + + print_help(_("Please enter SNMP community name that will be used for AP " + "detection.")); + mvwaddstr(main_sub, 0, 2, SEARCH_COMMUNITY); + wrefresh(main_sub); + get_pass(buf, 0, 2 + strlen(SEARCH_COMMUNITY), sizeof(buf)); + old_community = community; + community = malloc(strlen(buf) + 1); + strncpy(community, buf, strlen(buf) + 1); + print_help(""); + clear_main(0); - print_title(_("Access Points Search")); + print_top(NULL, _("Access Points Search")); mvwaddstr(main_sub, 0, 0, SEARCH_HEADER); wrefresh(main_sub); if ((s1 = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { - print_helperr(CREATE_SOCKET_ERROR); + print_helperr(ERR_CREATING_SOCKET); goto wait_quit; } @@ -455,13 +473,15 @@ void ap_search() case '7': case '8': case '9': - if (ac-'0' > (i - 1)) + if (ac - '0' > (i - 1)) continue; - print_title(""); + + print_top(NULL, NULL); clear_main(0); - connect_options(fapsa[ac-'0'].ip.s_addr, - fapsa[ac-'0'].type + 1); - free(fapsa); + free(old_community); + connect_options(fapsa[ac - '0'].ip.s_addr, + fapsa[ac - '0'].type + 1); + free(fapsa); return; } } @@ -475,8 +495,11 @@ quit: if (fapsa) free(fapsa); + free(community); + community = old_community; + print_help(""); - print_title(""); + print_top(NULL, NULL); clear_main(0); }