本文整理汇总了C++中address::is_multicast方法的典型用法代码示例。如果您正苦于以下问题:C++ address::is_multicast方法的具体用法?C++ address::is_multicast怎么用?C++ address::is_multicast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类address
的用法示例。
在下文中一共展示了address::is_multicast方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetupSocket
int SetupSocket(const address &addr, bool shouldbind, bool ssm) {
int af_family = addr.family();
int level = addr.optlevel();
int sock = socket(af_family, SOCK_DGRAM, 0);
if (sock < 0) {
perror("Failed to create multicast socket");
return -1;
}
int on = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) {
perror("setsockopt");
return -1;
}
if (shouldbind) {
if (bind(sock, addr.saddr(), addr.addrlen()) != 0) {
perror("Failed to bind multicast socket");
return -1;
}
}
#ifdef SO_TIMESTAMP
if (setsockopt(sock, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on)) != 0) {
perror("setsockopt(SO_TIMESTAMP)");
return -1;
}
#endif
int type = level == IPPROTO_IPV6 ?
#ifdef IPV6_RECVHOPLIMIT
IPV6_RECVHOPLIMIT
#else
IPV6_HOPLIMIT
#endif
:
#ifdef IP_RECVTTL
IP_RECVTTL;
#else
IP_TTL;
#endif
if (setsockopt(sock, level, type, &on, sizeof(on)) != 0) {
perror("receiving hop limit/ttl setsockopt()");
return -1;
}
if (!SetHops(sock, addr, defaultTTL)) {
perror("SetHops");
return -1;
}
if (!ssm && addr.is_multicast()) {
if (MulticastListen(sock, addr) != 0) {
perror("Failed to join multicast group");
return -1;
}
}
return sock;
}
示例2: main
int main(int argc, char **argv) {
int res;
srand(time(NULL));
char tmp[256];
if (gethostname(tmp, sizeof(tmp)) != 0) {
perror("Failed to get hostname");
return -1;
}
beaconName = tmp;
parse_arguments(argc, argv);
MulticastStartup();
if (beaconName.empty())
fatal("No name supplied, check `dbeacon -h`.");
if (!probeAddrLiteral.empty()) {
if (!probeAddr.parse(probeAddrLiteral.c_str(), true))
return -1;
probeAddr.to_string(sessionName, sizeof(sessionName));
if (!probeAddr.is_multicast())
fatal("Specified probe addr (%s) is not of a multicast group.",
sessionName);
if (adminContact.empty())
fatal("No administration contact supplied, check `dbeacon -h`.");
mcastListen.push_back(ContentDesc(probeAddr, false));
insert_event(SENDING_EVENT, 100);
insert_event(REPORT_EVENT, 10000);
insert_event(MAP_REPORT_EVENT, 30000);
insert_event(WEBSITE_REPORT_EVENT, 120000);
redist.push_back(probeAddr);
if (useSSM) {
if (probeSSMAddrLiteral.empty()) {
int family = forceFamily;
if (family == AF_UNSPEC) {
family = probeAddr.family();
}
if (family == AF_INET) {
probeSSMAddrLiteral = defaultIPv4SSMChannel;
} else {
probeSSMAddrLiteral = defaultIPv6SSMChannel;
}
}
if (!ssmProbeAddr.parse(probeSSMAddrLiteral.c_str(), true)) {
fatal("Bad address format for SSM channel.");
} else if (!ssmProbeAddr.is_unspecified()) {
insert_event(SSM_SENDING_EVENT, 100);
insert_event(SSM_REPORT_EVENT, 15000);
if (listenForSSM) {
mcastListen.push_back(ContentDesc(ssmProbeAddr, true));
}
}
}
} else {
if (mcastListen.empty())
fatal("Nothing to do, check `dbeacon -h`.");
else
strcpy(sessionName, beaconName.c_str());
}
address local;
local.set_family(probeAddr.family());
mcastSock = SetupSocket(local, false, false);
if (mcastSock < 0)
return -1;
if (beaconUnicastAddr.is_unspecified())
beaconUnicastAddr = get_local_address_for(probeAddr);
if (bind(mcastSock, beaconUnicastAddr.saddr(), beaconUnicastAddr.addrlen()) != 0) {
perror("Failed to bind local socket");
return -1;
}
if (beaconUnicastAddr.fromsocket(mcastSock) < 0) {
perror("getsockname");
return -1;
}
for (McastListen::const_iterator i = mcastListen.begin();
i != mcastListen.end(); ++i) {
int sock = SetupSocket(i->first, true, i->second);
if (sock < 0)
return -1;
//.........这里部分代码省略.........