EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: gethostbyname and getaddrinfo - multiple DNS entries for a hostname
From: <[email protected]>
To: <[email protected]>
Cc: [email protected]
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
 





Replies:
Re: gethostbyname and getaddrinfo - multiple DNS entries for a hostname Eric Norum

Navigate by Date:
Prev: Re: RE: IOC device support ahwwq
Next: Area Detector Zenon Szalata
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: RE: IOC device support ahwwq
Next: Re: gethostbyname and getaddrinfo - multiple DNS entries for a hostname Eric Norum
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 20 Apr 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·