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 #include <string>
17 
18 #ifndef OHOS_DHCP_ARGUMENT_H
19 #define OHOS_DHCP_ARGUMENT_H
20 
21 #define ARGUMENT_NAME_SIZE 32
22 #define ARGUMENT_VALUE_SIZE 256
23 #define INIT_ARGS_SIZE 4
24 
25 #define NO_ARG 0
26 #define REQUIRED_ARG 1
27 #define OPTIONAL_ARG 2
28 
29 #define USAGE_DESC_MAX_LENGTH 32
30 const std::string IP_V4_DEFAULT("192.168.62.1");
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct DhcpUsage DhcpUsage;
37 struct DhcpUsage {
38     struct option *opt;
39     const char *params;
40     const char *desc;
41     const char *example;
42     int required;
43     int (*dealOption)(const char *, const char *);
44 };
45 
46 
47 typedef struct ArgumentInfo ArgumentInfo;
48 struct ArgumentInfo {
49     char name[ARGUMENT_NAME_SIZE];
50     char value[ARGUMENT_VALUE_SIZE];
51 };
52 
53 int InitArguments(void);
54 int HasArgument(const char *argument);
55 ArgumentInfo *GetArgument(const char *name);
56 int PutArgument(const char *argument, const char *val);
57 
58 int ParseArguments(const std::string& ifName, const std::string& netMask, const std::string& ipRange,
59     const std::string& localIp);
60 
61 void FreeArguments(void);
62 
63 void ShowHelp(int argc);
64 
65 void PrintRequiredArguments(void);
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif // OHOS_DHCP_ARGUMENT_H
72