Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve hostname as IP #13

Open
wants to merge 1 commit into
base: hydro-devel
Choose a base branch
from

Conversation

garaemon
Copy link

prosilica::Camera only read ip address. Need to resolve hostname as IP to pass it to prosilica::Camera

if ((he = gethostbyname(ip_address_.c_str())) != NULL)
{
struct in_addr **addr_list
= (struct in_addr **)he->h_addr_list;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have to cast it to an struct in_addr rather than leave it as the normal char ** that it normally returns? I'm referencing this document:

http://www.gnu.org/software/libc/manual/html_node/Host-Names.html

Also, if you must cast it, please use the c++ style static_cast.

@wjwwood
Copy link
Member

wjwwood commented Jun 25, 2015

The patch seems reasonable to me, other than my minor comments.

@garaemon
Copy link
Author

Updated

about in_addr issue, as described in here h_addr and h_addr_list are char* and char** but it's really in_addr*.

@wjwwood
Copy link
Member

wjwwood commented Jun 25, 2015

I see, makes sense. I'll let @trainman419 merge.

@trainman419
Copy link
Contributor

This should probably include some kind of error handling and a useful message if the hostname lookup fails. As currently implemented, if the hostname lookup fails, it just passes the hostname to the prosilica library.

Re-using the ~ip_address parameter to specify a hostname is not a straightforward API, but I'm also hesitant to introduce another parameter. @wjwwood or @garaemon do you have any suggestions on better parameter usage?

@garaemon
Copy link
Author

I wrote a simple testcode of gethostbyname and result is:

$ ./a.out                   
[OK]    localhost => 127.0.0.1
[OK]    127.0.0.1 => 127.0.0.1
[OK]    google.com(DNS lookup) => 173.194.117.231
[OK]    hrp2007v(writtein in /etc/hosts) => 10.7.3.12
[OK]    192.168.96.100 => 192.168.96.100
[ERROR] Failed to resolve 192.168.96.100a (malformed IP)
[ERROR] Failed to resolve 192.168.96.1000 (malformed IP)

Legal IP should be successfully resolved as the same IP.
I think re-using ~ip_address does not effect existing code which is working now.

And it can detect hostname (and malformed IP address) by return value of gethostbyname.
Should it output some error messages?

@trainman419
Copy link
Contributor

I know how gethostbyname works. I know that it will accept an IP address and produce the correct result.

I'm worried that users won't realize that they can supply a hostname in the ip_address parameter, because the parameter name implies that the node is only expecting an IP address. This is why I think there should be a new, explicit hostname parameter, so that future users know that they're allowed to specify their camera by hostname.

You should include explicit error-handling for when the gethostbyname call fails, with a concise and readable message indicating that it tired to do a hostname lookup, and that the hostname lookup failed.

@garaemon
Copy link
Author

I see.

Let me summarize;

  • Keep ~ip_address as a parameter to specify IP address directly
  • Add new ~hostname parameter to resolve hostname and IP address with error handling

@garaemon
Copy link
Author

garaemon commented Jul 3, 2015

Updated

  • Keep ~ip_address without hostname resolving

  • Add ~hostname parameter to resolve hostname by gethostbyname

  • If failed to resolve hosname, print error

  • Specifying ~ip_address:=chestcamera, it should not be resolved

    [INFO] [1435917691.82] [/chest_camera] Trying to load camera with ipaddress: chestcamera
    [WARN] [1435917695.82] [/chest_camera] Unable to open prosilica camera with ip address chestcamera: Unable to find requested camera: 
                                       Timeout during wait
    [INFO] [1435917695.82] [/chest_camera] Available cameras:
    02-2171A-07131 - GC2450C - Unique ID = 115847 IP = 192.168.96.116
    
  • Specifying ~hostname:=chestcamera, it should be resolved

    [INFO] [1435917858.62] [/chest_camera] Trying to load camera with hostname: chestcamera
    [INFO] [1435917858.62] [/chest_camera] hostname resolved as 192.168.96.116
    [INFO] [1435917858.94] [/chest_camera] Started Prosilica camera with guid "115847"
    [INFO] [1435917861.94] [/chest_camera] Loaded calibration for camera 'prosilica115847'
    [INFO] [1435917861.94] [/chest_camera] starting camera 115847 in freerun trigger mode
    [INFO] [1435917862.30] [/chest_camera] starting camera 115847 in fixedrate trigger mode
    
  • Specifying ~hostname:=chestcameraa, it should be resolved but be failed

    [INFO] [1435917966.09] [/chest_camera]  Trying to load camera with hostname: chestcameraaa
    [FATAL] [1435917966.12] [/chest_camera] Failed to resolve hostname: chestcameraaa
    [WARN] [1435917966.12] [/chest_camera]  Unable to open prosilica camera with hostname chestcameraaa: Failed to resolve hostname
    [INFO] [1435917966.12] [/chest_camera]  Available cameras:
    02-2171A-07131 - GC2450C - Unique ID = 115847 IP = 192.168.96.116
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants