/** * 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); }
/** * 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); }
/** * 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); }