1 /*
2 * Copyright (C) 2023 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 "net_interface_callback.h"
17 #include "mdns_manager.h"
18
19 #include <algorithm>
20 #include <sys/types.h>
21 #include <unistd.h>
22
23 namespace OHOS {
24 namespace NetManagerStandard {
NetInterfaceStateCallback()25 NetInterfaceStateCallback::NetInterfaceStateCallback() {}
26
OnInterfaceAddressUpdated(const std::string & addr,const std::string & ifName,int32_t flags,int32_t scope)27 int32_t NetInterfaceStateCallback::OnInterfaceAddressUpdated(const std::string &addr, const std::string &ifName,
28 int32_t flags, int32_t scope)
29 {
30 NETMGR_EXT_LOG_D("mdns_log OnInterfaceAddressUpdated, addr:[%{public}s], iface:[%{public}s], scope:[%{public}d]",
31 addr.c_str(), ifName.c_str(), scope);
32
33 std::string ifrName = ifName;
34 std::transform(ifrName.begin(), ifrName.end(), ifrName.begin(), ::tolower);
35 if (ifrName.find("p2p") != std::string::npos) {
36 NETMGR_EXT_LOG_D("mdns_log Not p2p netcard handle");
37 return NETMANAGER_SUCCESS;
38 }
39
40 MDnsManager::GetInstance().RestartMDnsProtocolImpl();
41 return NETMANAGER_SUCCESS;
42 }
43
OnInterfaceAddressRemoved(const std::string & addr,const std::string & ifName,int32_t flags,int32_t scope)44 int32_t NetInterfaceStateCallback::OnInterfaceAddressRemoved(const std::string &addr, const std::string &ifName,
45 int32_t flags, int32_t scope)
46 {
47 NETMGR_EXT_LOG_D("mdns_log OnInterfaceAddressRemoved, addr:[%{public}s], iface:[%{public}s], scope:[%{public}d]",
48 addr.c_str(), ifName.c_str(), scope);
49 return NETMANAGER_SUCCESS;
50 }
51
OnInterfaceAdded(const std::string & ifName)52 int32_t NetInterfaceStateCallback::OnInterfaceAdded(const std::string &ifName)
53 {
54 NETMGR_EXT_LOG_D("mdns_log OnInterfaceAdded, iface:[%{public}s]", ifName.c_str());
55 return NETMANAGER_SUCCESS;
56 }
57
OnInterfaceRemoved(const std::string & ifName)58 int32_t NetInterfaceStateCallback::OnInterfaceRemoved(const std::string &ifName)
59 {
60 NETMGR_EXT_LOG_D("mdns_log OnInterfaceRemoved, iface:[%{public}s]", ifName.c_str());
61 return NETMANAGER_SUCCESS;
62 }
63
OnInterfaceChanged(const std::string & ifName,bool up)64 int32_t NetInterfaceStateCallback::OnInterfaceChanged(const std::string &ifName, bool up)
65 {
66 NETMGR_EXT_LOG_D("mdns_log OnInterfaceChanged, iface:[%{public}s]->Up:[%{public}d]", ifName.c_str(), up);
67 return NETMANAGER_SUCCESS;
68 }
69
OnInterfaceLinkStateChanged(const std::string & ifName,bool up)70 int32_t NetInterfaceStateCallback::OnInterfaceLinkStateChanged(const std::string &ifName, bool up)
71 {
72 NETMGR_EXT_LOG_D("mdns_log OnInterfaceLinkStateChanged, iface:[%{public}s]->Up:[%{public}d]", ifName.c_str(), up);
73 return NETMANAGER_SUCCESS;
74 }
75 } // namespace NetManagerStandard
76 } // namespace OHOS