37 #include <netinet/in.h> 38 #include <sys/socket.h> 41 #if !defined(__ANDROID__) 46 #define NI_MAXHOST 1025 53 : only_localhost_allowed_(false)
55 char *ros_ip_env = NULL, *ros_hostname_env = NULL;
57 _dupenv_s(&ros_ip_env, NULL,
"ROS_IP");
58 _dupenv_s(&ros_hostname_env, NULL,
"ROS_HOSTNAME");
60 ros_ip_env = getenv(
"ROS_IP");
61 ros_hostname_env = getenv(
"ROS_HOSTNAME");
63 if (ros_hostname_env && !strcmp(ros_hostname_env,
"localhost"))
65 else if (ros_ip_env && !strncmp(ros_ip_env,
"127.", 4))
67 else if (ros_ip_env && !strcmp(ros_ip_env,
"::1"))
70 char our_hostname[256] = {0};
71 gethostname(our_hostname,
sizeof(our_hostname)-1);
74 #if !defined(__ANDROID__) 79 if (-1 == getifaddrs(&ifaddr))
84 for (ifaddrs *ifa = ifaddr; ifa; ifa = ifa->ifa_next)
86 if(NULL == ifa->ifa_addr)
88 int family = ifa->ifa_addr->sa_family;
89 if (family != AF_INET && family != AF_INET6)
92 if (getnameinfo(ifa->ifa_addr,
93 (family == AF_INET) ?
sizeof(sockaddr_in)
94 :
sizeof(sockaddr_in6),
96 NULL, 0, NI_NUMERICHOST))
112 if (host.length() >= 4 && host.substr(0, 4) == std::string(
"127."))
115 for (std::vector<std::string>::const_iterator it =
allowed_hosts_.begin();
121 ROS_WARN(
"ROS_HOSTNAME / ROS_IP is set to only allow local connections, so " 122 "a requested connection to '%s' is being rejected.", host.c_str());
bool only_localhost_allowed_
std::vector< std::string > allowed_hosts_
bool isHostAllowed(const std::string &host) const
returns true if the transport is allowed to connect to the host passed to it.