/* * The main ! */ int main(int argc, char ** argv) { int skfd; /* generic raw socket desc. */ int goterr = 0; /* Create a channel to the NET kernel. */ if((skfd = iw_sockets_open()) < 0) { perror("socket"); return(-1); } /* No argument : show the list of all device + info */ if(argc == 1) iw_enum_devices(skfd, &print_priv_info, NULL, 0); else /* Special cases take one... */ /* All */ if((!strncmp(argv[1], "-a", 2)) || (!strcmp(argv[1], "--all"))) iw_enum_devices(skfd, &print_priv_all, NULL, 0); else /* Help */ if((!strncmp(argv[1], "-h", 2)) || (!strcmp(argv[1], "--help"))) iw_usage(); else /* Version */ if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) goterr = iw_print_version_info("iwpriv"); else /* The device name must be the first argument */ /* Name only : show for that device only */ if(argc == 2) print_priv_info(skfd, argv[1], NULL, 0); else /* Special cases take two... */ /* All */ if((!strncmp(argv[2], "-a", 2)) || (!strcmp(argv[2], "--all"))) print_priv_all(skfd, argv[1], NULL, 0); else /* Roaming */ if(!strncmp(argv[2], "roam", 4)) goterr = set_roaming(skfd, argv + 3, argc - 3, argv[1]); else /* Port type */ if(!strncmp(argv[2], "port", 4)) goterr = port_type(skfd, argv + 3, argc - 3, argv[1]); else /*-------------*/ /* Otherwise, it's a private ioctl */ goterr = set_private(skfd, argv + 2, argc - 2, argv[1]); /* Close the socket. */ close(skfd); return(goterr); }
static void stats_convert(struct stats_file *file) { struct stats_file temp_file; int err; DBG("converting data file %s", file->name); stats_file_update_cache32(file); bzero(&temp_file, sizeof(struct stats_file)); err = stats_open_temp(&temp_file); if (err < 0) { connman_error("failed to open temporary file during data conversion"); return; } stats_file_setup(&temp_file); struct stats_iter32 data_iter; struct stats_record32 *record; data_iter.file = file; data_iter.begin = get_iterator_begin32(data_iter.file); data_iter.end = get_iterator_end32(data_iter.file); data_iter.it = data_iter.begin; record = get_next_record32(&data_iter); while (record) { struct stats_record *next; if (temp_file.last == get_end(&temp_file)) { err = stats_file_remap(&temp_file, temp_file.len + sysconf(_SC_PAGESIZE)); if (err < 0) { connman_error("failed to extend file %s", temp_file.name); unlink(temp_file.name); stats_file_unmap(&temp_file); TFR(close(temp_file.fd)); stats_file_cleanup(&temp_file); return; } stats_file_update_cache(&temp_file); } next = get_next(&temp_file, get_end(&temp_file)); if (next == get_begin(&temp_file)) { connman_error("ring buffer is full"); unlink(temp_file.name); stats_file_unmap(&temp_file); TFR(close(temp_file.fd)); stats_file_cleanup(&temp_file); return; } next->ts = record->ts; next->roaming = record->roaming; next->data.rx_packets = record->data.rx_packets; next->data.tx_packets = record->data.tx_packets; next->data.rx_bytes = record->data.rx_bytes; next->data.tx_bytes = record->data.tx_bytes; next->data.rx_errors = record->data.rx_errors; next->data.tx_errors = record->data.tx_errors; next->data.rx_dropped = record->data.rx_dropped; next->data.tx_dropped = record->data.tx_dropped; next->data.time = record->data.time; if (next->roaming) set_roaming(&temp_file, next); else set_home(&temp_file, next); set_end(&temp_file, next); record = get_next_record32(&data_iter); } // close and swap stats_file_unmap(file); TFR(close(file->fd)); err = rename(temp_file.name, file->name); if (err < 0) connman_error("failed to rename converted data file %s to %s", temp_file.name, file->name); g_free(temp_file.name); temp_file.name = file->name; memcpy(file, &temp_file, sizeof(struct stats_file)); }
/* * The main ! */ int main(int argc, char ** argv) { int skfd = -1; /* generic raw socket desc. */ int goterr = 0; /* Create a channel to the NET kernel. */ if((skfd = sockets_open()) < 0) { perror("socket"); exit(-1); } /* No argument : show the list of all device + info */ if(argc == 1) { print_priv_devices(skfd); close(skfd); exit(0); } /* Special cases take one... */ /* Help */ if((!strncmp(argv[1], "-h", 9)) || (!strcmp(argv[1], "--help"))) { iw_usage(); close(skfd); exit(0); } /* The device name must be the first argument */ /* Name only : show for that device only */ if(argc == 2) { print_priv_info(skfd, argv[1]); close(skfd); exit(0); } /* Special cases take two... */ /* Roaming */ if(!strncmp(argv[2], "roam", 4)) { goterr = set_roaming(skfd, argv + 3, argc - 3, argv[1]); close(skfd); exit(0); } /* Port type */ if(!strncmp(argv[2], "port", 4)) { goterr = port_type(skfd, argv + 3, argc - 3, argv[1]); close(skfd); exit(0); } /* Otherwise, it's a private ioctl */ goterr = set_private(skfd, argv + 2, argc - 2, argv[1]); /* Close the socket. */ close(skfd); return(0); }