本文整理汇总了C++中ConstString::addString方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstString::addString方法的具体用法?C++ ConstString::addString怎么用?C++ ConstString::addString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConstString
的用法示例。
在下文中一共展示了ConstString::addString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getHostName
//.........这里部分代码省略.........
String ip = ips[i].get_host_addr();
if (ip==name) {
result = true;
break;
}
}
delete[] ips;
}
#else
/**
* If this does not work properly, use a more sophisticated way
* instead of just gethostname.
*/
char hostname[NI_MAXHOST]; hostname[NI_MAXHOST-1] = '\0';
gethostname(hostname, NI_MAXHOST);
if (strcmp(hostname, name.c_str()) == 0) result = true;
#endif
// just in case
if (name=="localhost"||name=="127.0.0.1") { result = true; }
return result;
}
yarp::os::Bottle NameConfig::getIpsAsBottle() {
yarp::os::Bottle result;
#ifdef YARP_HAS_ACE
ACE_INET_Addr *ips = NULL;
size_t count = 0;
if (ACE::get_ip_interfaces(count,ips)>=0) {
for (size_t i=0; i<count; i++) {
String ip = ips[i].get_host_addr();
result.addString(ip.c_str());
}
delete[] ips;
}
#else
int family, s;
char host[NI_MAXHOST];
struct ifaddrs *ifaddr, *ifa;
if (getifaddrs(&ifaddr) == -1) {
perror("getifaddrs in getIpsAsBottle");
exit(EXIT_FAILURE);
}
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL) continue;
family = ifa->ifa_addr->sa_family;
if (family == AF_INET || family == AF_INET6) {
s = getnameinfo(ifa->ifa_addr,
(family == AF_INET) ? sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6),
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if (s != 0) {
printf("getnameinfo() failed: %s\n", gai_strerror(s));
exit(EXIT_FAILURE);
}
result.addString(host);
}
}
#endif
return result;
}