int main(int argc, char** argv) { int inumber; if(argc != 2) { printf("%s <absolute_path>\n", argv[0]); return EXIT_FAILURE; } mount(); if((inumber = inumber_of_path(argv[1])) != 0) { file_desc_t fd; if(open_ifile(&fd, inumber) != RETURN_FAILURE) { struct entry_s entry; while(read_ifile(&fd, &entry, sizeof(struct entry_s)) > 0) { if(entry.inumber != 0) printf("%s\n", entry.name); } close_ifile(&fd); } } else PRINT_FATAL_ERROR("Not a valid path"); return EXIT_SUCCESS; }
int wirouterkeyrec(int argc, char *argv[]) { int debug = 0, verbose = 0, option = 0, optidx = 0, update = 0; struct option long_options[] = { {"ssid", 1, 0, 's'}, {"ssid_file", 1, 0, 'f'}, {"config", 1, 0, 'c'}, {"agpfurl", 1, 0, 'a'}, {"updateagpf", 0, 0, 'u'}, {"debug", 0, 0, 'd'}, {"help", 0, 0, 'h'}, {"verbose", 0, 0, 'v'}, {NULL, 0, 0, 0} }; unsigned char *temp = NULL, *agpf_host = NULL, *agpf_url = NULL, *agpf_web_page = (unsigned char *) AGPF_DEFAULT_WEB_PAGE, wr_config_file[255]; /* Config File Name */ Essid_list *net_list = NULL; /* Networks list */ /* Print the usage */ if(argc < 2) wr_usage(argv[0]); memset(wr_config_file, 0, sizeof(wr_config_file)); while((option = getopt_long(argc, argv, "s:f:c:a:dhvu", long_options, &optidx)) > 0) { switch(option) { case 's': /* Multiple networks */ if(strstr(optarg, ",")) { /* Parsing List */ for(temp = (unsigned char *) strtok(optarg, ","); temp; temp = (unsigned char *) strtok(NULL, ",")) net_list = wr_essid_add(net_list, temp); } /* Just one network */ else { net_list = wr_essid_add(net_list, (unsigned char *)optarg); } if(!net_list) PRINT_FATAL_ERROR("Unable to get a valid SSID list [Errno: %s].", strerror(errno)); break; case 'f': /* Load networks from file */ net_list = wr_load_essid_from_file(net_list, (unsigned char *)optarg); if(!net_list) PRINT_FATAL_ERROR("Unable to get a valid SSID list [Errno: %s].", strerror(errno)); break; case 'c': /* Set a new configuration file */ if(strlen(optarg) < 255) strncpy((char *)wr_config_file, optarg, sizeof(wr_config_file)-1); else PRINT_ERROR("File name too long. Will be used the default config file (%s)", AGPF_DEFAULT_CONFIG_FILE); if(wr_check_file_exist(wr_config_file) < 0) PRINT_FATAL_ERROR("Unable to open the configuration file [Errno: %s].", strerror(errno)); break; case 'u': /* Update the configuration file */ update = 1; break; case 'a': /* Set the URL from where downloading the AGPF configuration file */ agpf_web_page = (unsigned char *)optarg; wr_parsing_web_page(agpf_web_page, &agpf_host, &agpf_url); if(!agpf_host || !agpf_url) PRINT_ERROR("Invalid URL. Will be used the default URL (%s)", AGPF_DEFAULT_WEB_PAGE); break; case 'd': debug = 1; break; case 'h': wr_usage(argv[0]); break; case 'v': verbose = 1; break; default: wr_usage(argv[0]); break; } } if(update) { PRINT_HEADER if(!agpf_host || !agpf_url) { agpf_web_page = (unsigned char *)AGPF_DEFAULT_WEB_PAGE; wr_parsing_web_page(agpf_web_page, &agpf_host, &agpf_url); if(!agpf_host || !agpf_url) PRINT_FATAL_ERROR("Unable to use the default URL (%s)", AGPF_DEFAULT_WEB_PAGE); } if(!wr_check_file_exist((unsigned char *) AGPF_DEFAULT_CONFIG_FILE_DIR)) agpf_update_config_file((unsigned char *)AGPF_DEFAULT_CONFIG_FILE_DIR, agpf_host, 80, agpf_url, NULL, NULL, debug); else agpf_update_config_file((unsigned char *)AGPF_DEFAULT_CONFIG_FILE, agpf_host, 80, agpf_url, NULL, NULL, debug); return 0; } if(!net_list) return -1; PRINT_HEADER net_list = wr_get_keys(net_list, wr_config_file, debug); /* Print the result */ if(net_list) { wr_print_essid(net_list, verbose); net_list = wr_essid_free(net_list); } else { printf("\nThere are no WPA keys found.\n\n"); return -1; } return 0; }