31#if defined(YARP_HAS_ACE)
32# include <ace/INET_Addr.h>
33# include <ace/Sock_Connect.h>
38#elif defined(__unix__) || defined(__APPLE__)
39# include <arpa/inet.h>
41# include <sys/socket.h>
48#define CONF_FILENAME YARP_CONFIG_FILENAME
54bool NameConfig::fromString(
const std::string& txt)
75 mode = b.
check(
"mode",
Value(
"yarp")).asString();
76 return (address.
getPort() != 0);
80 address =
Contact(
ss[0], yarp::conf::numeric::from_string<int>(
ss[1]));
111 std::string result = txt;
112 for (
char&
i : result) {
114 if (!((ch >=
'0' && ch <=
'9') || (ch >=
'A' && ch <=
'Z') || (ch >=
'a' && ch <=
'z'))) {
124 if (
stem ==
nullptr) {
131 if (space !=
"/root") {
145 if (
fin ==
nullptr) {
149 while (
fgets(buf,
sizeof(buf) - 1,
fin) !=
nullptr) {
161 if (!
fname.empty()) {
164 return fromString(txt);
174 if (!
fname.empty()) {
177 std::string
m = (!mode.empty()) ? mode :
"yarp";
199 if (
fout ==
nullptr) {
214 std::string result =
"127.0.0.1";
225 if (ACE::get_ip_interfaces(count,
ips) >= 0) {
226 for (
size_t i = 0;
i < count;
i++) {
235 if (yarp::os::impl::getifaddrs(&
ifaddr) == -1) {
240 if (
ifa->ifa_addr ==
nullptr) {
243 family =
ifa->ifa_addr->sa_family;
245 s = yarp::os::impl::getnameinfo(
ifa->ifa_addr,
253 yCError(
NAMECONFIG,
"getnameinfo() failed: %s", yarp::os::impl::gai_strerror(s));
256 ip = std::string(hostname);
261 if (ip.find(
':') != std::string::npos) {
265#if defined YARP_HAS_ACE
268 bool would_be_loopback = (ip ==
"127.0.0.1" || ip ==
"127.1.0.1" || ip ==
"127.0.1.1");
303 if (ip.length() < result.length() && result != seed) {
324#if defined(YARP_HAS_ACE)
327 if (ACE::get_ip_interfaces(count,
ips) >= 0) {
328 for (
size_t i = 0;
i < count;
i++) {
329 std::string ip =
ips[
i].get_host_addr();
337#elif defined(__unix__) || defined(__APPLE__)
344 if (
strcmp(hostname, name.c_str()) == 0) {
349 for (
size_t i = 0;
i < lst.
size();
i++) {
359 if (name ==
"localhost" || name ==
"127.0.0.1") {
370#if defined(YARP_HAS_ACE)
373 if (ACE::get_ip_interfaces(count,
ips) >= 0) {
374 for (
size_t i = 0;
i < count;
i++) {
375 std::string ip =
ips[
i].get_host_addr();
391 if (
ifa->ifa_addr ==
nullptr) {
394 family =
ifa->ifa_addr->sa_family;
396 s = yarp::os::impl::getnameinfo(
ifa->ifa_addr,
404 yCError(
NAMECONFIG,
"getnameinfo() failed: %s", yarp::os::impl::gai_strerror(s));
421 for (
size_t i = 0;
i < bot.
size();
i++) {
434 this->address = address;
445 if (space.empty() || refresh) {
457 if (spaces.
size() == 0) {
#define YARP_CONFIG_NAMESPACE_FILENAME
A simple collection of objects that can be described and transmitted in a portable way.
void fromString(const std::string &text)
Initializes bottle from a string.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool isNull() const override
Checks if the object is invalid.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
A mini-server for performing network communication in the background.
A class for storing options and configuration information.
void fromConfig(const char *txt, bool wipe=true)
Parses text in the configuration format described in fromConfigFile().
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
A single value (typically within a Bottle).
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual std::string asString() const
Get string value.
std::string getSafeString(const std::string &txt)
std::string getNamespace(bool refresh=false)
static std::string getHostName(bool prefer_loopback=false, const std::string &seed="")
std::string readConfig(const std::string &fileName)
static bool isLocalName(const std::string &name)
static std::string expandFilename(const char *fname)
bool fromFile(const char *ns=nullptr)
void setNamespace(const std::string &ns)
bool writeConfig(const std::string &fileName, const std::string &text)
yarp::os::Bottle getNamespaces(bool refresh=false)
static std::string getIps()
std::string getConfigFileName(const char *stem=nullptr, const char *ns=nullptr)
static yarp::os::Bottle getIpsAsBottle()
void setAddress(const Contact &address)
bool toFile(bool clean=false)
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
std::string yarpconfighome()
Returns the directory where user-specific YARP configuration files should be written.
std::string get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
static constexpr value_type preferred_separator
std::string to_string(IntegerType x)
ContainerT split(const typename ContainerT::value_type &s, std::basic_regex< typename ContainerT::value_type::value_type > regex)
Utility to split a string by a separator, into a vector of strings.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
int mkdir_p(const char *p, int ignoreLevels=0)
Create a directory and all parent directories needed.