本文整理汇总了C++中address类的典型用法代码示例。如果您正苦于以下问题:C++ address类的具体用法?C++ address怎么用?C++ address使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了address类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: CountSSMLeave
static void CountSSMLeave(const address &group, const address &source) {
address source_addr;
char tmp[64], tmp2[64];
GroupMap::iterator g = groupMap.find(group);
assert(g != groupMap.end());
source_addr.set_family(source.family());
source_addr.copy_address(source);
source_addr.set_port(0);
SourceMap::iterator s = g->second.find(source_addr);
assert(s != g->second.end());
SourceSet::iterator ss = s->second.find(source);
if (ss == s->second.end()) {
return;
}
if (verbose)
info("Removing beacon %s from (%s, %s)", source.to_string(tmp, sizeof(tmp)),
source_addr.to_string(tmp2, sizeof(tmp2)),
group.to_string(tmp2, sizeof(tmp2)));
s->second.erase(ss);
if (s->second.empty()) {
if (verbose)
info("No more beacons for (%s, %s), leaving group",
source_addr.to_string(tmp, sizeof(tmp)),
group.to_string(tmp2, sizeof(tmp2)));
SSMLeave(ssmMcastSock,group, source_addr);
g->second.erase(s);
}
if (g->second.empty()) {
if (verbose)
info("No more sources, unregistering group %s, ", group.to_string(tmp, sizeof(tmp)));
groupMap.erase(g);
}
}
开发者ID:ConsortiumGARR,项目名称:dbeacon,代码行数:34,代码来源:dbeacon.cpp
示例2: access
int ip_filter::access(address const& addr) const
{
if (addr.is_v4())
return m_filter4.access(addr.to_v4());
assert(addr.is_v6());
return m_filter6.access(addr.to_v6());
}
开发者ID:Sukumi,项目名称:python-libtorrent,代码行数:7,代码来源:ip_filter.cpp
示例3: CountSSMJoin
static void CountSSMJoin(const address &group, const address &source) {
address source_addr;
char tmp[64], tmp2[64], tmp3[64];
source_addr.set_family(source.family());
source_addr.copy_address(source);
source_addr.set_port(0);
GroupMap::iterator g = groupMap.find(group);
if (g == groupMap.end()) {
if (verbose)
info("Registering SSM group %s", group.to_string(tmp, sizeof(tmp)));
g = groupMap.insert(std::make_pair(group, SourceMap())).first;
}
SourceMap::iterator s = g->second.find(source_addr);
if (s == g->second.end()) {
if (verbose)
info("Joining (%s, %s)", source_addr.to_string(tmp, sizeof(tmp)),
group.to_string(tmp2, sizeof(tmp2)));
if (SSMJoin(ssmMcastSock, group, source_addr) < 0) {
if (verbose)
info("Join failed, reason: %s", strerror(errno));
return;
} else {
s = g->second.insert(std::make_pair(source_addr, SourceSet())).first;
}
}
SourceSet::iterator ss = s->second.find(source);
if (ss == s->second.end()) {
if (verbose)
info("Adding beacon %s to (%s, %s)", source.to_string(tmp, sizeof(tmp)),
source_addr.to_string(tmp2, sizeof(tmp2)),
group.to_string(tmp3, sizeof(tmp3)));
s->second.insert(source);
}
}
开发者ID:ConsortiumGARR,项目名称:dbeacon,代码行数:35,代码来源:dbeacon.cpp
示例4: send_report
int send_report(int type) {
int len;
len = build_report(buffer, bufferLen, type == SSM_REPORT ? STATS_REPORT : type, true);
if (len < 0)
return len;
int res;
if (type == SSM_REPORT) {
if ((res = sendto(mcastSock, buffer, len, 0, ssmProbeAddr.saddr(), ssmProbeAddr.addrlen())) < 0)
d_log(LOG_DEBUG, "Failed to send SSM report: %s", strerror(errno));
else
bytesSent += res;
} else {
for (vector<address>::const_iterator i = redist.begin();
i != redist.end(); ++i) {
char tmp[64];
if (verbose)
d_log(LOG_DEBUG, "Sending Report to %s",
i->to_string(tmp, sizeof(tmp)));
if ((res = sendto(mcastSock, buffer, len, 0, i->saddr(),
i->addrlen())) < 0)
d_log(LOG_DEBUG, "Failed to send report to %s: %s",
i->to_string(tmp, sizeof(tmp)), strerror(errno));
else
bytesSent += res;
}
}
return 0;
}
开发者ID:ConsortiumGARR,项目名称:dbeacon,代码行数:34,代码来源:dbeacon.cpp
示例5: external_address
address external_ip::external_address(address const& ip) const
{
address ext = m_vote_group[ip.is_v6()].external_address();
#if TORRENT_USE_IPV6
if (ip.is_v6() && ext == address_v4()) return address_v6();
#endif
return ext;
}
开发者ID:EricMyers47,项目名称:OpenSpace,代码行数:8,代码来源:ip_voter.cpp
示例6: find
// private
hosts::iterator hosts::find(const address& host)
{
const auto found = [&host](const address& entry)
{
return entry.port() == host.port() && entry.ip() == host.ip();
};
return std::find_if(buffer_.begin(), buffer_.end(), found);
}
开发者ID:pmienk,项目名称:libbitcoin-network,代码行数:10,代码来源:hosts.cpp
示例7: is_equal
bool address::is_equal(const address &a) const {
if (stor.ss_family != a.stor.ss_family)
return false;
if (stor.ss_family == AF_INET6)
return memcmp(&v6()->sin6_addr, &a.v6()->sin6_addr, sizeof(in6_addr)) == 0;
else if (stor.ss_family == AF_INET)
return v4()->sin_addr.s_addr == a.v4()->sin_addr.s_addr;
return false;
}
开发者ID:teask,项目名称:dbeacon,代码行数:9,代码来源:dbeacon_posix.cpp
示例8: time_now
tcp::endpoint utp_socket_manager::local_endpoint(address const& remote, error_code& ec) const
{
tcp::endpoint socket_ep = m_sock.local_endpoint(ec);
// first enumerate the routes in the routing table
if (time_now() - m_last_route_update > seconds(60))
{
m_last_route_update = time_now();
error_code ec;
m_routes = enum_routes(m_sock.get_io_service(), ec);
if (ec) return socket_ep;
}
if (m_routes.empty()) return socket_ep;
// then find the best match
ip_route* best = &m_routes[0];
for (std::vector<ip_route>::iterator i = m_routes.begin()
, end(m_routes.end()); i != end; ++i)
{
if (is_any(i->destination) && i->destination.is_v4() == remote.is_v4())
{
best = &*i;
continue;
}
if (match_addr_mask(remote, i->destination, i->netmask))
{
best = &*i;
continue;
}
}
// best now tells us which interface we would send over
// for this target. Now figure out what the local address
// is for that interface
if (time_now() - m_last_if_update > seconds(60))
{
m_last_if_update = time_now();
error_code ec;
m_interfaces = enum_net_interfaces(m_sock.get_io_service(), ec);
if (ec) return socket_ep;
}
for (std::vector<ip_interface>::iterator i = m_interfaces.begin()
, end(m_interfaces.end()); i != end; ++i)
{
if (i->interface_address.is_v4() != remote.is_v4())
continue;
if (strcmp(best->name, i->name) == 0)
return tcp::endpoint(i->interface_address, socket_ep.port());
}
return socket_ep;
}
开发者ID:ABuus,项目名称:libtorrent,代码行数:55,代码来源:utp_socket_manager.cpp
示例9: copy_address
bool address::copy_address(const address &source) {
if (family() != source.family())
return false;
if (stor.ss_family == AF_INET6)
v6()->sin6_addr = source.v6()->sin6_addr;
else
v4()->sin_addr = source.v4()->sin_addr;
return true;
}
开发者ID:teask,项目名称:dbeacon,代码行数:11,代码来源:dbeacon_posix.cpp
示例10: send_nprobe
static int send_nprobe(const address &addr, uint32_t &seq) {
int len;
len = build_probe(buffer, bufferLen, seq, get_time_of_day());
seq++;
len = sendto(mcastSock, buffer, len, 0, addr.saddr(), addr.addrlen());
if (len > 0)
bytesSent += len;
return len;
}
开发者ID:ConsortiumGARR,项目名称:dbeacon,代码行数:11,代码来源:dbeacon.cpp
示例11: in_subnet
bool in_subnet(address const& addr, ip_interface const& iface)
{
if (addr.is_v4() != iface.interface_address.is_v4()) return false;
// since netmasks seems unreliable for IPv6 interfaces
// (MacOS X returns AF_INET addresses as bitmasks) assume
// that any IPv6 address belongs to the subnet of any
// interface with an IPv6 address
if (addr.is_v6()) return true;
return (addr.to_v4().to_ulong() & iface.netmask.to_v4().to_ulong())
== (iface.interface_address.to_v4().to_ulong() & iface.netmask.to_v4().to_ulong());
}
开发者ID:Krinkelss,项目名称:libtorrent,代码行数:12,代码来源:enum_net.cpp
示例12: write_address
void write_address(address const& a, OutIt& out)
{
if (a.is_v4())
{
write_uint32(a.to_v4().to_ulong(), out);
}
else if (a.is_v6())
{
address_v6::bytes_type bytes
= a.to_v6().to_bytes();
std::copy(bytes.begin(), bytes.end(), out);
}
}
开发者ID:huyang819,项目名称:cdn-partner,代码行数:13,代码来源:socket.hpp
示例13: mask_address
address mask_address(const address& addrIn, uint8_t prefixLen) {
if (addrIn.is_v4()) {
prefixLen = std::min<uint8_t>(prefixLen, 32);
uint32_t mask = get_subnet_mask_v4(prefixLen);
return address_v4(addrIn.to_v4().to_ulong() & mask);
}
struct in6_addr mask;
struct in6_addr addr6;
prefixLen = std::min<uint8_t>(prefixLen, 128);
compute_ipv6_subnet(addrIn.to_v6(), prefixLen, &mask, &addr6);
address_v6::bytes_type data;
std::memcpy(data.data(), &addr6, sizeof(addr6));
return address_v6(data);
}
开发者ID:opendaylight,项目名称:opflex,代码行数:14,代码来源:Network.cpp
示例14: if
void utp_socket_manager::mtu_for_dest(address const& addr, int& link_mtu, int& utp_mtu)
{
int mtu = 0;
if (is_teredo(addr)) mtu = TORRENT_TEREDO_MTU;
else mtu = TORRENT_ETHERNET_MTU;
#if defined __APPLE__
// apple has a very strange loopback. It appears you can't
// send messages of the reported MTU size, and you don't get
// EWOULDBLOCK either.
if (is_loopback(addr))
{
if (is_teredo(addr)) mtu = TORRENT_TEREDO_MTU;
else mtu = TORRENT_ETHERNET_MTU;
}
#endif
// clamp the MTU within reasonable bounds
if (mtu < TORRENT_INET_MIN_MTU) mtu = TORRENT_INET_MIN_MTU;
else if (mtu > TORRENT_INET_MAX_MTU) mtu = TORRENT_INET_MAX_MTU;
link_mtu = mtu;
mtu -= TORRENT_UDP_HEADER;
if (m_sock.get_proxy_settings().type == settings_pack::socks5
|| m_sock.get_proxy_settings().type == settings_pack::socks5_pw)
{
// this is for the IP layer
address proxy_addr = m_sock.proxy_addr().address();
if (proxy_addr.is_v4()) mtu -= TORRENT_IPV4_HEADER;
else mtu -= TORRENT_IPV6_HEADER;
// this is for the SOCKS layer
mtu -= TORRENT_SOCKS5_HEADER;
// the address field in the SOCKS header
if (addr.is_v4()) mtu -= 4;
else mtu -= 16;
}
else
{
if (addr.is_v4()) mtu -= TORRENT_IPV4_HEADER;
else mtu -= TORRENT_IPV6_HEADER;
}
utp_mtu = (std::min)(mtu, restrict_mtu());
}
开发者ID:Jackarain,项目名称:libtorrent,代码行数:49,代码来源:utp_socket_manager.cpp
示例15: address_to_bytes
std::string address_to_bytes(address const& a)
{
#if LIBED2K_USE_IPV6
if (a.is_v6())
{
address_v6::bytes_type b = a.to_v6().to_bytes();
return std::string((char*)&b[0], b.size());
}
else
#endif
{
address_v4::bytes_type b = a.to_v4().to_bytes();
return std::string((char*)&b[0], b.size());
}
}
开发者ID:ST3ALth,项目名称:libed2k,代码行数:15,代码来源:socket_io.cpp
示例16: SetHops
bool SetHops(int sock, const address &addr, int ttl) {
if (addr.optlevel() == IPPROTO_IPV6) {
if (setsockopt(sock, addr.optlevel(), IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl)) != 0) {
return false;
}
} else {
TTLType _ttl = ttl;
if (setsockopt(sock, addr.optlevel(), IP_MULTICAST_TTL, &_ttl, sizeof(_ttl)) != 0) {
return false;
}
}
return true;
}
开发者ID:teask,项目名称:dbeacon,代码行数:15,代码来源:dbeacon_posix.cpp
示例17: equal
bool equal(const address& left, const address& right)
{
const auto left_addresses = left.addresses();
const auto right_addresses = right.addresses();
bool same = (left_addresses.size() == right_addresses.size());
for (size_t i = 0; (i < left_addresses.size()) && same; i++)
{
same = (left_addresses[i] == right_addresses[i])
&& (left_addresses[i].timestamp() == right_addresses[i].timestamp());
}
return same;
}
开发者ID:libbitcoin,项目名称:libbitcoin,代码行数:15,代码来源:address.cpp
示例18: sendto
int udp_socket::sendto(char const* msg, std::size_t len,
address const& addr)
{
return ::sendto(get_descriptor(*this), msg, len, 0,
reinterpret_cast<sockaddr const*>(addr.data()),
sizeof(sockaddr));
}
开发者ID:darka,项目名称:blahnet,代码行数:7,代码来源:udp_socket.cpp
示例19: address_cast
inline T address_cast(const address& addr,
typename enable_if<is_same<T, address_v6>::value>::type* = 0)
{
if (!addr.is_v6())
throw bad_address_cast();
return get_v6_helper(addr);
}
开发者ID:ChineseDr,项目名称:mongo,代码行数:7,代码来源:address.hpp
示例20: write_address
void write_address(address const& a, OutIt&& out)
{
#if TORRENT_USE_IPV6
if (a.is_v4())
{
#endif
write_uint32(a.to_v4().to_ulong(), out);
#if TORRENT_USE_IPV6
}
else if (a.is_v6())
{
for (auto b : a.to_v6().to_bytes())
write_uint8(b, out);
}
#endif
}
开发者ID:Chocobo1,项目名称:libtorrent,代码行数:16,代码来源:socket_io.hpp
注:本文中的address类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论