Exemplo n.º 1
0
/**
 * \brief Conversion of unsigned int
 */
const char *Translator::toUnsigned(uint16_t length, uint16_t *ret_len, uint8_t *data_record,
	uint16_t offset, const ipfix_element_t * element, struct json_conf * config)
{
	// Calculate the length of returned string here to avoid unnecessary strlen later
	const char *ret = NULL;
	*ret_len = 0;

	if(length == BYTE1) {
		// 1 byte
		if(element->en == 0 && element->id == 6 && config->tcpFlags) {
			// Formated TCP flags
			ret = formatFlags8(read8(data_record + offset));
			*ret_len = 8;
			return ret;
		} else if (element->en == 0 && element->id == 4 && !config->protocol) {
			// Formated protocol identification (TCP, UDP, ICMP,...)
			ret =  (formatProtocol(read8(data_record + offset)));
			*ret_len = strlen(ret);
			return ret;
		} else {
			// Other elements
			ret = u32toa_branchlut2(read8(data_record + offset), buffer);
		}
	} else if(length == BYTE2) {
		// 2 bytes
		if (element->en == 0 && element->id == 6 && config->tcpFlags) {
			// Formated TCP flags
			ret = formatFlags16(read16(data_record + offset));
			*ret_len = 8;
			return ret;
		} else {
			// Other elements
			ret = u32toa_branchlut2(ntohs(read16(data_record + offset)), buffer);
		}
	} else if(length == BYTE4) {
		// 4 bytes
		ret = u32toa_branchlut2(ntohl(read32(data_record + offset)), buffer);
	} else if(length == BYTE8) {
		// 8 bytes
 		ret = u64toa_branchlut2(be64toh(read64(data_record + offset)), buffer);
	} else {
		// Other sizes
		*ret_len = snprintf(buffer, BUFF_SIZE, "%s", "\"unknown\"");
		return buffer;
	}

	*ret_len = ret - buffer;
	return buffer;
}
Exemplo n.º 2
0
/**
 * \brief Conversion of unsigned int
 */
const char *Translator::toUnsigned(uint16_t *length, uint8_t *data_record, uint16_t offset, const ipfix_element_t * element, struct json_conf * config)
{
	if(*length == BYTE1) {
		// 1 byte
		if(element->en == 0 && element->id == 6 && config->tcpFlags) {
			// Formated TCP flags
			return formatFlags8(read8(data_record + offset));
		} else if (element->en == 0 && element->id == 4 && !config->protocol) {
			// Formated protocol identification (TCP, UDP, ICMP,...)
			return (formatProtocol(read8(data_record + offset)));
		} else {
			// Other elements
			snprintf(buffer, BUFF_SIZE, "%" PRIu8, read8(data_record + offset));
		}
	} else if(*length == BYTE2) {
		// 2 bytes
		if (element->en == 0 && element->id == 6 && config->tcpFlags) {
			// Formated TCP flags
			return formatFlags16(read16(data_record + offset));
		} else {
			// Other elements
			snprintf(buffer, BUFF_SIZE, "%" PRIu16, ntohs(read16(data_record + offset)));
		}
	} else if(*length == BYTE4) {
		// 4 bytes
		snprintf(buffer, BUFF_SIZE, "%" PRIu32, ntohl(read32(data_record + offset)));
	} else if(*length == BYTE8) {
		// 8 bytes
		snprintf(buffer, BUFF_SIZE, "%" PRIu64, be64toh(read64(data_record + offset)));
	} else {
		// Other sizes
		snprintf(buffer, BUFF_SIZE, "%s", "\"unknown\"");
	}

	return buffer;
}