本文整理汇总了C++中IpAddress::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ IpAddress::isValid方法的具体用法?C++ IpAddress::isValid怎么用?C++ IpAddress::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IpAddress
的用法示例。
在下文中一共展示了IpAddress::isValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connect
void TcpClient::connect(const IpAddress& address, NetPort port, const Duration& timeout, const Duration& pause)
{
Expect(address.isValid(), Throw(InvalidParameter, "Invalid IpAddress"));
Expect(port != NetPort_Any, Throw(InvalidParameter, "Invalid NetPort"));
int ret;
Clock clock;
Socket::create(address.getProtocol());
prv::SockAddrBuffer buffer(address, port);
clock.start();
do
{
ret = ::connect(getHandler(), buffer.getSockAddr(), buffer.getLength());
if(ret != 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<long long>(pause.asMilliseconds())));
}
}while(ret != 0 && clock.getElapsedTime() < timeout);
Expect(ret == 0, Throw(InternalError, "Failed to connect to the remote host"));
}
示例2: lookup_from_ip_with_arp_table
MacAddress MacAddress::lookup_from_ip_with_arp_table(const IpAddress& ipAddress,
bool ping) {
if(!ipAddress.isValid()) {
return MacAddress();
}
char line[500];
char ip_address[500];
int hw_type;
int flags;
char mac_address[500];
char mask[500];
char device[500];
MacAddress foundMac;
if (ping) {
ipAddress.ping(1000);
}
// ARP Table Reading Suggestion From
// http://stackoverflow.com/a/21031888
FILE *fp = fopen("/proc/net/arp", "r");
fgets(line, sizeof(line), fp); // Skip the first line (column headers).
while(fgets(line, sizeof(line), fp)) {
sscanf(line, "%s 0x%x 0x%x %s %s %s\n",
ip_address,
&hw_type,
&flags,
mac_address,
mask,
device);
if (ipAddress.toString().compare(ip_address) == 0) {
foundMac = MacAddress(mac_address);
break;
}
}
fclose(fp);
return foundMac;
}