• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #ifndef OHOS_DHCPC_H
16 #define OHOS_DHCPC_H
17 
18 #include <pthread.h>
19 
20 #include "dhcp_define.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #ifdef OHOS_EUPDATER
27 #define WORKDIR                 "/tmp/service/el1/public/dhcp/"
28 #else
29 #define WORKDIR                 "/data/service/el1/public/dhcp/"
30 #endif // OHOS_EUPDATER
31 
32 #define DHCPC_NAME              "dhcp_client_service"
33 #define DHCPC_CONF              "dhcp_client_service.conf"
34 #define DHCPC_PID               "dhcp_client_service.pid"
35 #define DHCPC_VERSION           "1.0"
36 #define DHCPC_LEASE             "dhcp_client_service-%s.lease"
37 
38 enum DHCP_IP_TYPE {
39     DHCP_IP_TYPE_NONE =  0,
40     DHCP_IP_TYPE_ALL  =  1,
41     DHCP_IP_TYPE_V4   =  2,
42     DHCP_IP_TYPE_V6   =  3
43 };
44 
45 struct DhcpClientCfg {
46     char workDir[DIR_MAX_LEN];              /* Current process working directory. */
47     char confFile[DIR_MAX_LEN];             /* Current process Configuration Directory. */
48     char pidFile[DIR_MAX_LEN];              /* Current process pid file. */
49     char resultFile[DIR_MAX_LEN];           /* Save the obtained IPv4 result. */
50     char ifaceName[INFNAME_SIZE];           /* Name of the network interface used by the current process. */
51     int  ifaceIndex;                        /* Index of the network interface used by the current process. */
52     unsigned int ifaceIpv4;                 /* IPv4 of the network interface used by the current process. */
53     unsigned int getMode;                   /* Current process obtaining IPv4 address mode. */
54     unsigned char ifaceMac[MAC_ADDR_LEN];   /* Mac addr of the network interface used by the current process. */
55     unsigned char *pOptClientId;            /* DHCP packet options field clientid. */
56     bool timeoutExit;                       /* DHCP packet sending times out and exits automatically. */
57     char leaseFile[DIR_MAX_LEN];
58     char result6File[DIR_MAX_LEN];
59     pthread_t thrId;
60     pid_t parentProcessId;
61 };
62 
63 int StartProcess(void);
64 int StopProcess(const char *pidFile);
65 int GetProStatus(const char *pidFile);
66 void *CheckParentProcessIsExist(void *arg);
67 
68 struct DhcpClientCfg *GetDhcpClientCfg(void);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 #endif
74