本文整理汇总了C++中address::optlevel方法的典型用法代码示例。如果您正苦于以下问题:C++ address::optlevel方法的具体用法?C++ address::optlevel怎么用?C++ address::optlevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类address
的用法示例。
在下文中一共展示了address::optlevel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: _McastListenNewAPI
int _McastListenNewAPI(int sock, const address &grpaddr) {
_loc_group_req grp;
memset(&grp, 0, sizeof(grp));
grp.gr_interface = mcastInterface;
set_address(grp.gr_group, grpaddr);
return setsockopt(sock, grpaddr.optlevel(), MCAST_JOIN_GROUP, &grp, sizeof(grp));
}
示例3: SSMJoinLeave
static int SSMJoinLeave(int sock, int type, const address &grpaddr, const address &srcaddr) {
_loc_group_source_req req;
memset(&req, 0, sizeof(req));
req.gsr_interface = mcastInterface;
set_address(req.gsr_group, grpaddr);
set_address(req.gsr_source, srcaddr);
return setsockopt(sock, srcaddr.optlevel(), type, &req, sizeof(req));
}
示例4: 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;
}