Esempio n. 1
0
void dump_ini_start_section(void) {
    if (current_time.tv_sec != 0) {
        dump_flush(FALSE);
    }
    old_dump_engine = dump_engine;
    dump_init();
}
Esempio n. 2
0
/**
 * Dump packet received from node.
 */
static void
dump_packet_from(struct dump *dump, const struct gnutella_node *node)
{
	struct dump_header dh;	

	if (!dump_initialize(dump))
		return;

	dump_header_set(&dh, node);
	dump_append(dump, dh.data, sizeof dh.data);
	dump_append(dump, node->header, sizeof node->header);
	dump_append(dump, node->data, node->size);
	dump_flush(dump);
}
Esempio n. 3
0
/**
 * Dump relayed or locally-emitted packet.
 * If ``from'' is NULL, packet was emitted locally.
 */
static void
dump_packet_from_to(struct dump *dump,
	const struct gnutella_node *from, const struct gnutella_node *to,
	const pmsg_t *mb)
{
	struct dump_header dh_to;	
	struct dump_header dh_from;	

	g_assert(to != NULL);
	g_assert(mb != NULL);
	g_assert(pmsg_read_base(mb) == pmsg_start(mb));

	if (!dump_initialize(dump))
		return;

	/*
	 * This is only for Gnutella packets, leave DHT messages out.
	 */

	if (GTA_MSG_DHT == gnutella_header_get_function(pmsg_start(mb)))
		return;

	if (!ipset_contains_addr(&dump_tx_to_addrs, to->addr, TRUE))
		return;

	if (NULL == from) {
		struct gnutella_node local;
		local.peermode = NODE_IS_UDP(to) ? NODE_P_UDP : NODE_P_NORMAL;
		local.addr = listen_addr();
		local.port = GNET_PROPERTY(listen_port);
		if (!ipset_contains_addr(&dump_tx_from_addrs, local.addr, TRUE))
			return;
		dump_header_set(&dh_from, &local);
	} else {
		if (!ipset_contains_addr(&dump_tx_from_addrs, from->addr, TRUE))
			return;
		dump_header_set(&dh_from, from);
	}

	dump_header_set(&dh_to, to);
	dh_to.data[0] |= DH_F_TO;
	if (pmsg_prio(mb) != PMSG_P_DATA)
		dh_to.data[0] |= DH_F_CTRL;
		
	dump_append(dump, dh_to.data, sizeof dh_to.data);
	dump_append(dump, dh_from.data, sizeof dh_from.data);
	dump_append(dump, pmsg_read_base(mb), pmsg_size(mb));
	dump_flush(dump);
}
Esempio n. 4
0
void dump_create_outdir(char * basedir) {
    char *buf;

    if (!dump_engine)
        return;

    if (threaded)
        pthread_mutex_lock(&dump_mutex);

    // store basedir to check when a new output directory is created
    if (log_basedir && strcmp(log_basedir, basedir) != 0) {
        dump_flush(TRUE);
        dir_counter = 0;
    }
    log_basedir = strdup(basedir);

    first_dump_tm.tv_sec = -1;
    first_dump_tm.tv_usec = -1;
    last_dump_tm.tv_sec = -1;
    last_dump_tm.tv_usec = -1;

    // compose the name of the directory...
    buf = sprintf_safe("%s/%s%02d", basedir, DUMP_DIR_BASENAME, dir_counter);
    if (outdir)
        free(outdir);
    outdir = MMmalloc(strlen(buf) + 1, "dump_create_outdir");
    memcpy(outdir, buf, strlen(buf) + 1);

    if (mkdir(outdir, 0777) != 0) {
        fprintf(fp_stderr, "dump engine err: error creating '%s'\n", outdir);
        exit(1);
    }
    fprintf(fp_stdout, "(%s) Creating output dir %s\n", Timestamp(), outdir);

    // ... and dumping log file
    buf = sprintf_safe("%s/%s", outdir, DUMP_LOG_FNAME);
    fp_log = fopen(buf, "w");
    if (fp_log == NULL) {
        fprintf(fp_stderr, "dump engine: error creating '%s'\n", buf);
        exit(1);
    }

    dir_counter++;

    if (threaded)
        pthread_mutex_unlock(&dump_mutex);
}
Esempio n. 5
0
/**
 * Dump packet received from node.
 */
static void
dump_packet_from(struct dump *dump, const struct gnutella_node *node)
{
	struct dump_header dh;	

	g_assert(node != NULL);

	if (!dump_initialize(dump))
		return;

	if (!ipset_contains_addr(&dump_rx_addrs, node->addr, TRUE))
		return;

	dump_header_set(&dh, node);
	dump_append(dump, dh.data, sizeof dh.data);
	dump_append(dump, node->header, sizeof node->header);
	dump_append(dump, node->data, node->size);
	dump_flush(dump);
}