static int add_prefixes_from_file(bgpstream_ip_counter_t *poi, char *pfx_file_string) { char pfx_line[MAX_LOG_BUFFER_LEN]; io_t *file = NULL; bgpstream_pfx_storage_t pfx_st; if (pfx_file_string == NULL) { return -1; } if ((file = wandio_create(pfx_file_string)) == NULL) { fprintf(stderr, "ERROR: Could not open prefix file (%s)\n", pfx_file_string); return -1; } while (wandio_fgets(file, &pfx_line, MAX_LOG_BUFFER_LEN, 1) > 0) { /* treat # as comment line, and ignore empty lines */ if (pfx_line[0] == '#' || pfx_line[0] == '\0') { continue; } if (bgpstream_str2pfx(pfx_line, &pfx_st) == NULL || bgpstream_ip_counter_add(poi, (bgpstream_pfx_t *)&pfx_st) != 0) { /* failed to parse/insert the prefix */ return -1; } } wandio_destroy(file); return 0; }
off_t corsaro_file_rgets(corsaro_file_in_t *file, void *buffer, off_t len) { /* refuse to read from a libtrace file */ assert(file != NULL); assert(file->mode == CORSARO_FILE_MODE_ASCII || file->mode == CORSARO_FILE_MODE_BINARY || file->mode == CORSARO_FILE_MODE_UNKNOWN); assert(file->wand_io != NULL); /* just hand off to the helper func in wandio_utils (no chomp) */ return wandio_fgets(file->wand_io, buffer, len, 0); }