int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s <interface> [whitelist]\n", argv[0]); return 1; } struct timeval start_timeval; gettimeofday(&start_timeval, NULL); start_timestamp_microseconds = start_timeval.tv_sec * NUM_MICROS_PER_SECOND + start_timeval.tv_usec; initialize_bismark_id(); if (argc < 3 || initialize_domain_whitelist(argv[2])) { fprintf(stderr, "Error loading domain whitelist; whitelisting disabled.\n"); } #ifndef DISABLE_ANONYMIZATION if (anonymization_init()) { fprintf(stderr, "Error initializing anonymizer\n"); return 1; } #endif #ifdef ENABLE_FREQUENT_UPDATES if (anonymize_mac(bismark_mac, bismark_mac)) { fprintf(stderr, "Error anonymizing router MAC address\n"); } #endif packet_series_init(&packet_data); flow_table_init(&flow_table); dns_table_init(&dns_table, &domain_whitelist); #ifdef ENABLE_HTTP_URL http_table_init(&http_table); #endif address_table_init(&address_table); drop_statistics_init(&drop_statistics); #ifdef ENABLE_FREQUENT_UPDATES device_throughput_table_init(&device_throughput_table); #endif upload_failures_init(&upload_failures, UPLOAD_FAILURES_FILENAME); initialize_signal_handler(); set_next_alarm(); /* By default, pcap uses an internal buffer of 500 KB. Any packets that * overflow this buffer will be dropped. pcap_stats tells the number of * dropped packets. * * Because pcap does its own buffering, we don't need to run packet * processing in a separate thread. (It would be easier to just increase * the buffer size if we experience performance problems.) */ pcap_handle = initialize_pcap(argv[1]); if (!pcap_handle) { return 1; } return pcap_loop(pcap_handle, -1, process_packet, NULL); }
int address_table_write_update(address_table_t* const table, gzFile handle) { if (!gzprintf(handle, "%d %d\n", NORM(table->last - table->added_since_last_update + 1), MAC_TABLE_ENTRIES)) { #ifndef NDEBUG perror("Error writing update"); #endif return -1; } int idx; for (idx = table->added_since_last_update; idx > 0; --idx) { int mac_id = NORM(table->last - idx + 1); #ifndef DISABLE_ANONYMIZATION uint64_t digest_ip; uint8_t digest_mac[ETH_ALEN]; if (anonymize_ip(table->entries[mac_id].ip_address, &digest_ip) || anonymize_mac(table->entries[mac_id].mac_address, digest_mac)) { #ifndef NDEBUG fprintf(stderr, "Error anonymizing MAC mapping\n"); #endif return -1; } if (!gzprintf(handle, "%s %" PRIx64 "\n", buffer_to_hex(digest_mac, ETH_ALEN), digest_ip)) { #else if (!gzprintf(handle, "%s %" PRIx32 "\n", buffer_to_hex(table->entries[mac_id].mac_address, ETH_ALEN), table->entries[mac_id].ip_address)) { #endif #ifndef NDEBUG perror("Error writing update"); #endif return -1; } } if (!gzprintf(handle, "\n")) { #ifndef NDEBUG perror("Error writing update"); #endif return -1; } table->added_since_last_update = 0; return 0; }