| Home | Trees | Indices | Help |
|---|
|
|
1 # Software License Agreement (BSD License) 2 # 3 # Copyright (c) 2009, Willow Garage, Inc. 4 # All rights reserved. 5 # 6 # Redistribution and use in source and binary forms, with or without 7 # modification, are permitted provided that the following conditions 8 # are met: 9 # 10 # * Redistributions of source code must retain the above copyright 11 # notice, this list of conditions and the following disclaimer. 12 # * Redistributions in binary form must reproduce the above 13 # copyright notice, this list of conditions and the following 14 # disclaimer in the documentation and/or other materials provided 15 # with the distribution. 16 # * Neither the name of Willow Garage, Inc. nor the names of its 17 # contributors may be used to endorse or promote products derived 18 # from this software without specific prior written permission. 19 # 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 # POSSIBILITY OF SUCH DAMAGE. 32 # 33 # Revision $Id: environment.py 4428 2009-05-05 05:48:36Z jfaustwg $ 34 35 import os 36 import socket 37 import stat 38 import string 39 import sys 40 41 import rosgraph 42 import rosgraph.network 43 44 from roswtf.rules import warning_rule, error_rule 45 46 # #122048 # best we can do is compare roslib's routine against socket resolution and make sure they agree 49 local_addrs = rosgraph.network.get_local_addresses() 50 51 resolved_ips = [host[4][0] for host in socket.getaddrinfo(socket.gethostname(), 0, 0, 0, socket.SOL_TCP)] 52 global_ips = [ ip for ip in resolved_ips if not ip.startswith('127.') and not ip == '::1'] 53 54 remote_ips = list(set(global_ips) - set(local_addrs)) 55 if remote_ips: 56 return "Local hostname [%s] resolves to [%s], which does not appear to be a local IP address %s."%(socket.gethostname(), ','.join(remote_ips), str(local_addrs))57 58 # suggestion by mquigley based on laptop dhcp issues60 """Make sure that ROS_HOSTNAME resolves to a local IP address""" 61 if not rosgraph.ROS_HOSTNAME in ctx.env: 62 return 63 64 hostname = ctx.env[rosgraph.ROS_HOSTNAME] 65 try: 66 resolved_ips = [host[4][0] for host in socket.getaddrinfo(hostname, 0, 0, 0, socket.SOL_TCP)] 67 except socket.gaierror: 68 return "ROS_HOSTNAME [%s] cannot be resolved to an IP address"%(hostname) 69 70 # best we can do is compare roslib's routine against socket resolution and make sure they agree 71 local_addrs = rosgraph.network.get_local_addresses() 72 73 remote_ips = list(set(resolved_ips) - set(local_addrs)) 74 if remote_ips: 75 return "ROS_HOSTNAME [%s] resolves to [%s], which does not appear to be a local IP address %s."%(hostname, ','.join(remote_ips), str(local_addrs))7678 """Make sure that ROS_IP is a local IP address""" 79 if not rosgraph.ROS_IP in ctx.env: 80 return 81 82 ip = ctx.env[rosgraph.ROS_IP] 83 84 # best we can do is compare roslib's routine against socket resolution and make sure they agree 85 addrs = rosgraph.network.get_local_addresses() 86 87 if ip not in addrs: 88 return "ROS_IP [%s] does not appear to be a local IP address %s."%(ip, str(addrs))89 90 # Error/Warning Rules 91 92 warnings = [ 93 (ros_hostname_check, 94 "ROS_HOSTNAME may be incorrect: "), 95 (ros_ip_check, 96 "ROS_IP may be incorrect: "), 97 98 ] 99 100 errors = [ 101 (ip_check, 102 "Local network configuration is invalid: "), 103 ] 104106 for r in warnings: 107 warning_rule(r, r[0](ctx), ctx) 108 for r in errors: 109 error_rule(r, r[0](ctx), ctx)110
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Fri Aug 28 12:34:24 2015 | http://epydoc.sourceforge.net |