fatal("ipfix_end_template_set failed");
msg(MSG_FATAL, "ipfix_end_template_set failed");
int sndNewDataTemplate(void* ipfixSender_, SourceID sourceID, DataTemplateInfo* dataTemplateInfo) {	IpfixSender* ipfixSender = ipfixSender_;	ipfix_exporter* exporter = (ipfix_exporter*)ipfixSender->ipfixExporter;	if (!exporter) {		fatal("Exporter not set");		return -1;		}	uint16_t my_template_id = ++ipfixSender->lastTemplateId;	if (ipfixSender->lastTemplateId > 60000) {		/* FIXME: Does not always work, e.g. if more than 50000 new Templates per minute are created */		ipfixSender->lastTemplateId = 10000;		}	/* put Template ID in Template's userData */	int* p = (int*)malloc(sizeof(int));	*p = htons(my_template_id);	dataTemplateInfo->userData = p;		int i;	/* Count number of IPv4 fields with length 5 */		int splitFields = 0;	for (i = 0; i < dataTemplateInfo->fieldCount; i++) {		FieldInfo* fi = &dataTemplateInfo->fieldInfo[i];		if ((fi->type.id == IPFIX_TYPEID_sourceIPv4Address) && (fi->type.length == 5)) {			splitFields++;			}		else if ((fi->type.id == IPFIX_TYPEID_destinationIPv4Address) && (fi->type.length == 5)) {			splitFields++;			}		}	/* Count number of IPv4 fields with length 5 */		int splitFixedfields = 0;	for (i = 0; i < dataTemplateInfo->dataCount; i++) {		FieldInfo* fi = &dataTemplateInfo->dataInfo[i];		if ((fi->type.id == IPFIX_TYPEID_sourceIPv4Address) && (fi->type.length == 5)) {			splitFixedfields++;			}		else if ((fi->type.id == IPFIX_TYPEID_destinationIPv4Address) && (fi->type.length == 5)) {			splitFixedfields++;			}		}							if (0 != ipfix_start_datatemplate_set(exporter, my_template_id, dataTemplateInfo->fieldCount + splitFields, dataTemplateInfo->dataCount + splitFixedfields)) {		fatal("ipfix_start_datatemplate_set failed");		return -1;		}	for (i = 0; i < dataTemplateInfo->fieldCount; i++) {		FieldInfo* fi = &dataTemplateInfo->fieldInfo[i];				/* Split IPv4 fields with length 5, i.e. fields with network mask attached */		if ((fi->type.id == IPFIX_TYPEID_sourceIPv4Address) && (fi->type.length == 5)) {			ipfix_put_template_field(exporter, my_template_id, IPFIX_TYPEID_sourceIPv4Address, 4, 0);			ipfix_put_template_field(exporter, my_template_id, IPFIX_TYPEID_sourceIPv4Mask, 1, 0);			}		else if ((fi->type.id == IPFIX_TYPEID_destinationIPv4Address) && (fi->type.length == 5)) {			ipfix_put_template_field(exporter, my_template_id, IPFIX_TYPEID_destinationIPv4Address, 4, 0);			ipfix_put_template_field(exporter, my_template_id, IPFIX_TYPEID_destinationIPv4Mask, 1, 0);			}		else {			ipfix_put_template_field(exporter, my_template_id, fi->type.id, fi->type.length, fi->type.eid);			}		}	debugf("%d data fields", dataTemplateInfo->dataCount);		int dataLength = 0;	for (i = 0; i < dataTemplateInfo->dataCount; i++) {		FieldInfo* fi = &dataTemplateInfo->dataInfo[i];				dataLength += fi->type.length;				/* Split IPv4 fields with length 5, i.e. fields with network mask attached */		if ((fi->type.id == IPFIX_TYPEID_sourceIPv4Address) && (fi->type.length == 5)) {			ipfix_put_template_fixedfield(exporter, my_template_id, IPFIX_TYPEID_sourceIPv4Address, 4, 0);			ipfix_put_template_fixedfield(exporter, my_template_id, IPFIX_TYPEID_sourceIPv4Mask, 1, 0);			}		else if ((fi->type.id == IPFIX_TYPEID_destinationIPv4Address) && (fi->type.length == 5)) {			ipfix_put_template_fixedfield(exporter, my_template_id, IPFIX_TYPEID_destinationIPv4Address, 4, 0);			ipfix_put_template_fixedfield(exporter, my_template_id, IPFIX_TYPEID_destinationIPv4Mask, 1, 0);			}		else {			ipfix_put_template_fixedfield(exporter, my_template_id, fi->type.id, fi->type.length, fi->type.eid);			}		}		debugf("%d data length", dataLength);	char* data = (char*)malloc(dataLength);	memcpy(data, dataTemplateInfo->data, dataLength);	for (i = 0; i < dataTemplateInfo->fieldCount; i++) {		FieldInfo* fi = &dataTemplateInfo->fieldInfo[i];		/* Invert imask of IPv4 fields with length 5, i.e. fields with network mask attached */		if ((fi->type.id == IPFIX_TYPEID_sourceIPv4Address) && (fi->type.length == 5)) {			uint8_t* mask = (uint8_t*)(data + fi->offset + 4);			*mask = 32 - *mask;			}		else if ((fi->type.id == IPFIX_TYPEID_destinationIPv4Address) && (fi->type.length == 5)) {			uint8_t* mask = (uint8_t*)(data + fi->offset + 4);			*mask = 32 - *mask;			}		else {			}				}	if (0 != ipfix_put_template_data(exporter, my_template_id, data, dataLength)) {		fatal("ipfix_put_template_data failed");		return -1;		}	free(data);	if (0 != ipfix_end_template_set(exporter, my_template_id)) {		fatal("ipfix_end_template_set failed");		return -1;		}	return 0;	}