void tprintf_cleanup(void) { pthread_spin_lock(&buffer_lock); tprintf_flush(); pthread_spin_unlock(&buffer_lock); pthread_spin_destroy(&buffer_lock); }
/* * The main loop of the dissector. This is designed generic, so it doesn't * know the underlying linktype. */ static void dissector_main(uint8_t *packet, size_t len, struct protocol *start, struct protocol *end) { size_t off = 0; unsigned int key; struct hash_table *table; struct protocol *proto = start; while (proto != NULL) { len -= off; packet += off; if (unlikely(!proto->process)) break; off = proto->offset; if (!off) off = len; proto->process(packet, off); if (unlikely(!proto->proto_next)) break; proto->proto_next(packet, len, &table, &key, &off); if (unlikely(!table)) break; proto = lookup_hash(key, table); while (proto && key != proto->key) proto = proto->next; } len -= off; packet += off; if (end != NULL) if (likely(end->process)) end->process(packet, len); tprintf_flush(); }
void tprintf_cleanup(void) { spinlock_lock(&buffer_lock); tprintf_flush(); spinlock_unlock(&buffer_lock); spinlock_destroy(&buffer_lock); }
void dissector_entry_point(uint8_t *packet, size_t len, int linktype, int mode) { struct protocol *proto_start, *proto_end; struct pkt_buff *pkt = NULL; if (mode == PRINT_NONE) return; pkt = pkt_alloc(packet, len); switch (linktype) { case LINKTYPE_EN10MB: case ___constant_swab32(LINKTYPE_EN10MB): proto_start = dissector_get_ethernet_entry_point(); proto_end = dissector_get_ethernet_exit_point(); break; case LINKTYPE_IEEE802_11: case ___constant_swab32(LINKTYPE_IEEE802_11): proto_start = dissector_get_ieee80211_entry_point(); proto_end = dissector_get_ieee80211_exit_point(); break; default: panic("Linktype not supported!\n"); }; dissector_main(pkt, proto_start, proto_end); switch (mode) { case PRINT_HEX: hex(pkt); break; case PRINT_ASCII: ascii(pkt); break; case PRINT_HEX_ASCII: hex_ascii(pkt); break; } tprintf_flush(); pkt_free(pkt); }
void dissector_entry_point(uint8_t *packet, struct frame_map *hdr, int linktype, int mode, char **buffer_pkt, uint8_t *switch_filter, uint8_t *stats) { struct protocol *proto_start = NULL; struct protocol *proto_end = NULL; struct pkt_buff *pkt = NULL; if (mode == FNTTYPE_PRINT_NONE) return; pkt = pkt_alloc(packet, hdr->tp_h.tp_snaplen); switch (linktype) { case LINKTYPE_EN10MB: proto_start = dissector_get_ethernet_entry_point(); proto_end = dissector_get_ethernet_exit_point(); break; default: panic("Linktype not supported!\n"); }; dissector_main(pkt, proto_start, proto_end, buffer_pkt, switch_filter, stats); switch (mode) { case FNTTYPE_PRINT_HEX: hex(pkt); break; case FNTTYPE_PRINT_ASCII: ascii(pkt); break; case FNTTYPE_PRINT_HEX_ASCII: hex_ascii(pkt); break; } tprintf_flush(); pkt_free(pkt); }
void tprintf(char *msg, ...) { int ret; va_list vl; va_start(vl, msg); pthread_spin_lock(&buffer_lock); ret = vsnprintf(buffer + buffer_use, sizeof(buffer) - buffer_use, msg, vl); if (ret < 0) /* Something screwed up! Unexpected. */ goto out; if (ret >= sizeof(buffer) - buffer_use) { tprintf_flush(); /* Rewrite the buffer */ ret = vsnprintf(buffer + buffer_use, sizeof(buffer) - buffer_use, msg, vl); /* Again, we've failed! This shouldn't happen! So * switch to vfprintf temporarily :-( */ if (ret >= sizeof(buffer) - buffer_use) { fprintf(stderr, "BUG (buffer too large) -->\n"); vfprintf(stdout, msg, vl); fprintf(stderr, " <--\n"); goto out; } } if (ret < sizeof(buffer) - buffer_use) buffer_use += ret; out: pthread_spin_unlock(&buffer_lock); va_end(vl); }