1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DHCP_FUZZ_COMMON_FUNC_H 17 #define DHCP_FUZZ_COMMON_FUNC_H 18 19 #include <cstdint> 20 21 namespace OHOS { 22 namespace DHCP { 23 constexpr int U32_BYTE0_SHIFT = 24; 24 constexpr int U32_BYTE1_SHIFT = 16; 25 constexpr int U32_BYTE2_SHIFT = 8; 26 constexpr int U32_BYTE3_SHIFT = 0; 27 constexpr int U16_BYTE0_SHIFT = 8; 28 constexpr int U16_BYTE1_SHIFT = 0; 29 constexpr int U32_BYTE0_INDEX = 0; 30 constexpr int U32_BYTE1_INDEX = 1; 31 constexpr int U32_BYTE2_INDEX = 2; 32 constexpr int U32_BYTE3_INDEX = 3; 33 constexpr int U16_BYTE0_INDEX = 0; 34 constexpr int U16_BYTE1_INDEX = 1; 35 U32_AT(const uint8_t * data)36inline uint32_t U32_AT(const uint8_t* data) 37 { 38 if (data == nullptr) { 39 return 0; 40 } 41 return (static_cast<uint32_t>(data[U32_BYTE0_INDEX]) << U32_BYTE0_SHIFT) | 42 (static_cast<uint32_t>(data[U32_BYTE1_INDEX]) << U32_BYTE1_SHIFT) | 43 (static_cast<uint32_t>(data[U32_BYTE2_INDEX]) << U32_BYTE2_SHIFT) | 44 (static_cast<uint32_t>(data[U32_BYTE3_INDEX]) << U32_BYTE3_SHIFT); 45 } U16_AT(const uint8_t * data)46inline uint16_t U16_AT(const uint8_t* data) 47 { 48 if (data == nullptr) { 49 return 0; 50 } 51 return (static_cast<uint16_t>(data[U16_BYTE0_INDEX]) << U16_BYTE0_SHIFT) | 52 (static_cast<uint16_t>(data[U16_BYTE1_INDEX]) << U16_BYTE1_SHIFT); 53 } 54 } // namespace DHCP 55 } // namespace OHOS 56 #endif 57 58