Skip to content

Commit 8c011e0

Browse files
bukeporestyled-commitsandy31415
authored
Only use kMaxIfNameLength instead of IFNAMSIZ (#37859)
* Only use kMaxIfNameLength instead of IFNAMSIZ I encountered IFNAMSIZ is not defined when doing some porting. I think it's better to use the unified definition for network interface name in this project. * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Andrei Litvin <andy314@gmail.com>
1 parent 7c581bc commit 8c011e0

17 files changed

+30
-29
lines changed

src/platform/Darwin/DnssdHostNameRegistrar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void LogDetails(InetInterfacesVector inetInterfaces, Inet6InterfacesVector inet6
154154

155155
for (auto interfaceId : interfaceIds)
156156
{
157-
char interfaceName[IFNAMSIZ] = {};
157+
char interfaceName[chip::Inet::InterfaceId::kMaxIfNameLength] = {};
158158
if_indextoname(interfaceId, interfaceName);
159159
ChipLogProgress(Discovery, "\t%s (%u)", interfaceName, interfaceId);
160160
LogDetails(interfaceId, inetInterfaces, inet6Interfaces);

src/platform/Darwin/NetworkCommissioningDriver.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class DarwinNetworkIterator : public NetworkIterator
4848
void Release() override { delete this; }
4949

5050
protected:
51-
size_t mInterfaceCount = 0;
52-
char mInterfaceName[IFNAMSIZ] = {};
53-
bool mInterfaceStatus = false;
51+
size_t mInterfaceCount = 0;
52+
char mInterfaceName[chip::Inet::InterfaceId::kMaxIfNameLength] = {};
53+
bool mInterfaceStatus = false;
5454
};
5555

5656
class DarwinEthernetNetworkIterator final : public DarwinNetworkIterator

src/platform/Darwin/WiFi/ConnectivityManagerImplWiFi.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
bool status = false;
8080

8181
if (_GetWiFiStationMode() == kWiFiStationMode_Enabled) {
82-
char interfaceName[IFNAMSIZ];
82+
char interfaceName[chip::Inet::InterfaceId::kMaxIfNameLength];
8383
VerifyOrReturnError(CHIP_NO_ERROR == GetWiFiInterfaceName(interfaceName, sizeof(interfaceName)), false);
8484
VerifyOrReturnError(CHIP_NO_ERROR == GetInterfaceStatus(interfaceName, &status), false);
8585
}

src/platform/Linux/ConfigurationManagerImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
143143
{
144144
if ((addr->ifa_addr) && (addr->ifa_addr->sa_family == AF_PACKET))
145145
{
146-
if (strncmp(addr->ifa_name, CHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME, IFNAMSIZ) == 0)
146+
if (strncmp(addr->ifa_name, CHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME, chip::Inet::InterfaceId::kMaxIfNameLength) == 0)
147147
{
148148
mac = (struct sockaddr_ll *) addr->ifa_addr;
149149
break;
150150
}
151151

152-
if (strncmp(addr->ifa_name, "lo", IFNAMSIZ) != 0 && !mac)
152+
if (strncmp(addr->ifa_name, "lo", chip::Inet::InterfaceId::kMaxIfNameLength) != 0 && !mac)
153153
{
154154
mac = (struct sockaddr_ll *) addr->ifa_addr;
155155
}

src/platform/Linux/ConnectivityManagerImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
110110
mpConnectCallback = nullptr;
111111
mpScanCallback = nullptr;
112112

113-
if (ConnectivityUtils::GetEthInterfaceName(mEthIfName, IFNAMSIZ) == CHIP_NO_ERROR)
113+
if (ConnectivityUtils::GetEthInterfaceName(mEthIfName, chip::Inet::InterfaceId::kMaxIfNameLength) == CHIP_NO_ERROR)
114114
{
115115
ChipLogProgress(DeviceLayer, "Got Ethernet interface: %s", mEthIfName);
116116
}
@@ -131,7 +131,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
131131
#endif
132132

133133
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
134-
if (ConnectivityUtils::GetWiFiInterfaceName(sWiFiIfName, IFNAMSIZ) == CHIP_NO_ERROR)
134+
if (ConnectivityUtils::GetWiFiInterfaceName(sWiFiIfName, chip::Inet::InterfaceId::kMaxIfNameLength) == CHIP_NO_ERROR)
135135
{
136136
ChipLogProgress(DeviceLayer, "Got WiFi interface: %s", sWiFiIfName);
137137
}

src/platform/Linux/ConnectivityManagerImpl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
289289

290290
// ===== Private members reserved for use by this class only.
291291

292-
char mEthIfName[IFNAMSIZ];
292+
char mEthIfName[chip::Inet::InterfaceId::kMaxIfNameLength];
293293

294294
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
295295
ConnectivityManager::WiFiStationMode mWiFiStationMode;
@@ -301,7 +301,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
301301
#endif
302302

303303
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
304-
char sWiFiIfName[IFNAMSIZ];
304+
char sWiFiIfName[chip::Inet::InterfaceId::kMaxIfNameLength];
305305
#endif
306306

307307
#if CHIP_DEVICE_CONFIG_ENABLE_WPA

src/platform/Linux/PlatformManagerImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ gboolean WiFiIPChangeListener(GIOChannel * ch, GIOCondition /* condition */, voi
100100
{
101101
if (routeInfo->rta_type == IFA_LOCAL)
102102
{
103-
char name[IFNAMSIZ];
103+
char name[chip::Inet::InterfaceId::kMaxIfNameLength];
104104
if (if_indextoname(addressMessage->ifa_index, name) == nullptr)
105105
{
106106
ChipLogError(DeviceLayer, "Error %d when getting the interface name at index: %d", errno,

src/platform/NuttX/ConfigurationManagerImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
143143
{
144144
if ((addr->ifa_addr) && (addr->ifa_addr->sa_family == AF_PACKET))
145145
{
146-
if (strncmp(addr->ifa_name, CHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME, IFNAMSIZ) == 0)
146+
if (strncmp(addr->ifa_name, CHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME, chip::Inet::InterfaceId::kMaxIfNameLength) == 0)
147147
{
148148
mac = (struct sockaddr_ll *) addr->ifa_addr;
149149
break;
150150
}
151151

152-
if (strncmp(addr->ifa_name, "lo", IFNAMSIZ) != 0 && !mac)
152+
if (strncmp(addr->ifa_name, "lo", chip::Inet::InterfaceId::kMaxIfNameLength) != 0 && !mac)
153153
{
154154
mac = (struct sockaddr_ll *) addr->ifa_addr;
155155
}

src/platform/NuttX/ConnectivityManagerImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
107107
mpConnectCallback = nullptr;
108108
mpScanCallback = nullptr;
109109

110-
if (ConnectivityUtils::GetEthInterfaceName(mEthIfName, IFNAMSIZ) == CHIP_NO_ERROR)
110+
if (ConnectivityUtils::GetEthInterfaceName(mEthIfName, chip::Inet::InterfaceId::kMaxIfNameLength) == CHIP_NO_ERROR)
111111
{
112112
ChipLogProgress(DeviceLayer, "Got Ethernet interface: %s", mEthIfName);
113113
}
@@ -128,7 +128,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
128128
#endif
129129

130130
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
131-
if (ConnectivityUtils::GetWiFiInterfaceName(sWiFiIfName, IFNAMSIZ) == CHIP_NO_ERROR)
131+
if (ConnectivityUtils::GetWiFiInterfaceName(sWiFiIfName, chip::Inet::InterfaceId::kMaxIfNameLength) == CHIP_NO_ERROR)
132132
{
133133
ChipLogProgress(DeviceLayer, "Got WiFi interface: %s", sWiFiIfName);
134134
}

src/platform/NuttX/ConnectivityManagerImpl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
248248

249249
// ===== Private members reserved for use by this class only.
250250

251-
char mEthIfName[IFNAMSIZ];
251+
char mEthIfName[chip::Inet::InterfaceId::kMaxIfNameLength];
252252

253253
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
254254
ConnectivityManager::WiFiStationMode mWiFiStationMode;
@@ -260,7 +260,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
260260
#endif
261261

262262
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
263-
char sWiFiIfName[IFNAMSIZ];
263+
char sWiFiIfName[chip::Inet::InterfaceId::kMaxIfNameLength];
264264
#endif
265265

266266
#if CHIP_DEVICE_CONFIG_ENABLE_WPA

src/platform/NuttX/PlatformManagerImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ gboolean WiFiIPChangeListener(GIOChannel * ch, GIOCondition /* condition */, voi
9999
{
100100
if (routeInfo->rta_type == IFA_LOCAL)
101101
{
102-
char name[IFNAMSIZ];
102+
char name[chip::Inet::InterfaceId::kMaxIfNameLength];
103103
if (if_indextoname(addressMessage->ifa_index, name) == nullptr)
104104
{
105105
ChipLogError(DeviceLayer, "Error %d when getting the interface name at index: %d", errno,

src/platform/Tizen/ConnectivityManagerImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
7272
{
7373
CHIP_ERROR err = CHIP_NO_ERROR;
7474

75-
if (ConnectivityUtils::GetEthInterfaceName(mEthIfName, IFNAMSIZ) == CHIP_NO_ERROR)
75+
if (ConnectivityUtils::GetEthInterfaceName(mEthIfName, chip::Inet::InterfaceId::kMaxIfNameLength) == CHIP_NO_ERROR)
7676
{
7777
ChipLogProgress(DeviceLayer, "Got Ethernet interface: %s", mEthIfName);
7878
}
@@ -92,7 +92,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
9292

9393
Internal::WiFiMgr().Init();
9494

95-
if (ConnectivityUtils::GetWiFiInterfaceName(sWiFiIfName, IFNAMSIZ) == CHIP_NO_ERROR)
95+
if (ConnectivityUtils::GetWiFiInterfaceName(sWiFiIfName, chip::Inet::InterfaceId::kMaxIfNameLength) == CHIP_NO_ERROR)
9696
{
9797
ChipLogProgress(DeviceLayer, "Got WiFi interface: %s", sWiFiIfName);
9898
}

src/platform/Tizen/ConnectivityManagerImpl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
134134

135135
// ===== Private members reserved for use by this class only.
136136

137-
char mEthIfName[IFNAMSIZ];
137+
char mEthIfName[chip::Inet::InterfaceId::kMaxIfNameLength];
138138

139139
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
140140
ConnectivityManager::WiFiStationMode mWiFiStationMode;
@@ -143,7 +143,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
143143
System::Clock::Timestamp mLastAPDemandTime;
144144
System::Clock::Timeout mWiFiStationReconnectInterval;
145145
System::Clock::Timeout mWiFiAPIdleTimeout;
146-
static char sWiFiIfName[IFNAMSIZ];
146+
static char sWiFiIfName[chip::Inet::InterfaceId::kMaxIfNameLength];
147147
#endif
148148
};
149149

src/platform/webos/ConfigurationManagerImpl.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
133133
VerifyOrExit(getifaddrs(&addresses) == 0, error = CHIP_ERROR_INTERNAL);
134134
for (auto addr = addresses; addr != nullptr; addr = addr->ifa_next)
135135
{
136-
if ((addr->ifa_addr) && (addr->ifa_addr->sa_family == AF_PACKET) && strncmp(addr->ifa_name, "lo", IFNAMSIZ) != 0)
136+
if ((addr->ifa_addr) && (addr->ifa_addr->sa_family == AF_PACKET) &&
137+
strncmp(addr->ifa_name, "lo", chip::Inet::InterfaceId::kMaxIfNameLength) != 0)
137138
{
138139
struct sockaddr_ll * mac = (struct sockaddr_ll *) addr->ifa_addr;
139140
memcpy(buf, mac->sll_addr, mac->sll_halen);

src/platform/webos/ConnectivityManagerImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
9393
mpConnectCallback = nullptr;
9494
mpScanCallback = nullptr;
9595

96-
if (ConnectivityUtils::GetEthInterfaceName(mEthIfName, IFNAMSIZ) == CHIP_NO_ERROR)
96+
if (ConnectivityUtils::GetEthInterfaceName(mEthIfName, chip::Inet::InterfaceId::kMaxIfNameLength) == CHIP_NO_ERROR)
9797
{
9898
ChipLogProgress(DeviceLayer, "Got Ethernet interface: %s", mEthIfName);
9999
}
@@ -114,7 +114,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
114114
#endif
115115

116116
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
117-
if (ConnectivityUtils::GetWiFiInterfaceName(sWiFiIfName, IFNAMSIZ) == CHIP_NO_ERROR)
117+
if (ConnectivityUtils::GetWiFiInterfaceName(sWiFiIfName, chip::Inet::InterfaceId::kMaxIfNameLength) == CHIP_NO_ERROR)
118118
{
119119
ChipLogProgress(DeviceLayer, "Got WiFi interface: %s", sWiFiIfName);
120120
}

src/platform/webos/ConnectivityManagerImpl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
231231

232232
// ===== Private members reserved for use by this class only.
233233

234-
char mEthIfName[IFNAMSIZ];
234+
char mEthIfName[chip::Inet::InterfaceId::kMaxIfNameLength];
235235

236236
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
237237
ConnectivityManager::WiFiStationMode mWiFiStationMode;
@@ -243,7 +243,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
243243
#endif
244244

245245
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
246-
static char sWiFiIfName[IFNAMSIZ];
246+
static char sWiFiIfName[chip::Inet::InterfaceId::kMaxIfNameLength];
247247
#endif
248248

249249
static NetworkCommissioning::WiFiDriver::ScanCallback * mpScanCallback;

src/platform/webos/PlatformManagerImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void PlatformManagerImpl::WiFiIPChangeListener()
103103
{
104104
if (routeInfo->rta_type == IFA_LOCAL)
105105
{
106-
char name[IFNAMSIZ];
106+
char name[chip::Inet::InterfaceId::kMaxIfNameLength];
107107
if (if_indextoname(addressMessage->ifa_index, name) == nullptr)
108108
{
109109
ChipLogError(DeviceLayer, "Error %d when getting the interface name at index: %d", errno,

0 commit comments

Comments
 (0)