g+
g+ Communities
Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014 
<== Date ==> <== Thread ==>

Subject: gethostbyname and getaddrinfo - multiple DNS entries for a hostname
From: <matthew.pearson@diamond.ac.uk>
To: <tech-talk@aps.anl.gov>
Cc: core-talk@aps.anl.gov
Date: Sat, 9 Mar 2013 10:41:30 +0000
Hi,

In the POSIX code in libCom for networking (posix/osdSock.c) there is the use of gethostbyname to map a hostname to IP address. This is what the Asyn function drvAsynIPPort uses to map hostname to IP address (that we use in IOC startup scripts).

We have a problem at Diamond for a few systems that move around different beamlines. These typically comprise a few ethernet attached devices and an Epics IOC running on Linux. The IP addresses of the device that an IOC can talk to changes depending on which beamline it's running on, but the hostname can stay the same. So in our DNS server we have multiple IPv4 address for a hostname, and we would like to be able to use the hostname in the IOC startup script. 

The problem is our DNS server can't/doesn't prioritise local subnets, so our hostname to IP address lookup can return any value from the list (and only one value is returned). At least, that's what gethostbyname does in hostToIPAddr in posix/osdSock.c. However, I've found that if I use getaddrinfo instead I always get the correct IP address for the local subnet first (in the list of returned IP address). So getaddrinfo seems to be matching the localhost to the list of possible IP addresses.

getaddrinfo seems to be the newer POSIX way of doing DNS lookups, and has superseded gethostbyname. From the man page:
The gethostbyname*() and gethostbyaddr*() functions are obsolete. Applications should use getaddrinfo(3) and getnameinfo(3) instead.


Has anyone else had this problem with multiple DNS entries? Any one see a problem with changing hostToIPAddr to use getaddrinfo instead of gethostbyname?

In the meantime we may start doing our own hostname to IP mapping, using getaddrinfo, and only ever pass an IP address into drvAsynIPPort.

Cheers,
Matt













-- 
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. 
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
 





Navigate by Date:
Prev: Proposal to add site-specific TOP_RULES Benjamin Franksen
Next: Re: New API for batched dbGet/dbPut Michael Davidsaver
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014 
Navigate by Thread:
Prev: Proposal to add site-specific TOP_RULES Benjamin Franksen
Next: PMAC Gaudiello, Phillip
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICSv4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·