コード例 #1
0
ファイル: udpdump.c プロジェクト: alagoutte/wireshark
static int dump_packet(const char* proto_name, const guint16 listenport, const char* buf,
		const ssize_t buflen, const struct sockaddr_in clientaddr, FILE* fp)
{
	char* mbuf;
	guint offset = 0;
	time_t curtime = time(NULL);
	guint64 bytes_written = 0;
	int err;
	int ret = EXIT_SUCCESS;

	/* The space we need is the standard header + variable lengths */
	mbuf = (char*)g_malloc0(UDPDUMP_EXPORT_HEADER_LEN + ((strlen(proto_name) + 3) & 0xfffffffc) + buflen);

	add_proto_name(mbuf, &offset, proto_name);
	add_ip_source_address(mbuf, &offset, clientaddr.sin_addr.s_addr);
	add_ip_dest_address(mbuf, &offset, WS_IN4_LOOPBACK);
	add_udp_source_port(mbuf, &offset, clientaddr.sin_port);
	add_udp_dst_port(mbuf, &offset, listenport);
	add_end_options(mbuf, &offset);

	memcpy(mbuf + offset, buf, buflen);
	offset += (guint)buflen;

	if (!libpcap_write_packet(fp, curtime, (guint32)(curtime / 1000), offset, offset, mbuf, &bytes_written, &err)) {
		g_warning("Can't write packet");
		ret = EXIT_FAILURE;
	}

	fflush(fp);

	g_free(mbuf);
	return ret;
}
コード例 #2
0
ファイル: ciscodump.c プロジェクト: wireshark/wireshark
static void ssh_loop_read(ssh_channel channel, FILE* fp, const guint32 count)
{
	char line[SSH_READ_BLOCK_SIZE];
	char chr;
	unsigned offset = 0;
	unsigned packet_size = 0;
	guint8* packet;
	time_t curtime = time(NULL);
	int err;
	guint64 bytes_written;
	long unsigned packets = 0;
	int status = CISCODUMP_PARSER_STARTING;

	/* This is big enough to put on the heap */
	packet = (guint8*)g_malloc(PACKET_MAX_SIZE);

	do {
		if (ssh_channel_read_timeout(channel, &chr, 1, FALSE, SSH_READ_TIMEOUT) == SSH_ERROR) {
			g_warning("Error reading from channel");
			g_free(packet);
			return;
		}

		if (chr != '\n') {
			line[offset] = chr;
			offset++;
		} else {
			/* Parse the current line */
			line[offset] = '\0';
			status = parse_line(packet, &packet_size, line, status);

			if (status == CISCODUMP_PARSER_END_PACKET) {
				/* dump the packet to the pcap file */
				if (!libpcap_write_packet(fp, curtime, (guint32)(curtime / 1000), packet_size,
						packet_size, packet, &bytes_written, &err)) {
					g_debug("Error in libpcap_write_packet(): %s", g_strerror(err));
					break;
				}
				g_debug("Dumped packet %lu size: %u", packets, packet_size);
				packet_size = 0;
				status = CISCODUMP_PARSER_STARTING;
				packets++;
			}
			offset = 0;
		}

	} while(packets < count);

	g_free(packet);
}
コード例 #3
0
ファイル: dpauxmon.c プロジェクト: wireshark/wireshark
static int dump_packet(FILE* fp, const char* buf, const guint32 buflen, guint64 ts_usecs)
{
	guint64 bytes_written = 0;
	int err;
	int ret = EXIT_SUCCESS;

	if (!libpcap_write_packet(fp, ts_usecs / 1000000, ts_usecs % 1000000, buflen, buflen, buf, &bytes_written, &err)) {
		g_warning("Can't write packet");
		ret = EXIT_FAILURE;
	}

	fflush(fp);

	return ret;
}