void ipv4_network_to_string(ipv4network netaddr, char *string, size_t size) { int length; ipv4_addr_to_string(netaddr.net, string, size); length = strlen(string); assert(length <= size); snprintf(string + length, size - length, "/%hhu", netaddr.mask); }
static int write_out_packet(pcapreport_ctx_t * const ctx, pcapreport_stream_t * const st, const byte *data, const uint32_t len) { int rv; unsigned int pkts = len / 188; if (st->output_name) { if (!st->output_file) { fprint_msg("pcapreport: Dumping all packets for %s:%d to %s\n", ipv4_addr_to_string(st->output_dest_addr), st->output_dest_port, st->output_name); st->output_file = fopen(st->output_name, "wb"); if (!st->output_file) { fprint_err("### pcapreport: Cannot open %s .\n", st->output_name); return 1; } } if (ctx->verbose) { fprint_msg("++ Dumping %d bytes to output file.\n", len); } rv = fwrite(data, 188, pkts, st->output_file); if (rv != pkts) { fprint_err( "### pcapreport: Couldn't write %d bytes" " to %s (error = %d).\n", len, st->output_name, ferror(st->output_file)); return 1; } } return 0; }