How best to get the (internet-style) domain name of a system? GetDomainName() appears to be returning "(none)" here on x86 Linux.
Mailing lists / fpc-pascal / 2013-04
Portable (or at least working) version of GetDomainName()?
17 messages · 4 people · –
- MMark Morgan Lloyd 7
- Wwaldo kitty 7
- TTomas Hajny 2
- LLudo Brands 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Mark Morgan Lloyd wroteHow best to get the (internet-style) domain name of a system? GetDomainName() appears to be returning "(none)" here on x86 Linux.
do you mean the FQDN (Fully Qualified Domain Name)??
waldo kitty wrote 6 lines
I mean that on the machine I'm working on the hostname is pye-dev-01 and the domain name is telemetry.co.uk. I was under the impression that GetDomainName() should return the latter, but apart from anything else it's unix-only and whilst Windows is not somewhere I want to go today I'd like a portable solution if possible.
Mark Morgan Lloyd wrote 12 lines
ok... you are looking for the FQDN, then... the question is how is this machine referenced and its FQDN created and maintained... it would seem that you would have a DNS server that would return this information... it sounds like your machine only has its host name defined and there is nothing else DNS-wise that returns the rest of the domain name...
from the machine you are trying to perform this look up from, what do you get if you do the following?
nslookup pye-dev-01
nslookup pye-dev-01.telemetry.co.uk
using the last one, i get the message that that machine doesn't exist... of course, i'm on the outside and access to this machine may not be allowed from outside... not even finding its address...
i don't see this as linux or windows centric... what i'm seeing seems to point to a DNS configuration situation... you might be able to handle this with a local entry in your HOSTS file...
[crystalball] get nslookup working first. your code should work. [/crystalball]
waldo kitty wrote 30 lines
Server: 192.168.1.1
Address: 192.168.1.1#53
Name: pye-dev-01.telemetry.co.uk
Address: 192.168.1.16
nslookup pye-dev-01.telemetry.co.uk
Server: 192.168.1.1
Address: 192.168.1.1#53
Name: pye-dev-01.telemetry.co.uk
Address: 192.168.1.16
using the last one, i get the message that that machine doesn't exist... of course, i'm on the outside and access to this machine may not be allowed from outside... not even finding its address...
As you can see, that's an internal (RFC 1918 IIRC) address.
Show quoted text 6 lines
OK, that's no big deal. But it looks like GetDomainName() doesn't quite do what it says on the can :-)
Mark Morgan Lloyd wrote 20 lines
i like those outputs :)
Show quoted text 5 lines
yup... i kinda figured that was the case...
Show quoted text 8 lines
agreed... i was just looking around on my FPC 2.6.0 install and note the following from rtl/unix/unix.pp
Function GetDomainName:String; deprecated; // because linux only.diggin in, i note that it seems to use the system's uname function... but i think that is different than the command line "uname" or "uname -a" because none of my linux machine return their FQDN in this output... i note that it also seems to be pulling this function from a/the libc library...
i note that both, GetDomainName and GetHostName both use the same var (Sysn : utsname) but just different fields in what is apparently a record of some type...
can't trace further... the grill and a pork loin are calling me... not to mention other mouths in the location wanting some eats soon-ish...
waldo kitty wrote 11 lines
I saw that as well, and wouldn't have raised it if I'd not been working on x86 Linux. It might turn out to depend on the distro: I use Debian.
Show quoted text 12 lines
It might be notable that Debian doesn't volunteer a domain name unless it's able to contact DNS. I'll get onto nslookup, or just use temporary text (it's only salt for a password hash, and is stored).
Mark Morgan Lloyd wrotewaldo kitty wrote:
.
.
Show quoted text 16 lines
Have you tried using unit netdb from package fcl-net? It doesn't support Windows (and some other platforms yet), but it should work for Unix targets. I believe that the two approaches for finding out the domain are either getting it from the DNS or having it specified in /etc/resolv (and both are used by unit netdb - search for DefaultDomainList).
Tomas
Tomas Hajny wrote 25 lines
Thanks for the additional pointer, will investigate.
I saw that as well, and wouldn't have raised it if I'd not been working on x86 Linux. It…
Mark Morgan Lloyd wrote 5 lines
One of the problems with uname is that the kernel doesn't have a clue on how you are connected to the network. Your computer could have 10 network names if it had 10 addresses (not even 10 NIC's required).
Looking up the IP you want the domain name for in a DNS is the only reliable way. And it is portable.
Ludo
Ludo Brands wrote 13 lines
Thanks Ludo, I'd got there. I think there's still the possibility of ambiguity if there are multiple DNS servers listed in resolv.conf, but I agree that it's probably the best way available.
I saw that as well, and wouldn't have raised it if I'd not been working on x86 Linux. It…
Mark Morgan Lloyd wroteIt might be notable that Debian doesn't volunteer a domain name unless it's able to contact DNS. I'll get onto nslookup, or just use temporary text (it's only salt for a password hash, and is stored).
understood... your nslookup output looked fine to me... it is kinda of different in what mine returns but that's likely the DNS package and the configuration differences... (see the link below for an example of my results)
i would attempt to go portable by performing a DNS lookup on the address and or the given host name... i don't think i would try to use external programs for this but would compare my results with theirs for the same lookups...
FWIW: i also just stumbled over our very similar conversation of a year ago...
13 April 2012 - Resolving a local hostnames to an IP address
(sorry for the wrap)
but this time, you are trying to go the other way i guess... that or just trying to get all of the FQDN for the host your app is running on...
. . Have you tried using unit netdb from package fcl-net? It doesn't support Windows (and…
Tomas Hajny wrote 6 lines
[TRIM]
Show quoted text 10 lines
shouldn't the OS' lookup routines handle whether the value from HOSTS or DNS is used automatically? i know that on some systems, one can specify to use HOSTS first (ie: USE_HOSTS_FIRST=1 [OS2] or /etc/host.conf [*nix])... i've seen it in winwhatever once upon a long time ago...
or am i misunderstanding this aspect and the apps used to perform DNS lookups are reacting to this setting and using one value or the other depending on the results returned from the initial query?
Thanks Ludo, I'd got there. I think there's still the possibility of ambiguity if there…
Mark Morgan Lloyd wrote 18 lines
the first DNS server is the one used... if it doesn't respond in X amount of time, then it may be retried Y times before the next DNS server listed in resolv is tried... then you loop through the time period and retries again for each until you get NXDOMAIN or a positive result or have exhausted the list of DNS servers in resolv... at that point, the app may return an error code about not being able to reach a DNS server...
in some cases, the non-responding DNS server(s) may be blocked out from further usage... this may be for some time period or it may require a restart of the local DNS server app (DNS Proxy on some systems) or reboot of the system... i have at least one system that acts this way (locking out unresponsive DNS server entries and requiring a restart of the DNS proxy app)...
my understanding is that this is pretty much all handled by the OS' library code for performing the lookups...
[TRIM] shouldn't the OS' lookup routines handle whether the value from HOSTS or DNS is…
waldo kitty wroteOn 4/9/2013 04:24, Tomas Hajny wrote:
.
.
Show quoted text 15 lines
That depends on what API provided by the respective OS. As far as I understand it correctly, Unix does not provide such functionality in the basic API (syscalls) but only e.g. in libc (which is in turn used by nslookup, etc.), so Pascal code (for Unix) not using libc needs to implement this logic (that's what unit netdb does).
Tomas
Tomas Hajny wrote 20 lines
ahhhhh... ok... i hadn't yet had a chance to go looking in that unit... trying to first complete the email wading for the day ;)
FWIW: if i were to just be hunting and digging, the name of the unit would throw me off because it seems to indicate network database functions whereas i wouldn't think that DNS lookups and the like are database oriented... not like SQL stuff... but i guess the DNS is a form of database, isn't it ;)
understood... your nslookup output looked fine to me... it is kinda of different in what…
waldo kitty wrotei would attempt to go portable by performing a DNS lookup on the address and or the given host name... i don't think i would try to use external programs for this but would compare my results with theirs for the same lookups...
Agreed. I rarely use external programs since there's too much risk they're misplaced or of an unexpected version
Show quoted text 6 lines
So did I. As a quick hack I've parsed /etc/resolv.conf (which covers at least the Linux and Solaris cases), falling back to GetDomainName() if that fails. That will do for the moment, since it will normally be overridden by a .ini file or by something explicitly entered by the user.
