static NOINLINE int Read32(tiff* p) { int v; if (p->BigEndian) v = LOAD32BE(p->Ptr); else v = LOAD32LE(p->Ptr); p->Ptr += 4; return v; }
error_t dhcpDumpInt32(const DhcpOption *option) { uint32_t value; //Check option length if(option->length != 4) return ERROR_INVALID_OPTION; //Retrieve 32-bit value value = LOAD32BE(option->value); //Dump option contents TRACE_DEBUG(" %" PRIu32 "\r\n", value); //No error to report return NO_ERROR; }
error_t lcpDumpOptions(const PppOption *option, size_t length) { uint32_t value; //Parse options while(length > 0) { //Malformed LCP packet? if(length < sizeof(PppOption)) return ERROR_INVALID_LENGTH; //Check option length if(option->length < sizeof(PppOption)) return ERROR_INVALID_LENGTH; if(option->length > length) return ERROR_INVALID_LENGTH; //Display the name of the current option if(option->type < arraysize(lcpOptionLabel)) TRACE_DEBUG(" %s option (%" PRIu8 " bytes)\r\n", lcpOptionLabel[option->type], option->length); else TRACE_DEBUG(" Option %" PRIu8 " (%" PRIu8 " bytes)\r\n", option->type, option->length); //Check option code switch(option->type) { //16-bit unsigned value? case LCP_OPTION_MRU: //Check length field if(option->length != (sizeof(PppOption) + sizeof(uint16_t))) return ERROR_INVALID_OPTION; //Retrieve 16-bit value value = LOAD16BE(option->data); //Dump option contents TRACE_DEBUG(" %" PRIu32 "\r\n", value); break; //32-bit unsigned value? case LCP_OPTION_ACCM: case LCP_OPTION_MAGIC_NUMBER: //Check length field if(option->length != (sizeof(PppOption) + sizeof(uint32_t))) return ERROR_INVALID_OPTION; //Retrieve 32-bit value value = LOAD32BE(option->data); //Dump option contents TRACE_DEBUG(" 0x%08" PRIX32 "\r\n", value); break; //Raw data? default: //Dump option contents TRACE_DEBUG_ARRAY(" ", option->data, option->length - sizeof(PppOption)); break; } //Remaining bytes to process length -= option->length; //Jump to the next option option = (PppOption *) ((uint8_t *) option + option->length); } //No error to report return NO_ERROR; }