/**
 * Prints a string representation of IpfixRecord::Data to stdout.
 */
void printFieldData(IpfixRecord::FieldInfo::Type type, IpfixRecord::Data* pattern) {
	char* s;
	timeval t;
	uint64_t hbnum;

	switch (type.id) {
	case IPFIX_TYPEID_protocolIdentifier:
		printf("protocolIdentifier: ");
		printProtocol(type, pattern);
		break;
	case IPFIX_TYPEID_sourceIPv4Address:
		printf("sourceIPv4Address: ");
		printIPv4(type, pattern);
		break;
	case IPFIX_TYPEID_destinationIPv4Address:
		printf("destinationIPv4Address: ");
		printIPv4(type, pattern);
		break;
	case IPFIX_TYPEID_sourceTransportPort:
		printf("sourceTransportPort: ");
		printPort(type, pattern);
		break;
	case IPFIX_TYPEID_destinationTransportPort:
		printf("destinationTransportPort: ");
		printPort(type, pattern);
		break;
	case IPFIX_TYPEID_flowStartNanoSeconds:
	case IPFIX_TYPEID_flowEndNanoSeconds:
	case IPFIX_ETYPEID_revFlowStartNanoSeconds:
	case IPFIX_ETYPEID_revFlowEndNanoSeconds:
		printf("%s: ", typeid2string(type.id));
		hbnum = ntohll(*(uint64_t*)pattern);
		if (hbnum>0) {
			t = timentp64(*((ntp64*)(&hbnum)));
			printf("%d.%06d seconds", (int32_t)t.tv_sec, (int32_t)t.tv_usec);
		} else {
			printf("no value (only zeroes in field)");
		}
		break;
	case IPFIX_ETYPEID_frontPayload:
	case IPFIX_ETYPEID_revFrontPayload:
		printf("%s: ", typeid2string(type.id));
		printFrontPayload(type, pattern);
		break;
	default:
		s = typeid2string(type.id);
		if (s != NULL) {
			printf("%s: ", s);
			printUint(type, pattern);
		} else {
			DPRINTF("Field with ID %d unparseable\n", type.id);
		}
		break;
	}
}
Esempio n. 2
0
/**
 * Prints a string representation of IpfixRecord::Data to stdout.
 */
void PrintHelpers::printFieldData(InformationElement::IeInfo type, IpfixRecord::Data* pattern) {

	timeval t;
	uint64_t hbnum;
	string typeStr = type.toString();

	// try to get the values aligned
	if (typeStr.length() < 60)
		fprintf(fh, "%-60s: ", type.toString().c_str());
	else
		fprintf(fh, "%s: ", type.toString().c_str());

	switch (type.enterprise) {
		case 0:
			switch (type.id) {
				case IPFIX_TYPEID_protocolIdentifier:
					printProtocol(type, pattern);
					return;
				case IPFIX_TYPEID_sourceIPv4Address:
					printIPv4(type, pattern);
					return;
				case IPFIX_TYPEID_destinationIPv4Address:
					printIPv4(type, pattern);
					return;
				case IPFIX_TYPEID_sourceTransportPort:
					printPort(type, pattern);
					return;
				case IPFIX_TYPEID_destinationTransportPort:
					printPort(type, pattern);
					return;
				case IPFIX_TYPEID_flowStartSeconds:
				case IPFIX_TYPEID_flowEndSeconds:
				case IPFIX_TYPEID_flowStartMilliSeconds:
				case IPFIX_TYPEID_flowEndMilliSeconds:
				case PSAMP_TYPEID_observationTimeSeconds:
					printLocaltime(type, pattern);
					return;
				case IPFIX_TYPEID_flowStartNanoSeconds:
				case IPFIX_TYPEID_flowEndNanoSeconds:
					hbnum = ntohll(*(uint64_t*)pattern);
					if (hbnum>0) {
						t = timentp64(*((ntp64*)(&hbnum)));
						fprintf(fh, "%u.%06d seconds", (int32_t)t.tv_sec, (int32_t)t.tv_usec);
					} else {
						fprintf(fh, "no value (only zeroes in field)");
					}
					return;
			}
			break;

		case IPFIX_PEN_reverse:
			switch (type.id) {
				case IPFIX_TYPEID_flowStartNanoSeconds:
				case IPFIX_TYPEID_flowEndNanoSeconds:
					hbnum = ntohll(*(uint64_t*)pattern);
					if (hbnum>0) {
						t = timentp64(*((ntp64*)(&hbnum)));
						fprintf(fh, "%u.%06d seconds", (int32_t)t.tv_sec, (int32_t)t.tv_usec);
					} else {
						fprintf(fh, "no value (only zeroes in field)");
					}
					return;
			}
			break;

		default:
		{
			if (type==InformationElement::IeInfo(IPFIX_ETYPEID_frontPayload, IPFIX_PEN_vermont) ||
				type==InformationElement::IeInfo(IPFIX_ETYPEID_frontPayload, IPFIX_PEN_vermont|IPFIX_PEN_reverse)) {
				printFrontPayload(type, pattern);
				return;
			}
		}
	}

	printUint(type, pattern);
}