Skip to content

Commit e4f2652

Browse files
authored
Updated RemoteDeviceList and PfRingDeviceList's getDevice API to match the rest. (#1810)
* Updated PcapRemoteDeviceList to `getDeviceBy` API. * Updated PfRingDeviceList to `getDevice` api * Lint
1 parent 7a4e165 commit e4f2652

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

Pcap++/header/PcapRemoteDeviceList.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,45 @@ namespace pcpp
140140
/// Search a PcapRemoteDevice in the list by its IPv4 address
141141
/// @param[in] ip4Addr The IPv4 address
142142
/// @return The PcapRemoteDevice if found, nullptr otherwise
143+
PCPP_DEPRECATED("Use `getDeviceByIp`")
143144
PcapRemoteDevice* getRemoteDeviceByIP(const IPv4Address& ip4Addr) const;
144145

146+
/// Search a PcapRemoteDevice in the list by its IPv4 address
147+
/// @param[in] ip4Addr The IPv4 address
148+
/// @return The PcapRemoteDevice if found, nullptr otherwise
149+
PcapRemoteDevice* getDeviceByIP(const IPv4Address& ip4Addr) const;
150+
145151
/// Search a PcapRemoteDevice in the list by its IPv6 address
146152
/// @param[in] ip6Addr The IPv6 address
147153
/// @return The PcapRemoteDevice if found, nullptr otherwise
154+
PCPP_DEPRECATED("Use `getDeviceByIp`")
148155
PcapRemoteDevice* getRemoteDeviceByIP(const IPv6Address& ip6Addr) const;
149156

157+
/// Search a PcapRemoteDevice in the list by its IPv6 address
158+
/// @param[in] ip6Addr The IPv6 address
159+
/// @return The PcapRemoteDevice if found, nullptr otherwise
160+
PcapRemoteDevice* getDeviceByIP(const IPv6Address& ip6Addr) const;
161+
150162
/// Search a PcapRemoteDevice in the list by its IP address (IPv4 or IPv6)
151163
/// @param[in] ipAddr The IP address
152164
/// @return The PcapRemoteDevice if found, nullptr otherwise
165+
PCPP_DEPRECATED("Use `getDeviceByIp`")
153166
PcapRemoteDevice* getRemoteDeviceByIP(const IPAddress& ipAddr) const;
154167

168+
/// Search a PcapRemoteDevice in the list by its IP address (IPv4 or IPv6)
169+
/// @param[in] ipAddr The IP address
170+
/// @return The PcapRemoteDevice if found, nullptr otherwise
171+
PcapRemoteDevice* getDeviceByIP(const IPAddress& ipAddr) const;
172+
155173
/// Search a PcapRemoteDevice in the list by its IP address
156174
/// @param[in] ipAddrAsString The IP address in string format
157175
/// @return The PcapRemoteDevice if found, nullptr otherwise
176+
PCPP_DEPRECATED("Use `getDeviceByIp`")
158177
PcapRemoteDevice* getRemoteDeviceByIP(const std::string& ipAddrAsString) const;
178+
179+
/// Search a PcapRemoteDevice in the list by its IP address
180+
/// @param[in] ipAddrAsString The IP address in string format
181+
/// @return The PcapRemoteDevice if found, nullptr otherwise
182+
PcapRemoteDevice* getDeviceByIP(const std::string& ipAddrAsString) const;
159183
};
160184
} // namespace pcpp

Pcap++/header/PfRingDeviceList.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ namespace pcpp
4848
/// Get a PF_RING device by name. The name is the Linux interface name which appears in ifconfig
4949
/// (e.g eth0, eth1, etc.)
5050
/// @return A pointer to the PF_RING device
51+
PCPP_DEPRECATED("Use `getDeviceByName`")
5152
PfRingDevice* getPfRingDeviceByName(const std::string& devName) const;
5253

54+
/// Get a PF_RING device by name. The name is the Linux interface name which appears in ifconfig
55+
/// (e.g eth0, eth1, etc.)
56+
/// @return A pointer to the PF_RING device
57+
PfRingDevice* getDeviceByName(const std::string& devName) const;
58+
5359
/// Get installed PF_RING version
5460
/// @return A string representing PF_RING version
5561
std::string getPfRingVersion() const

Pcap++/src/PcapRemoteDeviceList.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ namespace pcpp
122122
}
123123

124124
PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const std::string& ipAddrAsString) const
125+
{
126+
return getDeviceByIP(ipAddrAsString);
127+
}
128+
129+
PcapRemoteDevice* PcapRemoteDeviceList::getDeviceByIP(const std::string& ipAddrAsString) const
125130
{
126131
IPAddress ipAddr;
127132

@@ -135,23 +140,33 @@ namespace pcpp
135140
return nullptr;
136141
}
137142

138-
PcapRemoteDevice* result = getRemoteDeviceByIP(ipAddr);
143+
PcapRemoteDevice* result = getDeviceByIP(ipAddr);
139144
return result;
140145
}
141146

142147
PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPAddress& ipAddr) const
148+
{
149+
return getDeviceByIP(ipAddr);
150+
}
151+
152+
PcapRemoteDevice* PcapRemoteDeviceList::getDeviceByIP(const IPAddress& ipAddr) const
143153
{
144154
if (ipAddr.getType() == IPAddress::IPv4AddressType)
145155
{
146-
return getRemoteDeviceByIP(ipAddr.getIPv4());
156+
return getDeviceByIP(ipAddr.getIPv4());
147157
}
148158
else // IPAddress::IPv6AddressType
149159
{
150-
return getRemoteDeviceByIP(ipAddr.getIPv6());
160+
return getDeviceByIP(ipAddr.getIPv6());
151161
}
152162
}
153163

154164
PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPv4Address& ip4Addr) const
165+
{
166+
return getDeviceByIP(ip4Addr);
167+
}
168+
169+
PcapRemoteDevice* PcapRemoteDeviceList::getDeviceByIP(const IPv4Address& ip4Addr) const
155170
{
156171
auto it = std::find_if(m_DeviceList.begin(), m_DeviceList.end(), [&ip4Addr](PcapRemoteDevice const* devPtr) {
157172
auto devIP = devPtr->getIPv4Address();
@@ -161,6 +176,11 @@ namespace pcpp
161176
}
162177

163178
PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPv6Address& ip6Addr) const
179+
{
180+
return getDeviceByIP(ip6Addr);
181+
}
182+
183+
PcapRemoteDevice* PcapRemoteDeviceList::getDeviceByIP(const IPv6Address& ip6Addr) const
164184
{
165185
auto it = std::find_if(m_DeviceList.begin(), m_DeviceList.end(), [&ip6Addr](PcapRemoteDevice const* devPtr) {
166186
auto devIP = devPtr->getIPv6Address();

Pcap++/src/PfRingDeviceList.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ namespace pcpp
111111
}
112112

113113
PfRingDevice* PfRingDeviceList::getPfRingDeviceByName(const std::string& devName) const
114+
{
115+
return getDeviceByName(devName);
116+
}
117+
118+
PfRingDevice* PfRingDeviceList::getDeviceByName(const std::string& devName) const
114119
{
115120
PCPP_LOG_DEBUG("Searching all live devices...");
116121
auto devIter = std::find_if(m_DeviceList.begin(), m_DeviceList.end(),

0 commit comments

Comments
 (0)