const char* stream_addr_ntoa_r(const stream_addr_t* src, char* buf, size_t bytes){ int __attribute__((unused)) written = 0; switch(stream_addr_type(src)){ case STREAM_ADDR_GUESS: abort(); case STREAM_ADDR_TCP: case STREAM_ADDR_UDP: written = snprintf(buf, bytes, "%s://%s:%d", stream_addr_type(src) == STREAM_ADDR_UDP ? "udp" : "tcp", inet_ntoa(src->in_addr), ntohs(src->in_port)); break; case STREAM_ADDR_ETHERNET: written = snprintf(buf, bytes, "eth://%s", hexdump_address(&src->ether_addr)); break; case STREAM_ADDR_CAPFILE: if ( stream_addr_have_flag(src, STREAM_ADDR_LOCAL) ){ strncpy(buf, src->local_filename, bytes); } else { strncpy(buf, src->filename, bytes); } buf[bytes-1] = 0; /* force null-terminator */ break; } assert(written < bytes); return buf; }
void stream_addr_reset(stream_addr_t* addr) { if ( stream_addr_type(addr) == STREAM_ADDR_CAPFILE && stream_addr_have_flag(addr, STREAM_ADDR_DUPLICATE) ) { free(addr->int_filename); } memset(addr, 0, sizeof(stream_addr_t)); }
static long stream_file_destroy(struct stream_file* st){ if ( stream_addr_have_flag(&st->base.addr, STREAM_ADDR_UNLINK) ){ unlink(st->base.addr.local_filename); } if ( need_fclose(st) ){ fclose(st->file); } free(st->base.comment); free(st); return 0; }
static int need_fclose(const struct stream_file* st){ return stream_addr_type(&st->base.addr) == STREAM_ADDR_CAPFILE || stream_addr_have_flag(&st->base.addr, STREAM_ADDR_FCLOSE); }