int main( int argc, char **argv ) { Config config(argc, argv); if( config.help ) { std::cout << config.desc() << std::endl; return 0; } if( config.list_interfaces ) { print_interfaces(std::cout); return 0; } if( config.host.empty() && config.filter.empty() ) { std::cerr << "Error: One of either --host or --filter is required." << std::endl; std::cerr << config.desc() << std::endl; return 1; } if( config.interface.empty() ) { std::cerr << "Error: You must specify the network interface. (-i)" << std::endl; std::cerr << config.desc() << std::endl; print_interfaces(std::cerr); return 1; } libpcap::live_capture pcap(config.interface, config.pcap_filter(), config.cap_timeout); if( pcap.has_error() ) { std::cerr << "Error while setting up libpcap: "; std::cerr << pcap.get_error() << std::endl; return 1; } thread_t pcap_thread( [&pcap]{ pcap.capture_loop(); } ); Stats::Tracker tracker(pcap, config.sample_period, config.quantum_period); std::cout << "Listening..." << std::endl; size_t dropped_count = 0; for(;;) { auto _count = pcap.dropped_count(); if( _count > dropped_count ) { std::cerr << "Warning: " << _count - dropped_count << " packets have been dropped." << std::endl; dropped_count = _count; } const auto peer_data = tracker.snapshot(); Analysis::print_status(peer_data, config); Analysis::check_events(peer_data, config); this_thread::sleep_for(config.quantum_period); } pcap_thread.join(); return 0; }
static int print_element_info (GstElementFactory * factory, gboolean print_names) { GstElement *element; gint maxlevel = 0; factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE (factory))); if (!factory) { g_print ("element plugin couldn't be loaded\n"); return -1; } element = gst_element_factory_create (factory, NULL); if (!element) { g_print ("couldn't construct element for some reason\n"); return -1; } if (print_names) _name = g_strdup_printf ("%s: ", GST_PLUGIN_FEATURE (factory)->name); else _name = NULL; print_factory_details_info (factory); if (GST_PLUGIN_FEATURE (factory)->plugin_name) { GstPlugin *plugin; plugin = gst_registry_find_plugin (gst_registry_get_default (), GST_PLUGIN_FEATURE (factory)->plugin_name); if (plugin) { print_plugin_info (plugin); } } print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel); print_interfaces (G_OBJECT_TYPE (element)); print_pad_templates_info (element, factory); print_element_flag_info (element); print_implementation_info (element); print_clocking_info (element); print_index_info (element); print_uri_handler_info (element); print_pad_info (element); print_element_properties_info (element); print_signal_info (element); print_children_info (element); gst_object_unref (element); gst_object_unref (factory); g_free (_name); return 0; }
int interface(char *mesh_iface, int argc, char **argv) { char *path_buff; int i, res, optchar; while ((optchar = getopt(argc, argv, "h")) != -1) { switch (optchar) { case 'h': interface_usage(); return EXIT_SUCCESS; default: interface_usage(); return EXIT_FAILURE; } } if (argc == 1) return print_interfaces(mesh_iface); if ((strcmp(argv[1], "add") != 0) && (strcmp(argv[1], "a") != 0) && (strcmp(argv[1], "del") != 0) && (strcmp(argv[1], "d") != 0)) { printf("Error - unknown argument specified: %s\n", argv[1]); interface_usage(); goto err; } path_buff = malloc(PATH_BUFF_LEN); if (!path_buff) { printf("Error - could not allocate path buffer: out of memory ?\n"); goto err; } for (i = 2; i < argc; i++) { snprintf(path_buff, PATH_BUFF_LEN, SYS_MESH_IFACE_FMT, argv[i]); if (argv[1][0] == 'a') res = write_file("", path_buff, mesh_iface, NULL); else res = write_file("", path_buff, "none", NULL); if (res != EXIT_SUCCESS) goto err_buff; } free(path_buff); return EXIT_SUCCESS; err_buff: free(path_buff); err: return EXIT_FAILURE; }
int main(int argc, char *argv[]) { struct ap_list apl; struct ap_info api; struct iw_dev dev; struct pollfd pfd[2]; struct deauth_thread_args ta; struct timeval tv1, tv2; suseconds_t msec; pthread_t deauth_thread; pthread_mutex_t chan_mutex, list_mutex, cnc_mutex; pthread_cond_t chan_cond; channelset_t chans; int ret, sigfd, c, n, chan; char *ifname, *chans_str; sigset_t exit_sig; time_t tm; if (argc < 2) { print_usage(stderr); return EXIT_FAILURE; } /* arguments */ ifname = argv[argc-1]; chans_str = NULL; while((c = getopt(argc, argv, "c:lh")) != -1) { switch (c) { case 'c': chans_str = optarg; break; case 'l': return print_interfaces(); case 'h': print_usage(stdout); return EXIT_SUCCESS; case '?': default: return EXIT_FAILURE; } } if (argv[optind] != ifname) { print_usage(stderr); return EXIT_FAILURE; } if (getuid()) { fprintf(stderr, "Not root?\n"); return EXIT_FAILURE; } /* init channel set */ if (chans_str == NULL) { channel_zero(&chans); for (n=1; n<=14; n++) channel_set(&chans, n); } else { if (parse_chans_str(chans_str, &chans) == -1) { fprintf(stderr, "Can not parse the channels\n"); return EXIT_FAILURE; } } /* init access point list */ init_ap_list(&apl); /* init signals */ sigemptyset(&exit_sig); sigaddset(&exit_sig, SIGINT); sigaddset(&exit_sig, SIGTERM); if (sigprocmask(SIG_BLOCK, &exit_sig, NULL) < 0) { err_msg("sigprocmask"); return EXIT_FAILURE; } sigfd = signalfd(-1, &exit_sig, 0); if (sigfd < 0) { err_msg("signalfd"); return EXIT_FAILURE; } pfd[0].fd = sigfd; pfd[0].revents = 0; pfd[0].events = POLLIN; /* init device */ iw_init_dev(&dev); strncpy(dev.ifname, ifname, sizeof(dev.ifname)-1); if (iw_open(&dev) < 0) { print_error(); goto _errout_no_thread; } pfd[1].fd = dev.fd_in; pfd[1].revents = 0; pfd[1].events = POLLIN; /* set channel */ n = 0; chan = 0; do { chan = (chan % CHANNEL_MAX) + 1; if (channel_isset(&chans, chan)) ret = iw_set_channel(&dev, chan); else ret = -1; /* if fails try next channel */ } while(++n < CHANNEL_MAX && ret < 0); if (ret < 0) { print_error(); goto _errout_no_thread; } /* start deauth thread */ ta.stop = 0; ta.apl = &apl; ta.dev = &dev; pthread_mutex_init(&chan_mutex, NULL); ta.chan_mutex = &chan_mutex; pthread_cond_init(&chan_cond, NULL); ta.chan_cond = &chan_cond; pthread_mutex_init(&list_mutex, NULL); ta.list_mutex = &list_mutex; ta.chan_changed = 1; pthread_mutex_init(&cnc_mutex, NULL); ta.cnc_mutex = &cnc_mutex; ta.chan_need_change = 0; if (pthread_create(&deauth_thread, NULL, deauth_thread_func, &ta) < 0) { err_msg("pthread_create"); goto _errout_no_thread; } clear_scr(); update_scr(&apl, &dev); tm = time(NULL); gettimeofday(&tv1, NULL); while (!ta.stop) { if (poll(pfd, 2, 0) < 0) { err_msg("poll"); goto _errout; } if (pfd[0].revents & POLLIN) /* got SIGTERM or SIGINT */ break; if (pfd[1].revents & POLLIN) { ret = read_ap_info(&dev, &api); if (ret < 0 && ret != ERRNODATA) { /* error */ print_error(); goto _errout; } else if (ret == 0 && channel_isset(&chans, api.chan)) { /* got infos */ pthread_mutex_lock(&list_mutex); if (add_or_update_ap(&apl, &api) < 0) { pthread_mutex_unlock(&list_mutex); print_error(); goto _errout; } pthread_mutex_unlock(&list_mutex); } } gettimeofday(&tv2, NULL); if (tv2.tv_usec > tv1.tv_usec) msec = tv2.tv_usec - tv1.tv_usec; else msec = tv1.tv_usec - tv2.tv_usec; /* update screen every 0.5 second */ if (msec >= 500000) { pthread_mutex_lock(&list_mutex); update_scr(&apl, &dev); pthread_mutex_unlock(&list_mutex); gettimeofday(&tv1, NULL); } /* change channel at least every 1 second */ if (time(NULL) - tm >= 1) { if (!ta.chan_changed) { pthread_mutex_lock(&cnc_mutex); ta.chan_need_change = 0; pthread_mutex_unlock(&cnc_mutex); pthread_mutex_lock(&chan_mutex); n = 0; do { chan = (chan % CHANNEL_MAX) + 1; if (channel_isset(&chans, chan)) ret = iw_set_channel(&dev, chan); else ret = -1; /* if fails try next channel */ } while(++n < CHANNEL_MAX && ret < 0); /* if all channels failed */ if (ret < 0) { print_error(); goto _errout; } tm = time(NULL); ta.chan_changed = 1; pthread_cond_signal(&chan_cond); pthread_mutex_unlock(&chan_mutex); } else { pthread_mutex_lock(&cnc_mutex); ta.chan_need_change = 1; pthread_mutex_unlock(&cnc_mutex); } } } /* we got an error from deauth thread */ if (ta.stop == 2) goto _errout; printf("\nExiting..\n"); ta.stop = 1; pthread_mutex_unlock(&list_mutex); pthread_cond_broadcast(&chan_cond); pthread_mutex_unlock(&chan_mutex); pthread_join(deauth_thread, NULL); iw_close(&dev); free_ap_list(&apl); return EXIT_SUCCESS; _errout: ta.stop = 1; pthread_mutex_unlock(&list_mutex); pthread_cond_broadcast(&chan_cond); pthread_mutex_unlock(&chan_mutex); pthread_join(deauth_thread, NULL); _errout_no_thread: iw_close(&dev); free_ap_list(&apl); return EXIT_FAILURE; }