1 /* 2 * Copyright (C) 2021-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 OHOS_DHCP_OPTION_H 17 #define OHOS_DHCP_OPTION_H 18 19 #include <stddef.h> 20 #include <stdint.h> 21 22 #define DHCP_OPTION_SIZE 256 23 #define DHCP_END_OPTION_CODE 255 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 typedef struct DhcpOption DhcpOption; 30 struct DhcpOption { 31 uint8_t code; 32 uint8_t length; 33 uint8_t data[DHCP_OPTION_SIZE]; 34 }; 35 typedef struct DhcpOption *PDhcpOption; 36 37 typedef struct DhcpOptionNode DhcpOptionNode; 38 struct DhcpOptionNode { 39 struct DhcpOptionNode *previous; 40 struct DhcpOptionNode *next; 41 DhcpOption option; 42 }; 43 typedef struct DhcpOptionNode *PDhcpOptionNode; 44 45 typedef struct DhcpOptionList DhcpOptionList; 46 struct DhcpOptionList { 47 PDhcpOptionNode first; 48 PDhcpOptionNode last; 49 size_t size; 50 }; 51 typedef struct DhcpOptionList *PDhcpOptionList; 52 53 int InitOptionList(PDhcpOptionList pOptions); 54 int HasInitialized(PDhcpOptionList pOptions); 55 int PushBackOption(PDhcpOptionList pOptions, PDhcpOption option); 56 int PushFrontOption(PDhcpOptionList pOptions, PDhcpOption option); 57 int RemoveOption(PDhcpOptionList pOptions, uint8_t code); 58 PDhcpOptionNode GetOptionNode(PDhcpOptionList pOptions, uint8_t code); 59 PDhcpOption GetOption(PDhcpOptionList pOptions, uint8_t code); 60 void ClearOptions(PDhcpOptionList pOptions); 61 void FreeOptionList(PDhcpOptionList pOptions); 62 int FillOption(PDhcpOption pOption, const char *data, size_t len); 63 int FillU32Option(PDhcpOption pOption, uint32_t u32); 64 int FillOptionData(PDhcpOption pOption, const uint8_t *data, size_t len); 65 int AppendAddressOption(PDhcpOption pOption, uint32_t address); 66 67 #ifdef __cplusplus 68 } 69 #endif 70 #endif 71