本文整理汇总了C++中IPAddress::str方法的典型用法代码示例。如果您正苦于以下问题:C++ IPAddress::str方法的具体用法?C++ IPAddress::str怎么用?C++ IPAddress::str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPAddress
的用法示例。
在下文中一共展示了IPAddress::str方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openTcp
bool Socket::openTcp(const IPAddress& host, int port, int flags)
{
#ifndef NDEBUG
setLoggingPrefix("Socket(tcp:%s:%d)", host.str().c_str(), port);
#endif
flags |= O_NONBLOCK | O_CLOEXEC;
int typeMask = 0;
#if defined(SOCK_NONBLOCK)
if (flags & O_NONBLOCK) {
flags &= ~O_NONBLOCK;
typeMask |= SOCK_NONBLOCK;
}
#endif
#if defined(SOCK_CLOEXEC)
if (flags & O_CLOEXEC) {
flags &= ~O_CLOEXEC;
typeMask |= SOCK_CLOEXEC;
}
#endif
fd_ = ::socket(host.family(), SOCK_STREAM | typeMask, IPPROTO_TCP);
if (fd_ < 0) {
TRACE("socket creation error: %s", strerror(errno));
return false;
}
if (flags) {
if (fcntl(fd_, F_SETFL, fcntl(fd_, F_GETFL) | flags) < 0) {
// error
}
}
int rv = ::connect(fd_, (struct sockaddr*) host.data(), host.size());
if (rv == 0) {
TRACE("connect: instant success (fd:%d)", fd_);
state_ = Operational;
return true;
} else if (/*rv < 0 &&*/ errno == EINPROGRESS) {
TRACE("connect: backgrounding (fd:%d)", fd_);
state_ = Connecting;
setMode(Write);
return true;
} else {
TRACE("could not connect to %s:%d: %s", host.str().c_str(), port, strerror(errno));
::close(fd_);
fd_ = -1;
return false;
}
}
示例2: ip
// Test subnet mask calculations
TEST_P(IPAddressMaskTest, Masks) {
auto param = GetParam();
IPAddress ip(param.address);
IPAddress masked = ip.mask(param.mask);
EXPECT_EQ(param.subnet, masked.str())
<< param.address << "/" << folly::to<std::string>(param.mask) << " -> "
<< param.subnet;
}
示例3: addAddress
void TunIntf::addAddress(const IPAddress& addr, uint8_t mask) {
auto ret = addrs_.emplace(addr, mask);
if (!ret.second) {
throw FbossError("Duplication interface address ", addr, "/",
static_cast<int>(mask), " for interface ", name_,
" @ index", ifIndex_);
}
VLOG(3) << "Added address " << addr.str() << "/"
<< static_cast<int>(mask) << " to interface " << name_
<< " @ index " << ifIndex_;
}
示例4: addProbedAddr
void TunManager::addProbedAddr(int ifIndex, const IPAddress& addr,
uint8_t mask) {
for (auto& intf : intfs_) {
if (intf.second->getIfIndex() == ifIndex) {
intf.second->addAddress(addr, mask);
return;
}
}
// This function is called for all interface addresses discovered from
// the host. Since we only create TunIntf object for TUN interfaces,
// it is normal we cannot find the interface matching the ifIndex provided.
VLOG(3) << "Cannot find interface @ index " << ifIndex
<< " for probed address " << addr.str() << "/"
<< static_cast<int>(mask);
}
示例5: toAppend
void toAppend(IPAddress addr, fbstring* result) {
result->append(addr.str());
}