X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2Fap_search.c;h=a633d0d2cf339d8e50558b0d68c63f0d49f31a2f;hb=9a9cc94445e34fde182b7a1cc56b5f4b7257da96;hp=7c41718bc25a61ddcc723ed554b8cbc0e6f51f1b;hpb=09ed626f25fb3e7c57ad7a59e5261ea005aa498f;p=ap-utils.git diff --git a/lib/ap_search.c b/lib/ap_search.c index 7c41718..a633d0d 100644 --- a/lib/ap_search.c +++ b/lib/ap_search.c @@ -34,28 +34,30 @@ #include #endif +#include #include #include #include #include "ap-utils.h" -#include "ap-curses.h" +#include "config.h" #if defined (__GLIBC__) #include #endif - -#define MAX_APS 10 -#define SEARCH_HEADER _("# Type IP Description") +#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_press = 0; +char q_pressed = 0; int i, f_ifctr; struct faps { struct in_addr ip; int type; -} fapsa[MAX_APS]; +} *fapsa; void scan_local_segment (struct sockaddr_in *from, struct sockaddr_in *to, char *ifname) @@ -63,15 +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; - /* - * sysDescr OIDs used to detect AP type [in order of appearance - * according to the 'for' loop below: ATMEL410, NWN, ATMEL12350 - */ + 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 MIB type [in order + * of appearance in the 'for' loop below: ATMEL410, NWN, ATMEL12350] + */ +/* 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; @@ -116,28 +128,31 @@ void scan_local_segment (struct sockaddr_in *from, struct sockaddr_in *to, goto close_ret; } - mvwaddstr(main_sub, 15, 1, _("Scanning via network interface:")); + mvwaddstr(main_sub, LAST_ROW - 5, 1, + _("Scanning via network interface:")); sprintf(message, _(" Index: %i"), f_ifctr); - mvwaddstr(main_sub, 16, 1, message); + mvwaddstr(main_sub, LAST_ROW - 4, 1, message); sprintf(message, _(" Name: %s"), ifname); - mvwaddstr(main_sub, 17, 1, message); + mvwaddstr(main_sub, LAST_ROW - 3, 1, message); sprintf(message, _(" IP: %s"), inet_ntoa(from->sin_addr)); - mvwaddstr(main_sub, 18, 1, message); + mvwaddstr(main_sub, LAST_ROW - 2, 1, message); if(atmel410_filter) { last_searched_type=ATMEL410; } for (scd_ap_type = ATMEL410; scd_ap_type <= last_searched_type; scd_ap_type++) { - clear_main_new(19, 20); - sprintf(message, _("Scanning for AP type: %s"), ap_types[scd_ap_type]); - mvwaddstr(main_sub, 19, 1, message); + clear_main_new(LAST_ROW - 1, LAST_ROW); + 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].oid = Wireless[scd_ap_type]; - varbinds[0].len_oid = - (scd_ap_type == ATMEL410 || scd_ap_type == ATMEL12350) ? - sizeof(Wireless[scd_ap_type]) : 8; + 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); @@ -196,7 +211,7 @@ void scan_local_segment (struct sockaddr_in *from, struct sockaddr_in *to, if (FD_ISSET(0, &rds)) { c = getc(stdin); if (c == 'q' || c == 'Q') { - q_press = 1; + q_pressed = 1; goto close_ret; } } @@ -270,17 +285,23 @@ void scan_local_segment (struct sockaddr_in *from, struct sockaddr_in *to, /* new AP (unique IP/APtype pair) found */ + fapsa = realloc(fapsa, (i + 1) * sizeof(struct faps)); + fapsa[i].ip = from->sin_addr; fapsa[i].type = scd_ap_type; - sprintf(message, "%2X %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 < varbinds[0].len_val && start[len]; len++) - mvwaddch(main_sub, i, len + 31, start[len]); wrefresh(main_sub); /* Bail out if the number of found devices exceeds sane limit. */ @@ -307,8 +328,21 @@ 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); @@ -318,6 +352,7 @@ void ap_search() } i = f_ifctr = 0; + fapsa = NULL; /* * Find all IPs of locally available IPv4 interfaces and corresponding @@ -395,7 +430,7 @@ void ap_search() from.sin_port = INADDR_ANY; to.sin_port = htons(161); scan_local_segment(&from, &to, ifr->ifr_name); - clear_main_new(15, 20); + clear_main_new(LAST_ROW - 5, LAST_ROW); } ifrec_ptr += ilen; /* No need to process next interfaces if the table is already full, */ @@ -403,8 +438,8 @@ void ap_search() break; /* or if someone pressed 'Q'. */ - if (q_press) { - q_press = 0; + if (q_pressed) { + q_pressed = 0; break; } } @@ -418,8 +453,8 @@ void ap_search() "Press any key.")); } else { if (i == MAX_APS) - mvwaddstr(main_sub, 19, 1, _("Program-hardcoded maximum number " - "of APs found.")); + mvwaddstr(main_sub, LAST_ROW - 1, 1, + _("Single-screen maximum number of APs found.")); wrefresh(main_sub); print_help(_("# - connect to AP; Q - quit")); @@ -438,12 +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(old_community); + connect_options(fapsa[ac - '0'].ip.s_addr, + fapsa[ac - '0'].type + 1); + free(fapsa); return; } } @@ -454,8 +492,14 @@ quit: if (ifbuf_ptr) free(ifbuf_ptr); + if (fapsa) + free(fapsa); + + free(community); + community = old_community; + print_help(""); - print_title(""); + print_top(NULL, NULL); clear_main(0); }