ti->scopeInfo[scopeNo].typeX.id = ntoh(*(uint16*)((byte*)record+0)); ti->scopeInfo[scopeNo].typeX.length = ntoh(*(uint16*)((byte*)record+2)); ti->scopeInfo[scopeNo].offset = bt->recordLength; bt->recordLength+=ti->scopeInfo[scopeNo].typeX.length; if (ti->scopeInfo[scopeNo].typeX.length == 65535) lengthVarying=true; if (ti->scopeInfo[scopeNo].typeX.id & 0x80) { ti->scopeInfo[scopeNo].typeX.eid = ntoh(*(uint32*)((byte*)record+4));
ti->scopeInfo[scopeNo].type.id = ntohs(*(uint16_t*)((byte*)record+0)); ti->scopeInfo[scopeNo].type.length = ntohs(*(uint16_t*)((byte*)record+2)); ti->scopeInfo[scopeNo].offset = bt->recordLength; bt->recordLength+=ti->scopeInfo[scopeNo].type.length; if (ti->scopeInfo[scopeNo].type.length == 65535) isLengthVarying=1; if (ti->scopeInfo[scopeNo].type.id & 0x80) { ti->scopeInfo[scopeNo].type.eid = ntohl(*(uint32_t*)((byte*)record+4));
static void processOptionsTemplateSet(SourceID sourceId, IpfixSetHeader* set) {	IpfixOptionsTemplateHeader* th = (IpfixOptionsTemplateHeader*)&set->data;	byte* endOfSet = (byte*)set + ntoh(set->length);	byte* record = (byte*)&th->data;	/* OptionsTemplateSets are >= 4 byte, so we stop processing when only 3 bytes are left */	while (record < endOfSet - 3) {		BufferedTemplate* bt = (BufferedTemplate*)malloc(sizeof(BufferedTemplate));		OptionsTemplateInfo* ti = (OptionsTemplateInfo*)malloc(sizeof(OptionsTemplateInfo));		bt->sourceID = sourceId;		bt->templateID = ntoh(th->templateId);		bt->recordLength = 0;		bt->setID = ntoh(set->id);		bt->optionsTemplateInfo = ti;		bt->optionsTemplateDestructionCallbackFunction = optionsTemplateDestructionCallbackFunction;		ti->userData = 0;		ti->scopeCount = ntoh(th->scopeCount);		ti->scopeInfo = (FieldInfo*)malloc(ti->scopeCount * sizeof(FieldInfo));		ti->fieldCount = ntoh(th->fieldCount)-ntoh(th->scopeCount);		ti->fieldInfo = (FieldInfo*)malloc(ti->fieldCount * sizeof(FieldInfo));		boolean lengthVarying = false;		uint16 scopeNo;		for (scopeNo = 0; scopeNo < ti->scopeCount; scopeNo++) {			ti->scopeInfo[scopeNo].typeX.id = ntoh(*(uint16*)((byte*)record+0));			ti->scopeInfo[scopeNo].typeX.length = ntoh(*(uint16*)((byte*)record+2));			ti->scopeInfo[scopeNo].offset = bt->recordLength; bt->recordLength+=ti->scopeInfo[scopeNo].typeX.length;			if (ti->scopeInfo[scopeNo].typeX.length == 65535) lengthVarying=true;			if (ti->scopeInfo[scopeNo].typeX.id & 0x80) {				ti->scopeInfo[scopeNo].typeX.eid = ntoh(*(uint32*)((byte*)record+4));				record = (byte*)((byte*)record+8);				} else {				ti->fieldInfo[scopeNo].typeX.eid = 0;				record = (byte*)((byte*)record+4);				}			}		uint16 fieldNo;		for (fieldNo = 0; fieldNo < ti->fieldCount; fieldNo++) {			ti->fieldInfo[fieldNo].typeX.id = ntoh(*(uint16*)((byte*)record+0));			ti->fieldInfo[fieldNo].typeX.length = ntoh(*(uint16*)((byte*)record+2));			ti->fieldInfo[fieldNo].offset = bt->recordLength; bt->recordLength+=ti->fieldInfo[fieldNo].typeX.length;			if (ti->fieldInfo[fieldNo].typeX.length == 65535) lengthVarying=true;			if (ti->fieldInfo[fieldNo].typeX.id & 0x80) {				ti->fieldInfo[fieldNo].typeX.eid = ntoh(*(uint32*)((byte*)record+4));				record = (byte*)((byte*)record+8);				} else {				ti->fieldInfo[fieldNo].typeX.eid = 0;				record = (byte*)((byte*)record+4);				}			}		if (lengthVarying) {  			bt->recordLength = 65535;			for (fieldNo = 0; fieldNo < ti->scopeCount; fieldNo++) ti->scopeInfo[fieldNo].offset = 65535;			for (fieldNo = 0; fieldNo < ti->fieldCount; fieldNo++) ti->fieldInfo[fieldNo].offset = 65535;  			}		bufferTemplate(bt); bt->expires = time(0) + TEMPLATE_EXPIRE_SECS;		if (optionsTemplateCallbackFunction != 0) {			optionsTemplateCallbackFunction(sourceId, ti);			}  		}	}